■ ■ ■ ■ ■ ■
internal/client/handlers/session.go
| skipped 13 lines |
14 | 14 | | |
15 | 15 | | "github.com/NHAS/reverse_ssh/internal" |
16 | 16 | | "github.com/NHAS/reverse_ssh/internal/client/handlers/subsystems" |
| 17 | + | "github.com/NHAS/reverse_ssh/internal/terminal" |
17 | 18 | | "github.com/NHAS/reverse_ssh/pkg/logger" |
18 | 19 | | "github.com/NHAS/reverse_ssh/pkg/storage" |
| 20 | + | |
19 | 21 | | "golang.org/x/crypto/ssh" |
20 | 22 | | ) |
| 23 | + | |
| 24 | + | func ServerConsoleSession(ServerConn ssh.Conn) internal.ChannelHandler { |
| 25 | + | |
| 26 | + | user, err := internal.CreateUser(ServerConn) |
| 27 | + | |
| 28 | + | return func(_ *internal.User, newChannel ssh.NewChannel, log logger.Logger) { |
| 29 | + | if err != nil { |
| 30 | + | log.Error("Unable to add user %s\n", err) |
| 31 | + | newChannel.Reject(ssh.ConnectionFailed, err.Error()) |
| 32 | + | return |
| 33 | + | } |
| 34 | + | |
| 35 | + | Session(user, newChannel, log) |
| 36 | + | } |
| 37 | + | |
| 38 | + | } |
21 | 39 | | |
22 | 40 | | // Session has a lot of 'function' in ssh. It can be used for shell, exec, subsystem, pty-req and more. |
23 | 41 | | // However these calls are done through requests, rather than opening a new channel |
| skipped 36 lines |
60 | 78 | | |
61 | 79 | | req.Reply(true, nil) |
62 | 80 | | |
63 | | - | parts := strings.Split(cmd.Cmd, " ") |
64 | | - | if len(parts) == 0 { |
| 81 | + | line := terminal.ParseLine(cmd.Cmd, 0) |
| 82 | + | |
| 83 | + | if line.Empty() { |
| 84 | + | log.Warning("Human client sent an empty exec payload: %s\n", err) |
65 | 85 | | return |
66 | 86 | | } |
67 | 87 | | |
68 | | - | if parts[0] == "scp" { |
69 | | - | scp(parts, connection, log) |
| 88 | + | command := line.Command.Value() |
| 89 | + | |
| 90 | + | if command == "scp" { |
| 91 | + | scp(line.Chunks[1:], connection, log) |
70 | 92 | | return |
71 | 93 | | } |
72 | 94 | | |
73 | | - | command := parts[0] |
74 | | - | if u, ok := isUrl(parts[0]); ok { |
| 95 | + | if u, ok := isUrl(command); ok { |
75 | 96 | | command, err = download(user.ServerConnection, u) |
76 | 97 | | if err != nil { |
77 | 98 | | fmt.Fprintf(connection, "%s", err.Error()) |
| skipped 2 lines |
80 | 101 | | } |
81 | 102 | | |
82 | 103 | | if user.Pty != nil { |
83 | | - | runCommandWithPty(command, parts[1:], user, requests, log, connection) |
| 104 | + | runCommandWithPty(command, line.Chunks[1:], user, requests, log, connection) |
84 | 105 | | return |
85 | 106 | | } |
86 | | - | runCommand(command, parts[1:], connection) |
| 107 | + | runCommand(command, line.Chunks[1:], connection) |
87 | 108 | | |
88 | 109 | | return |
89 | 110 | | case "shell": |
| skipped 143 lines |