Fix formatting for multi-line command output and delete tasks after completion.

This commit is contained in:
Jakob Friedl
2025-05-23 16:02:16 +02:00
parent 5ab9cd302c
commit a8a32668d1
6 changed files with 33 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
import terminal, strformat, strutils, sequtils, tables, json, times
import terminal, strformat, strutils, sequtils, tables, json, times, base64
import ./interact
import ../[types, globals, utils]
import ../db/database
@@ -163,8 +163,15 @@ proc handleResult*(listener, agent, task: string, taskResult: Task) =
{.cast(gcsafe).}:
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task}] ", resetStyle, "Task execution finished.")
cq.writeLine(taskResult.result)
if taskResult.result != "":
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task}] ", resetStyle, "Output:")
# TODO: Remove completed task from the queue
# Split result string on newline to keep formatting
for line in decode(taskResult.result).split("\n"):
cq.writeLine(line)
# Update task queue to include all tasks, except the one that was just completed
cq.agents[agent].tasks = cq.agents[agent].tasks.filterIt(it.id != task)
return

View File

@@ -9,7 +9,7 @@ var parser = newParser:
help("Conquest Command & Control")
command("shell"):
help("Execute a shell command.")
help("Execute a shell command and retrieve the output.")
arg("command", help="Command", nargs = 1)
arg("arguments", help="Arguments.", nargs = -1) # Handle 0 or more command-line arguments (seq[string])
@@ -44,6 +44,7 @@ proc handleAgentCommand*(cq: Conquest, args: varargs[string]) =
arguments: seq[string] = opts.shell.get.arguments
arguments.insert(command, 0)
cq.taskExecuteShell(arguments)
# Handle help flag
except ShortCircuit as err:
@@ -52,7 +53,5 @@ proc handleAgentCommand*(cq: Conquest, args: varargs[string]) =
# Handle invalid arguments
except UsageError:
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
cq.writeLine("")
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg(), "\n")