diff --git a/agents/monarch/nim.cfg b/agents/monarch/nim.cfg index d57a63a..9820bed 100644 --- a/agents/monarch/nim.cfg +++ b/agents/monarch/nim.cfg @@ -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 diff --git a/agents/monarch/task.nim b/agents/monarch/task.nim index 756b3f3..2d54670 100644 --- a/agents/monarch/task.nim +++ b/agents/monarch/task.nim @@ -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 diff --git a/server/agent/agent.nim b/server/agent/agent.nim index a6c53ac..107404b 100644 --- a/server/agent/agent.nim +++ b/server/agent/agent.nim @@ -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) diff --git a/server/agent/commands.nim b/server/agent/commands/commands.nim similarity index 97% rename from server/agent/commands.nim rename to server/agent/commands/commands.nim index 74a4e6f..2d8b8b4 100644 --- a/server/agent/commands.nim +++ b/server/agent/commands/commands.nim @@ -1,4 +1,4 @@ -import ./commands/[shell, sleep] +import ./[shell, sleep] export shell, sleep #[ diff --git a/server/agent/commands/shell.nim b/server/agent/commands/shell.nim index cab87bf..d07617f 100644 --- a/server/agent/commands/shell.nim +++ b/server/agent/commands/shell.nim @@ -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.") \ No newline at end of file + cq.writeLine(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, "Tasked agent to execute shell command.") \ No newline at end of file diff --git a/server/agent/commands/sleep.nim b/server/agent/commands/sleep.nim index d85e6f8..c26c474 100644 --- a/server/agent/commands/sleep.nim +++ b/server/agent/commands/sleep.nim @@ -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.") \ No newline at end of file + cq.writeLine(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, "Tasked agent to update sleep settings.") \ No newline at end of file diff --git a/server/agent/interact.nim b/server/agent/interact.nim index 19926aa..03f1c26 100644 --- a/server/agent/interact.nim +++ b/server/agent/interact.nim @@ -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": diff --git a/server/server.nim b/server/server.nim index 24f848b..e705f17 100644 --- a/server/server.nim +++ b/server/server.nim @@ -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: diff --git a/server/utils.nim b/server/utils.nim index 5851684..cbfea60 100644 --- a/server/utils.nim +++ b/server/utils.nim @@ -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))