Update agent in database when sleep setting is changed to display latest checkin correctly.
This commit is contained in:
@@ -8,7 +8,7 @@ proc taskSleep*(delay: int): tuple[output: TaskResult, status: TaskStatus] =
|
||||
|
||||
try:
|
||||
sleep(delay * 1000)
|
||||
return ("\n", Completed)
|
||||
return ("", Completed)
|
||||
|
||||
except CatchableError as err:
|
||||
return (fmt"An error occured: {err.msg}" & "\n", Failed)
|
||||
@@ -43,7 +43,6 @@ proc getTasks*(config: AgentConfig, agent: string): 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
|
||||
return false
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export shell, sleep
|
||||
[ ] cd : Change directory
|
||||
[ ] ls/dir : List all files in directory (including hidden ones)
|
||||
[ ] cat/type : Display contents of a file
|
||||
[ ] sleep : Set sleep obfuscation duration to a different value and persist that value in the agent
|
||||
[~] sleep : Set sleep obfuscation duration to a different value and persist that value in the agent
|
||||
|
||||
Post-exploitation
|
||||
-----------------
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import nanoid, sequtils, strutils, strformat, terminal, times
|
||||
import ../../types
|
||||
import ../../db/database
|
||||
|
||||
proc taskExecuteSleep*(cq: Conquest, delay: int) =
|
||||
|
||||
# Update 'sleep' value in database
|
||||
if not cq.dbUpdateSleep(cq.interactAgent.name, delay):
|
||||
return
|
||||
|
||||
# Create a new task
|
||||
let
|
||||
date: string = now().format("dd-MM-yyyy HH:mm:ss")
|
||||
|
||||
@@ -122,6 +122,18 @@ proc dbUpdateCheckin*(cq: Conquest, agentName: string, timestamp: string): bool
|
||||
|
||||
conquestDb.exec("UPDATE agents SET latestCheckin = ? WHERE name = ?", timestamp, agentName)
|
||||
|
||||
conquestDb.close()
|
||||
return true
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
return false
|
||||
|
||||
proc dbUpdateSleep*(cq: Conquest, agentName: string, delay: int): bool =
|
||||
try:
|
||||
let conquestDb = openDatabase(cq.dbPath, mode=dbReadWrite)
|
||||
|
||||
conquestDb.exec("UPDATE agents SET sleep = ? WHERE name = ?", delay, agentName)
|
||||
|
||||
conquestDb.close()
|
||||
return true
|
||||
except:
|
||||
|
||||
@@ -101,7 +101,7 @@ proc drawTable*(cq: Conquest, listeners: seq[Listener]) =
|
||||
cq.writeLine(border(botLeft, botMid, botRight, widths))
|
||||
|
||||
# Calculate time since latest checking in format: Xd Xh Xm Xs
|
||||
proc timeSince*(timestamp: DateTime): Cell =
|
||||
proc timeSince*(agent: Agent, timestamp: DateTime): Cell =
|
||||
|
||||
let
|
||||
now = now()
|
||||
@@ -127,8 +127,8 @@ proc timeSince*(timestamp: DateTime): Cell =
|
||||
return Cell(
|
||||
text: text.strip(),
|
||||
# When the agent is 'dead', meaning that the latest checkin occured
|
||||
# more than 15 seconds ago, dim the text of the cell
|
||||
style: if totalSeconds > 15: styleDim else: styleBright
|
||||
# more than the agents sleep configuration, dim the text style
|
||||
style: if totalSeconds > agent.sleep: styleDim else: styleBright
|
||||
)
|
||||
|
||||
proc drawTable*(cq: Conquest, agents: seq[Agent]) =
|
||||
@@ -154,7 +154,7 @@ proc drawTable*(cq: Conquest, agents: seq[Agent]) =
|
||||
Cell(text: a.os),
|
||||
Cell(text: a.process, fg: if a.elevated: fgRed else: fgWhite),
|
||||
Cell(text: $a.pid, fg: if a.elevated: fgRed else: fgWhite),
|
||||
timeSince(a.latestCheckin)
|
||||
a.timeSince(a.latestCheckin)
|
||||
]
|
||||
|
||||
# Highlight agents running within elevated processes
|
||||
|
||||
Reference in New Issue
Block a user