Updated task result console output

This commit is contained in:
Jakob Friedl
2025-06-02 21:14:13 +02:00
parent 3849bcd7f1
commit ac1bc22b93
9 changed files with 30 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
# Agent configuration
-d:ListenerUuid="KPDHWZNT"
-d:ListenerIp="localhost"
-d:ListenerPort=7777
-d:ListenerUuid="JEBFQPEP"
-d:ListenerIp="127.0.0.1"
-d:ListenerPort=5555
-d:SleepDelay=10

View File

@@ -18,7 +18,7 @@ proc handleTask*(task: Task, config: AgentConfig): TaskResult =
# Update sleep delay in agent config
if taskResult.status == Completed:
config.sleep = delay
config.sleep = parseInt(task.args[0])
# Return result
return taskResult

View File

@@ -214,14 +214,22 @@ proc handleResult*(listener, agent, task: string, taskResult: TaskResult) =
{.cast(gcsafe).}:
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task}] ", resetStyle, "Task execution finished.")
let date: string = now().format("dd-MM-yyyy HH:mm:ss")
if taskResult.data != "":
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task}] ", resetStyle, "Output:")
if taskResult.status == Failed:
cq.writeLine(fgBlack, styleBright, fmt"[{date}]", fgRed, styleBright, " [-] ", resetStyle, fmt"Task {task} failed.", "\n")
# Split result string on newline to keep formatting
for line in decode(taskResult.data).split("\n"):
cq.writeLine(line)
else:
cq.writeLine(fgBlack, styleBright, fmt"[{date}]", fgGreen, " [+] ", resetStyle, fmt"Task {task} finished.")
if taskResult.data != "":
cq.writeLine(fgBlack, styleBright, fmt"[{date}]", fgGreen, " [+] ", resetStyle, "Output:")
# Split result string on newline to keep formatting
for line in decode(taskResult.data).split("\n"):
cq.writeLine(line)
else:
cq.writeLine()
# 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)

View File

@@ -1,4 +1,4 @@
import ./commands/[shell, sleep]
import ./[shell, sleep]
export shell, sleep
#[

View File

@@ -16,4 +16,4 @@ proc taskExecuteShell*(cq: Conquest, arguments: seq[string]) =
# Add new task to the agent's task queue
cq.interactAgent.tasks.add(task)
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task.id}] ", resetStyle, "Tasked agent to execute shell command.")
cq.writeLine(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, "Tasked agent to execute shell command.")

View File

@@ -25,4 +25,4 @@ proc taskExecuteSleep*(cq: Conquest, delay: int) =
# Add new task to the agent's task queue
cq.interactAgent.tasks.add(task)
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task.id}] ", resetStyle, "Tasked agent to update sleep settings.")
cq.writeLine(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, "Tasked agent to update sleep settings.")

View File

@@ -1,6 +1,6 @@
import argparse, times, strformat, terminal, nanoid
import ./commands/commands
import ../[types]
import ./commands
#[
Agent Argument parsing
@@ -17,6 +17,9 @@ var parser = newParser:
help("Update sleep delay configuration.")
arg("delay", help="Delay in seconds.", nargs = 1)
command("info"):
help("Display agent information and current settings.")
command("help"):
nohelpflag()
@@ -52,6 +55,9 @@ proc handleAgentCommand*(cq: Conquest, args: varargs[string]) =
of "sleep":
cq.taskExecuteSleep(parseInt(opts.sleep.get.delay))
of "info":
discard
# Handle help flag
except ShortCircuit as err:
if err.flag == "argparse_help":

View File

@@ -18,7 +18,7 @@ var parser = newParser:
help("List all active listeners.")
command("start"):
help("Starts a new HTTP listener.")
option("-i", "--ip", default=some("localhost"), help="IPv4 address to listen on.", required=false)
option("-i", "--ip", default=some("127.0.0.1"), help="IPv4 address to listen on.", required=false)
option("-p", "--port", help="Port to listen on.", required=true)
# TODO: Future features:

View File

@@ -134,7 +134,7 @@ proc timeSince*(agent: Agent, timestamp: DateTime): Cell =
proc drawTable*(cq: Conquest, agents: seq[Agent]) =
let headers: seq[string] = @["Name", "Address", "Username", "Hostname", "Operating System", "Process", "PID", "Activity"]
let widths = @[8, 15, 15, 15, 16, 15, 5, 13]
let widths = @[8, 15, 15, 15, 16, 15, 5, 8]
let headerCells = headers.mapIt(Cell(text: it, fg: fgWhite, bg: bgDefault))
cq.writeLine(border(topLeft, topMid, topRight, widths))