-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathlist.go
67 lines (49 loc) · 1.3 KB
/
list.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package commands
import (
"fmt"
"io"
"sync"
"github.com/NHAS/reverse_ssh/pkg/table"
"golang.org/x/crypto/ssh"
)
type list struct {
controllableClients *sync.Map
}
func (l *list) Run(tty io.ReadWriter, args ...string) error {
if len(args) == 1 {
t, _ := table.NewTable("Target", "Hostname", "IP Address", "Sys Info")
v, ok := l.controllableClients.Load(args[0])
if !ok {
return fmt.Errorf("unknown client host")
}
client := v.(ssh.Conn)
_, sysInfo, err := client.SendRequest("info", true, nil)
//This will happen on connection failure, rather than error gathering system information
if err != nil {
sysInfo = []byte(err.Error())
}
t.AddValues(client.User(), client.RemoteAddr().String(), string(sysInfo))
t.Fprint(tty)
return nil
}
t, _ := table.NewTable("Targets", "ID", "Hostname", "IP Address")
l.controllableClients.Range(func(idStr interface{}, value interface{}) bool {
sc := value.(ssh.Conn)
t.AddValues(fmt.Sprintf("%s", idStr), sc.User(), sc.RemoteAddr().String())
return true
})
t.Fprint(tty)
return nil
}
func (l *list) Help(explain bool) string {
if explain {
return "List connected controllable hosts."
}
return makeHelpText(
"ls",
"ls <remote_id>",
)
}
func List(controllableClients *sync.Map) *list {
return &list{controllableClients}
}