extractCommand builds the actual command from an ExecRequest. The server sends Path="/bin/sh" Args=["-c","whoami"] for shell commands. We strip the shell invocation and extract the real command.
(path string, args []string)
| 55 | // The server sends Path="/bin/sh" Args=["-c","whoami"] for shell commands. |
| 56 | // We strip the shell invocation and extract the real command. |
| 57 | func extractCommand(path string, args []string) string { |
| 58 | // If path is a shell and args start with "-c", extract the actual command. |
| 59 | if len(args) >= 2 && args[0] == "-c" { |
| 60 | return strings.Join(args[1:], " ") |
| 61 | } |
| 62 | // If path is a shell with /c (cmd.exe /c whoami), extract actual command. |
| 63 | if len(args) >= 2 && strings.EqualFold(args[0], "/c") { |
| 64 | return strings.Join(args[1:], " ") |
| 65 | } |
| 66 | // Otherwise, treat as path + args. |
| 67 | if len(args) > 0 { |
| 68 | return path + " " + strings.Join(args, " ") |
| 69 | } |
| 70 | return path |
| 71 | } |
| 72 | |
| 73 | // --------------------------------------------------------------------------- |
| 74 | // Shared module execution helpers |