2023-09-16 16:02:17 +05:30
|
|
|
package rdp
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/praetorian-inc/fingerprintx/pkg/plugins"
|
|
|
|
|
"github.com/praetorian-inc/fingerprintx/pkg/plugins/services/rdp"
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
|
2023-09-16 16:02:17 +05:30
|
|
|
)
|
|
|
|
|
|
2024-02-07 21:45:40 +05:30
|
|
|
type (
|
|
|
|
|
// IsRDPResponse is the response from the IsRDP function.
|
|
|
|
|
// this is returned by IsRDP function.
|
|
|
|
|
// @example
|
|
|
|
|
// ```javascript
|
|
|
|
|
// const rdp = require('nuclei/rdp');
|
|
|
|
|
// const isRDP = rdp.IsRDP('acme.com', 3389);
|
|
|
|
|
// log(toJSON(isRDP));
|
|
|
|
|
// ```
|
|
|
|
|
IsRDPResponse struct {
|
|
|
|
|
IsRDP bool
|
|
|
|
|
OS string
|
|
|
|
|
}
|
|
|
|
|
)
|
2023-09-16 16:02:17 +05:30
|
|
|
|
|
|
|
|
// IsRDP checks if the given host and port are running rdp server.
|
|
|
|
|
// If connection is successful, it returns true.
|
|
|
|
|
// If connection is unsuccessful, it returns false and error.
|
|
|
|
|
// The Name of the OS is also returned if the connection is successful.
|
2024-02-07 21:45:40 +05:30
|
|
|
// @example
|
|
|
|
|
// ```javascript
|
|
|
|
|
// const rdp = require('nuclei/rdp');
|
|
|
|
|
// const isRDP = rdp.IsRDP('acme.com', 3389);
|
|
|
|
|
// log(toJSON(isRDP));
|
|
|
|
|
// ```
|
2024-03-01 16:38:56 +05:30
|
|
|
func IsRDP(host string, port int) (IsRDPResponse, error) {
|
2024-03-01 16:10:18 +03:00
|
|
|
return memoizedisRDP(host, port)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @memo
|
|
|
|
|
func isRDP(host string, port int) (IsRDPResponse, error) {
|
2023-09-16 16:02:17 +05:30
|
|
|
resp := IsRDPResponse{}
|
|
|
|
|
|
|
|
|
|
timeout := 5 * time.Second
|
|
|
|
|
conn, err := protocolstate.Dialer.Dial(context.TODO(), "tcp", fmt.Sprintf("%s:%d", host, port))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return resp, err
|
|
|
|
|
}
|
2025-07-01 00:40:44 +07:00
|
|
|
defer func() {
|
|
|
|
|
_ = conn.Close()
|
|
|
|
|
}()
|
2023-09-16 16:02:17 +05:30
|
|
|
|
|
|
|
|
server, isRDP, err := rdp.DetectRDP(conn, timeout)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return resp, err
|
|
|
|
|
}
|
|
|
|
|
if !isRDP {
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
resp.IsRDP = true
|
|
|
|
|
resp.OS = server
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-07 21:45:40 +05:30
|
|
|
type (
|
|
|
|
|
// CheckRDPAuthResponse is the response from the CheckRDPAuth function.
|
|
|
|
|
// this is returned by CheckRDPAuth function.
|
|
|
|
|
// @example
|
|
|
|
|
// ```javascript
|
|
|
|
|
// const rdp = require('nuclei/rdp');
|
|
|
|
|
// const checkRDPAuth = rdp.CheckRDPAuth('acme.com', 3389);
|
|
|
|
|
// log(toJSON(checkRDPAuth));
|
|
|
|
|
// ```
|
|
|
|
|
CheckRDPAuthResponse struct {
|
|
|
|
|
PluginInfo *plugins.ServiceRDP
|
|
|
|
|
Auth bool
|
|
|
|
|
}
|
|
|
|
|
)
|
2023-09-16 16:02:17 +05:30
|
|
|
|
|
|
|
|
// CheckRDPAuth checks if the given host and port are running rdp server
|
|
|
|
|
// with authentication and returns their metadata.
|
2024-02-07 21:45:40 +05:30
|
|
|
// If connection is successful, it returns true.
|
|
|
|
|
// @example
|
|
|
|
|
// ```javascript
|
|
|
|
|
// const rdp = require('nuclei/rdp');
|
|
|
|
|
// const checkRDPAuth = rdp.CheckRDPAuth('acme.com', 3389);
|
|
|
|
|
// log(toJSON(checkRDPAuth));
|
|
|
|
|
// ```
|
2024-03-01 16:38:56 +05:30
|
|
|
func CheckRDPAuth(host string, port int) (CheckRDPAuthResponse, error) {
|
2024-03-01 16:10:18 +03:00
|
|
|
return memoizedcheckRDPAuth(host, port)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @memo
|
|
|
|
|
func checkRDPAuth(host string, port int) (CheckRDPAuthResponse, error) {
|
2023-09-16 16:02:17 +05:30
|
|
|
resp := CheckRDPAuthResponse{}
|
|
|
|
|
|
|
|
|
|
timeout := 5 * time.Second
|
|
|
|
|
conn, err := protocolstate.Dialer.Dial(context.TODO(), "tcp", fmt.Sprintf("%s:%d", host, port))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return resp, err
|
|
|
|
|
}
|
2025-07-01 00:40:44 +07:00
|
|
|
defer func() {
|
|
|
|
|
_ = conn.Close()
|
|
|
|
|
}()
|
2023-09-16 16:02:17 +05:30
|
|
|
|
|
|
|
|
pluginInfo, auth, err := rdp.DetectRDPAuth(conn, timeout)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return resp, err
|
|
|
|
|
}
|
|
|
|
|
if !auth {
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
resp.Auth = true
|
|
|
|
|
resp.PluginInfo = pluginInfo
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|