Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/js/libs/vnc/vnc.go
2070 views
1
package vnc
2
3
import (
4
"context"
5
"fmt"
6
"net"
7
"strconv"
8
"time"
9
10
"github.com/praetorian-inc/fingerprintx/pkg/plugins"
11
"github.com/praetorian-inc/fingerprintx/pkg/plugins/services/vnc"
12
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
13
)
14
15
type (
16
// IsVNCResponse is the response from the IsVNC function.
17
// @example
18
// ```javascript
19
// const vnc = require('nuclei/vnc');
20
// const isVNC = vnc.IsVNC('acme.com', 5900);
21
// log(toJSON(isVNC));
22
// ```
23
IsVNCResponse struct {
24
IsVNC bool
25
Banner string
26
}
27
)
28
29
// IsVNC checks if a host is running a VNC server.
30
// It returns a boolean indicating if the host is running a VNC server
31
// and the banner of the VNC server.
32
// @example
33
// ```javascript
34
// const vnc = require('nuclei/vnc');
35
// const isVNC = vnc.IsVNC('acme.com', 5900);
36
// log(toJSON(isVNC));
37
// ```
38
func IsVNC(ctx context.Context, host string, port int) (IsVNCResponse, error) {
39
executionId := ctx.Value("executionId").(string)
40
return memoizedisVNC(executionId, host, port)
41
}
42
43
// @memo
44
func isVNC(executionId string, host string, port int) (IsVNCResponse, error) {
45
resp := IsVNCResponse{}
46
47
timeout := 5 * time.Second
48
dialer := protocolstate.GetDialersWithId(executionId)
49
if dialer == nil {
50
return IsVNCResponse{}, fmt.Errorf("dialers not initialized for %s", executionId)
51
}
52
conn, err := dialer.Fastdialer.Dial(context.TODO(), "tcp", net.JoinHostPort(host, strconv.Itoa(port)))
53
if err != nil {
54
return resp, err
55
}
56
defer func() {
57
_ = conn.Close()
58
}()
59
60
vncPlugin := vnc.VNCPlugin{}
61
service, err := vncPlugin.Run(conn, timeout, plugins.Target{Host: host})
62
if err != nil {
63
return resp, err
64
}
65
if service == nil {
66
return resp, nil
67
}
68
resp.Banner = service.Version
69
resp.IsVNC = true
70
return resp, nil
71
}
72
73