■ ■ ■ ■ ■ ■ ■
internal/server/commands/listen.go
1 | 1 | | package commands |
2 | 2 | | |
3 | 3 | | import ( |
| 4 | + | "encoding/json" |
4 | 5 | | "errors" |
5 | 6 | | "fmt" |
6 | 7 | | "io" |
| skipped 4 lines |
11 | 12 | | "github.com/NHAS/reverse_ssh/internal/server/clients" |
12 | 13 | | "github.com/NHAS/reverse_ssh/internal/server/multiplexer" |
13 | 14 | | "github.com/NHAS/reverse_ssh/internal/terminal" |
| 15 | + | "github.com/NHAS/reverse_ssh/internal/terminal/autocomplete" |
14 | 16 | | "github.com/NHAS/reverse_ssh/pkg/logger" |
15 | 17 | | "golang.org/x/crypto/ssh" |
16 | 18 | | ) |
| skipped 69 lines |
86 | 88 | | } |
87 | 89 | | |
88 | 90 | | if len(foundClients) == 0 { |
89 | | - | return fmt.Errorf("No clients matched '%s'", client) |
| 91 | + | return fmt.Errorf("No clients matched '%s'", specifier) |
| 92 | + | } |
| 93 | + | |
| 94 | + | if line.IsSet("l") { |
| 95 | + | |
| 96 | + | for id, cc := range foundClients { |
| 97 | + | result, message, _ := cc.SendRequest("query-tcpip-forwards", true, nil) |
| 98 | + | if !result { |
| 99 | + | fmt.Fprintf(tty, "%s does not support querying server forwards\n", id) |
| 100 | + | continue |
| 101 | + | } |
| 102 | + | |
| 103 | + | var remoteforwards []internal.RemoteForwardRequest |
| 104 | + | err := json.Unmarshal(message, &remoteforwards) |
| 105 | + | if err != nil { |
| 106 | + | fmt.Fprintf(tty, "%s sent an incompatiable message: %s\n", id, err) |
| 107 | + | continue |
| 108 | + | } |
| 109 | + | |
| 110 | + | fmt.Fprintf(tty, "%s (%s %s): \n", id, clients.NormaliseHostname(cc.User()), cc.RemoteAddr().String()) |
| 111 | + | for _, rf := range remoteforwards { |
| 112 | + | fmt.Fprintf(tty, "\t%s:%d\n", rf.BindAddr, rf.BindPort) |
| 113 | + | } |
| 114 | + | |
| 115 | + | } |
| 116 | + | |
| 117 | + | return nil |
90 | 118 | | } |
91 | 119 | | |
92 | 120 | | on := line.IsSet("on") |
| skipped 103 lines |
196 | 224 | | } |
197 | 225 | | |
198 | 226 | | func (W *listen) Expect(line terminal.ParsedLine) []string { |
| 227 | + | |
| 228 | + | if line.Section != nil { |
| 229 | + | switch line.Section.Value() { |
| 230 | + | case "c", "client": |
| 231 | + | return []string{autocomplete.RemoteId} |
| 232 | + | } |
| 233 | + | } |
| 234 | + | |
199 | 235 | | return nil |
200 | 236 | | } |
201 | 237 | | |
| skipped 22 lines |