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:
|
try:
|
||||||
sleep(delay * 1000)
|
sleep(delay * 1000)
|
||||||
return ("\n", Completed)
|
return ("", Completed)
|
||||||
|
|
||||||
except CatchableError as err:
|
except CatchableError as err:
|
||||||
return (fmt"An error occured: {err.msg}" & "\n", Failed)
|
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:
|
except CatchableError as err:
|
||||||
# When the listener is not reachable, don't kill the application, but check in at the next time
|
# When the listener is not reachable, don't kill the application, but check in at the next time
|
||||||
echo "[-] [getTasks]:", err.msg
|
echo "[-] [getTasks]:", err.msg
|
||||||
return false
|
|
||||||
finally:
|
finally:
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export shell, sleep
|
|||||||
[ ] cd : Change directory
|
[ ] cd : Change directory
|
||||||
[ ] ls/dir : List all files in directory (including hidden ones)
|
[ ] ls/dir : List all files in directory (including hidden ones)
|
||||||
[ ] cat/type : Display contents of a file
|
[ ] 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
|
Post-exploitation
|
||||||
-----------------
|
-----------------
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import nanoid, sequtils, strutils, strformat, terminal, times
|
import nanoid, sequtils, strutils, strformat, terminal, times
|
||||||
import ../../types
|
import ../../types
|
||||||
|
import ../../db/database
|
||||||
|
|
||||||
proc taskExecuteSleep*(cq: Conquest, delay: int) =
|
proc taskExecuteSleep*(cq: Conquest, delay: int) =
|
||||||
|
|
||||||
|
# Update 'sleep' value in database
|
||||||
|
if not cq.dbUpdateSleep(cq.interactAgent.name, delay):
|
||||||
|
return
|
||||||
|
|
||||||
# Create a new task
|
# Create a new task
|
||||||
let
|
let
|
||||||
date: string = now().format("dd-MM-yyyy HH:mm:ss")
|
date: string = now().format("dd-MM-yyyy HH:mm:ss")
|
||||||
|
|||||||
@@ -127,3 +127,15 @@ proc dbUpdateCheckin*(cq: Conquest, agentName: string, timestamp: string): bool
|
|||||||
except:
|
except:
|
||||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||||
return false
|
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:
|
||||||
|
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||||
|
return false
|
||||||
@@ -101,7 +101,7 @@ proc drawTable*(cq: Conquest, listeners: seq[Listener]) =
|
|||||||
cq.writeLine(border(botLeft, botMid, botRight, widths))
|
cq.writeLine(border(botLeft, botMid, botRight, widths))
|
||||||
|
|
||||||
# Calculate time since latest checking in format: Xd Xh Xm Xs
|
# Calculate time since latest checking in format: Xd Xh Xm Xs
|
||||||
proc timeSince*(timestamp: DateTime): Cell =
|
proc timeSince*(agent: Agent, timestamp: DateTime): Cell =
|
||||||
|
|
||||||
let
|
let
|
||||||
now = now()
|
now = now()
|
||||||
@@ -127,8 +127,8 @@ proc timeSince*(timestamp: DateTime): Cell =
|
|||||||
return Cell(
|
return Cell(
|
||||||
text: text.strip(),
|
text: text.strip(),
|
||||||
# When the agent is 'dead', meaning that the latest checkin occured
|
# When the agent is 'dead', meaning that the latest checkin occured
|
||||||
# more than 15 seconds ago, dim the text of the cell
|
# more than the agents sleep configuration, dim the text style
|
||||||
style: if totalSeconds > 15: styleDim else: styleBright
|
style: if totalSeconds > agent.sleep: styleDim else: styleBright
|
||||||
)
|
)
|
||||||
|
|
||||||
proc drawTable*(cq: Conquest, agents: seq[Agent]) =
|
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.os),
|
||||||
Cell(text: a.process, fg: if a.elevated: fgRed else: fgWhite),
|
Cell(text: a.process, fg: if a.elevated: fgRed else: fgWhite),
|
||||||
Cell(text: $a.pid, 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
|
# Highlight agents running within elevated processes
|
||||||
|
|||||||
Reference in New Issue
Block a user