/
vnc.go
50 lines (43 loc) · 1017 Bytes
/
vnc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package checks
import (
"context"
"fmt"
"net"
"github.com/mitchellh/go-vnc"
)
type Vnc struct {
checkBase
}
func (c Vnc) Run(teamID uint, boxIp string, res chan Result) {
// Configure the vnc client
username, password := getCreds(teamID, c.CredLists, c.Name)
config := vnc.ClientConfig{
Auth: []vnc.ClientAuth{
&vnc.PasswordAuth{Password: password},
},
}
// Dial the vnc server
dialer := net.Dialer{}
conn, err := dialer.DialContext(context.TODO(), "tcp", fmt.Sprintf("%s:%d", boxIp, c.Port))
if err != nil {
res <- Result{
Error: "connection to vnc server failed",
Debug: err.Error() + " for creds " + username + ":" + password,
}
return
}
defer conn.Close()
vncClient, err := vnc.Client(conn, &config)
if err != nil {
res <- Result{
Error: "failed to log in to VNC server",
Debug: err.Error() + " for creds " + username + ":" + password,
}
return
}
defer vncClient.Close()
res <- Result{
Status: true,
Debug: "creds " + username + ":" + password,
}
}