MCPcopy
hub / github.com/ph4ntonn/Stowaway / start

Method start

agent/handler/ssh.go:36–172  ·  view source on GitHub ↗

StartSSH 启动ssh

()

Source from the content-addressed store, hash-verified

34
35// StartSSH 启动ssh
36func (mySSH *SSH) start() {
37 var authPayload ssh.AuthMethod
38 var err error
39
40 sMessage := protocol.PrepareAndDecideWhichSProtoToUpper(global.G_Component.Conn, global.G_Component.Secret, global.G_Component.UUID)
41
42 sshResheader := &protocol.Header{
43 Sender: global.G_Component.UUID,
44 Accepter: protocol.ADMIN_UUID,
45 MessageType: protocol.SSHRES,
46 RouteLen: uint32(len([]byte(protocol.TEMP_ROUTE))), // No need to set route when agent send mess to admin
47 Route: protocol.TEMP_ROUTE,
48 }
49
50 sshResultheader := &protocol.Header{
51 Sender: global.G_Component.UUID,
52 Accepter: protocol.ADMIN_UUID,
53 MessageType: protocol.SSHRESULT,
54 RouteLen: uint32(len([]byte(protocol.TEMP_ROUTE))), // No need to set route when agent send mess to admin
55 Route: protocol.TEMP_ROUTE,
56 }
57
58 sshResSuccMess := &protocol.SSHRes{
59 OK: 1,
60 }
61
62 sshResFailMess := &protocol.SSHRes{
63 OK: 0,
64 }
65
66 defer func() {
67 if err != nil {
68 protocol.ConstructMessage(sMessage, sshResheader, sshResFailMess, false)
69 sMessage.SendMessage()
70 }
71 }()
72
73 switch mySSH.Method {
74 case UPMETHOD:
75 authPayload = ssh.Password(mySSH.Password)
76 case CERMETHOD:
77 var key ssh.Signer
78 key, err = ssh.ParsePrivateKey(mySSH.Certificate)
79 if err != nil {
80 return
81 }
82 authPayload = ssh.PublicKeys(key)
83 }
84
85 sshDial, err := ssh.Dial("tcp", mySSH.Addr, &ssh.ClientConfig{
86 User: mySSH.Username,
87 Auth: []ssh.AuthMethod{authPayload},
88 HostKeyCallback: ssh.InsecureIgnoreHostKey(),
89 Timeout: 10 * time.Second,
90 })
91 if err != nil {
92 return
93 }

Callers 1

DispatchSSHMessFunction · 0.45

Calls 5

ConstructMessageFunction · 0.92
CheckSystemFunction · 0.92
SendMessageMethod · 0.65
DialMethod · 0.65

Tested by

no test coverage detected