2025-05-22 20:03:22 +02:00
|
|
|
import argparse, times, strformat, terminal, nanoid
|
2025-06-02 21:14:13 +02:00
|
|
|
import ./commands/commands
|
2025-05-18 12:51:26 +02:00
|
|
|
import ../[types]
|
|
|
|
|
|
|
|
|
|
#[
|
2025-05-19 21:56:34 +02:00
|
|
|
Agent Argument parsing
|
2025-05-18 12:51:26 +02:00
|
|
|
]#
|
|
|
|
|
var parser = newParser:
|
|
|
|
|
help("Conquest Command & Control")
|
|
|
|
|
|
|
|
|
|
command("shell"):
|
2025-05-23 16:02:16 +02:00
|
|
|
help("Execute a shell command and retrieve the output.")
|
2025-05-22 20:03:22 +02:00
|
|
|
arg("command", help="Command", nargs = 1)
|
|
|
|
|
arg("arguments", help="Arguments.", nargs = -1) # Handle 0 or more command-line arguments (seq[string])
|
2025-05-18 12:51:26 +02:00
|
|
|
|
2025-05-28 10:39:30 +02:00
|
|
|
command("sleep"):
|
|
|
|
|
help("Update sleep delay configuration.")
|
|
|
|
|
arg("delay", help="Delay in seconds.", nargs = 1)
|
|
|
|
|
|
2025-06-02 21:14:13 +02:00
|
|
|
command("info"):
|
|
|
|
|
help("Display agent information and current settings.")
|
|
|
|
|
|
2025-06-20 16:44:39 +02:00
|
|
|
command("pwd"):
|
2025-07-07 21:30:05 +02:00
|
|
|
help("Retrieve current working directory.")
|
|
|
|
|
|
|
|
|
|
command("cd"):
|
|
|
|
|
help("Change current working directory.")
|
|
|
|
|
arg("directory", help="Relative or absolute path of the directory to change to.", nargs = -1)
|
|
|
|
|
|
|
|
|
|
command("ls"):
|
|
|
|
|
help("List files and directories.")
|
|
|
|
|
arg("directory", help="Relative or absolute path. Default: current working directory.", nargs = -1)
|
2025-06-20 16:44:39 +02:00
|
|
|
|
2025-05-18 12:51:26 +02:00
|
|
|
command("help"):
|
|
|
|
|
nohelpflag()
|
|
|
|
|
|
2025-05-21 14:06:04 +02:00
|
|
|
command("back"):
|
2025-05-18 12:51:26 +02:00
|
|
|
nohelpflag()
|
|
|
|
|
|
|
|
|
|
proc handleAgentCommand*(cq: Conquest, args: varargs[string]) =
|
|
|
|
|
|
|
|
|
|
# Return if no command (or just whitespace) is entered
|
|
|
|
|
if args[0].replace(" ", "").len == 0: return
|
|
|
|
|
|
|
|
|
|
let date: string = now().format("dd-MM-yyyy HH:mm:ss")
|
2025-05-22 20:03:22 +02:00
|
|
|
cq.writeLine(fgBlue, styleBright, fmt"[{date}] ", fgYellow, fmt"[{cq.interactAgent.name}] ", resetStyle, styleBright, args[0])
|
2025-05-18 12:51:26 +02:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
let opts = parser.parse(args[0].split(" ").filterIt(it.len > 0))
|
|
|
|
|
|
|
|
|
|
case opts.command
|
2025-05-22 20:03:22 +02:00
|
|
|
|
2025-05-21 14:06:04 +02:00
|
|
|
of "back": # Return to management mode
|
2025-05-18 12:51:26 +02:00
|
|
|
discard
|
|
|
|
|
|
|
|
|
|
of "help": # Display help menu
|
|
|
|
|
cq.writeLine(parser.help())
|
|
|
|
|
|
2025-05-22 20:03:22 +02:00
|
|
|
of "shell":
|
|
|
|
|
var
|
|
|
|
|
command: string = opts.shell.get.command
|
|
|
|
|
arguments: seq[string] = opts.shell.get.arguments
|
|
|
|
|
arguments.insert(command, 0)
|
|
|
|
|
cq.taskExecuteShell(arguments)
|
2025-05-28 10:39:30 +02:00
|
|
|
|
|
|
|
|
of "sleep":
|
|
|
|
|
cq.taskExecuteSleep(parseInt(opts.sleep.get.delay))
|
2025-05-22 20:03:22 +02:00
|
|
|
|
2025-06-02 21:14:13 +02:00
|
|
|
of "info":
|
|
|
|
|
discard
|
|
|
|
|
|
2025-06-20 16:44:39 +02:00
|
|
|
of "pwd":
|
|
|
|
|
cq.taskGetWorkingDirectory()
|
|
|
|
|
|
2025-07-07 21:30:05 +02:00
|
|
|
of "cd":
|
|
|
|
|
cq.taskSetWorkingDirectory(opts.cd.get.directory)
|
|
|
|
|
|
|
|
|
|
of "ls":
|
|
|
|
|
cq.taskListDirectory(opts.ls.get.directory)
|
|
|
|
|
|
2025-05-18 12:51:26 +02:00
|
|
|
# Handle help flag
|
|
|
|
|
except ShortCircuit as err:
|
|
|
|
|
if err.flag == "argparse_help":
|
|
|
|
|
cq.writeLine(err.help)
|
|
|
|
|
|
|
|
|
|
# Handle invalid arguments
|
2025-05-28 10:39:30 +02:00
|
|
|
except CatchableError:
|
2025-05-23 16:02:16 +02:00
|
|
|
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg(), "\n")
|
2025-05-19 21:56:34 +02:00
|
|
|
|