Improved logging format.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import ../common/[types, utils]
|
||||
import ../common/types
|
||||
|
||||
# Declare function prototypes
|
||||
proc executePs(ctx: AgentCtx, task: Task): TaskResult
|
||||
@@ -44,6 +44,7 @@ when defined(agent):
|
||||
import winim
|
||||
import os, strutils, sequtils, strformat, tables, algorithm
|
||||
import ../agent/protocol/result
|
||||
import ../common/utils
|
||||
|
||||
# TODO: Add user context to process information
|
||||
type
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import ../common/[types, utils]
|
||||
import ../common/types
|
||||
|
||||
# Define function prototypes
|
||||
proc executePwd(ctx: AgentCtx, task: Task): TaskResult
|
||||
@@ -97,6 +97,7 @@ when defined(agent):
|
||||
|
||||
import os, strutils, strformat, times, algorithm, winim
|
||||
import ../agent/protocol/result
|
||||
import ../common/utils
|
||||
|
||||
# Retrieve current working directory
|
||||
proc executePwd(ctx: AgentCtx, task: Task): TaskResult =
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import tables, strformat
|
||||
import ../common/[types, utils]
|
||||
import ../common/types
|
||||
|
||||
# Import modules
|
||||
import
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import ../common/[types, utils]
|
||||
import ../common/types
|
||||
|
||||
# Define function prototype
|
||||
proc executeShell(ctx: AgentCtx, task: Task): TaskResult
|
||||
@@ -24,8 +24,9 @@ when defined(server):
|
||||
|
||||
when defined(agent):
|
||||
|
||||
import ../agent/protocol/result
|
||||
import osproc, strutils, strformat
|
||||
import ../agent/protocol/result
|
||||
import ../common/utils
|
||||
|
||||
proc executeShell(ctx: AgentCtx, task: Task): TaskResult =
|
||||
try:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import ../common/[types, utils]
|
||||
import ../common/types
|
||||
|
||||
# Define function prototype
|
||||
proc executeSleep(ctx: AgentCtx, task: Task): TaskResult
|
||||
@@ -8,7 +8,7 @@ let commands* = @[
|
||||
Command(
|
||||
name: "sleep",
|
||||
commandType: CMD_SLEEP,
|
||||
description: "Update sleep delay ctxuration.",
|
||||
description: "Update sleep delay configuration.",
|
||||
example: "sleep 5",
|
||||
arguments: @[
|
||||
Argument(name: "delay", description: "Delay in seconds.", argumentType: INT, isRequired: true)
|
||||
@@ -25,6 +25,7 @@ when defined(agent):
|
||||
|
||||
import os, strutils, strformat
|
||||
import ../agent/protocol/result
|
||||
import ../common/utils
|
||||
|
||||
proc executeSleep(ctx: AgentCtx, task: Task): TaskResult =
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import terminal, strformat, strutils, sequtils, tables, times, system
|
||||
|
||||
import ../core/logger
|
||||
import ../[utils, globals]
|
||||
import ../db/database
|
||||
import ../protocol/packer
|
||||
import ../core/logger
|
||||
import ../../common/[types, utils]
|
||||
|
||||
#[
|
||||
@@ -19,16 +19,17 @@ proc register*(registrationData: seq[byte]): bool =
|
||||
|
||||
# Validate that listener exists
|
||||
if not cq.dbListenerExists(agent.listenerId.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] {agent.ip} attempted to register to non-existent listener: {agent.listenerId}.", "\n")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] {agent.ip} attempted to register to non-existent listener: {agent.listenerId}.", "\n")
|
||||
return false
|
||||
|
||||
# # Store agent in database
|
||||
# Store agent in database
|
||||
if not cq.dbStoreAgent(agent):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Failed to insert agent {agent.agentId} into database.", "\n")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] Failed to insert agent {agent.agentId} into database.", "\n")
|
||||
return false
|
||||
|
||||
# Create log directory
|
||||
if not cq.makeAgentLogDirectory(agent.agentId):
|
||||
cq.writeLine(fgRed, styleBright, "[-] Failed to create log")
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] Failed to create writeLine")
|
||||
return false
|
||||
|
||||
cq.agents[agent.agentId] = agent
|
||||
@@ -53,12 +54,12 @@ proc getTasks*(heartbeat: seq[byte]): seq[seq[byte]] =
|
||||
|
||||
# Check if listener exists
|
||||
if not cq.dbListenerExists(listenerId):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Task-retrieval request made to non-existent listener: {listenerId}.", "\n")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] Task-retrieval request made to non-existent listener: {listenerId}.", "\n")
|
||||
raise newException(ValueError, "Invalid listener.")
|
||||
|
||||
# Check if agent exists
|
||||
if not cq.dbAgentExists(agentId):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Task-retrieval request made to non-existent agent: {agentId}.", "\n")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] Task-retrieval request made to non-existent agent: {agentId}.", "\n")
|
||||
raise newException(ValueError, "Invalid agent.")
|
||||
|
||||
# Update the last check-in date for the accessed agent
|
||||
@@ -81,24 +82,23 @@ proc handleResult*(resultData: seq[byte]) =
|
||||
agentId = Uuid.toString(taskResult.header.agentId)
|
||||
listenerId = Uuid.toString(taskResult.listenerId)
|
||||
|
||||
let date: string = now().format("dd-MM-yyyy HH:mm:ss")
|
||||
cq.info(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, fmt"{$resultData.len} bytes received.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] [ * ] ", resetStyle, fmt"{$resultData.len} bytes received.")
|
||||
|
||||
case cast[StatusType](taskResult.status):
|
||||
of STATUS_COMPLETED:
|
||||
cq.success(fgBlack, styleBright, fmt"[{date}]", fgGreen, " [+] ", resetStyle, fmt"Task {taskId} completed.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}]", fgGreen, " [ + ] ", resetStyle, fmt"Task {taskId} completed.")
|
||||
of STATUS_FAILED:
|
||||
cq.error(fgBlack, styleBright, fmt"[{date}]", fgRed, styleBright, " [-] ", resetStyle, fmt"Task {taskId} failed.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}]", fgRed, styleBright, " [ - ] ", resetStyle, fmt"Task {taskId} failed.")
|
||||
of STATUS_IN_PROGRESS:
|
||||
discard
|
||||
|
||||
case cast[ResultType](taskResult.resultType):
|
||||
of RESULT_STRING:
|
||||
if int(taskResult.length) > 0:
|
||||
cq.info(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, "Output:")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] [ * ] ", resetStyle, "Output:")
|
||||
# Split result string on newline to keep formatting
|
||||
for line in Bytes.toString(taskResult.data).split("\n"):
|
||||
cq.output(line)
|
||||
cq.writeLine(line)
|
||||
|
||||
of RESULT_BINARY:
|
||||
# Write binary data to a file
|
||||
|
||||
@@ -91,8 +91,7 @@ proc httpGet*(ctx: Context) {.async.} =
|
||||
ctx.handled = true # Ensure that HTTP response is sent only once
|
||||
|
||||
# Notify operator that agent collected tasks
|
||||
let date = now().format("dd-MM-yyyy HH:mm:ss")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, fmt"{$response.len} bytes sent.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] [ * ] ", resetStyle, fmt"{$response.len} bytes sent.")
|
||||
|
||||
except CatchableError:
|
||||
resp "", Http404
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import terminal, strformat, strutils, tables, times, system, parsetoml
|
||||
|
||||
import ./[task, logger]
|
||||
import ./task
|
||||
import ../utils
|
||||
import ../db/database
|
||||
import ../../common/types
|
||||
@@ -49,7 +49,7 @@ proc agentList*(cq: Conquest, listener: string) =
|
||||
else:
|
||||
# Check if listener exists
|
||||
if not cq.dbListenerExists(listener.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Listener {listener.toUpperAscii} does not exist.")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] Listener {listener.toUpperAscii} does not exist.")
|
||||
return
|
||||
|
||||
cq.drawTable(cq.dbGetAllAgentsByListener(listener.toUpperAscii))
|
||||
@@ -59,7 +59,7 @@ proc agentList*(cq: Conquest, listener: string) =
|
||||
proc agentInfo*(cq: Conquest, name: string) =
|
||||
# Check if agent supplied via -n parameter exists in database
|
||||
if not cq.dbAgentExists(name.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Agent {name.toUpperAscii} does not exist.")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] Agent {name.toUpperAscii} does not exist.")
|
||||
return
|
||||
|
||||
let agent = cq.agents[name.toUpperAscii]
|
||||
@@ -87,7 +87,7 @@ proc agentKill*(cq: Conquest, name: string) =
|
||||
|
||||
# Check if agent supplied via -n parameter exists in database
|
||||
if not cq.dbAgentExists(name.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Agent {name.toUpperAscii} does not exist.")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] Agent {name.toUpperAscii} does not exist.")
|
||||
return
|
||||
|
||||
# TODO: Stop the process of the agent on the target system
|
||||
@@ -96,30 +96,29 @@ proc agentKill*(cq: Conquest, name: string) =
|
||||
|
||||
# Remove the agent from the database
|
||||
if not cq.dbDeleteAgentByName(name.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, "[-] Failed to terminate agent: ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] Failed to terminate agent: ", getCurrentExceptionMsg())
|
||||
return
|
||||
|
||||
cq.delAgent(name)
|
||||
cq.writeLine(fgYellow, styleBright, "[+] ", resetStyle, "Terminated agent ", fgYellow, styleBright, name.toUpperAscii, resetStyle, ".")
|
||||
cq.writeLine(fgYellow, styleBright, "[ + ] ", resetStyle, "Terminated agent ", fgYellow, styleBright, name.toUpperAscii, resetStyle, ".")
|
||||
|
||||
# Switch to interact mode
|
||||
proc agentInteract*(cq: Conquest, name: string) =
|
||||
|
||||
# Verify that agent exists
|
||||
if not cq.dbAgentExists(name.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Agent {name.toUpperAscii} does not exist.")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] Agent {name.toUpperAscii} does not exist.")
|
||||
return
|
||||
|
||||
let agent = cq.agents[name.toUpperAscii]
|
||||
var command: string = ""
|
||||
|
||||
# Change prompt indicator to show agent interaction
|
||||
cq.interactAgent = agent
|
||||
cq.setIndicator(fmt"[{agent.agentId}]> ")
|
||||
cq.setStatusBar(@[("[mode]", "interact"), ("[username]", fmt"{agent.username}"), ("[hostname]", fmt"{agent.hostname}"), ("[ip]", fmt"{agent.ip}"), ("[domain]", fmt"{agent.domain}")])
|
||||
cq.writeLine(fgYellow, styleBright, "[+] ", resetStyle, fmt"Started interacting with agent ", fgYellow, styleBright, agent.agentId, resetStyle, ". Type 'help' to list available commands.\n")
|
||||
cq.interactAgent = agent
|
||||
|
||||
cq.log(fmt"Started interacting with agent {agent.agentId}.")
|
||||
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] ", fgYellow, "[ + ] ", resetStyle, fmt"Started interacting with agent ", fgYellow, styleBright, agent.agentId, resetStyle, ". Type 'help' to list available commands.\n")
|
||||
|
||||
while command.replace(" ", "") != "back":
|
||||
command = cq.readLine()
|
||||
|
||||
@@ -37,7 +37,7 @@ proc serializeConfiguration(cq: Conquest, listener: Listener, sleep: int): seq[b
|
||||
|
||||
wipeKey(aesKey)
|
||||
|
||||
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, "Profile configuration serialized.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] [ * ] ", resetStyle, "Profile configuration serialized.")
|
||||
return encMaterial & encData
|
||||
|
||||
proc replaceAfterPrefix(content, prefix, value: string): string =
|
||||
@@ -63,10 +63,10 @@ proc compile(cq: Conquest, placeholderLength: int): string =
|
||||
.replaceAfterPrefix("-o:", exeFile)
|
||||
writeFile(configFile, config)
|
||||
|
||||
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, fmt"Placeholder created ({placeholder.len()} bytes).")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] [ * ] ", resetStyle, fmt"Placeholder created ({placeholder.len()} bytes).")
|
||||
|
||||
# Build agent by executing the ./build.sh script on the system.
|
||||
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, "Compiling agent.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] [ * ] ", resetStyle, "Compiling agent.")
|
||||
|
||||
try:
|
||||
# Using the startProcess function from the 'osproc' module, it is possible to retrieve the output as it is received, line-by-line instead of all at once
|
||||
@@ -81,19 +81,19 @@ proc compile(cq: Conquest, placeholderLength: int): string =
|
||||
|
||||
# Check if the build succeeded or not
|
||||
if exitCode == 0:
|
||||
cq.writeLine(fgGreen, "[*] ", resetStyle, "Agent payload generated successfully.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] ", fgGreen, "[ + ] ", resetStyle, "Agent payload generated successfully.")
|
||||
return exeFile
|
||||
else:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", resetStyle, "Build script exited with code ", $exitCode)
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] ", fgRed, "[ - ] ", resetStyle, "Build script exited with code ", $exitCode)
|
||||
return ""
|
||||
|
||||
except CatchableError as err:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", resetStyle, "An error occurred: ", err.msg)
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] ", fgRed, "[ - ] ", resetStyle, "An error occurred: ", err.msg)
|
||||
return ""
|
||||
|
||||
proc patch(cq: Conquest, unpatchedExePath: string, configuration: seq[byte]): bool =
|
||||
|
||||
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, "Patching profile configuration into agent.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] [ * ] ", resetStyle, "Patching profile configuration into agent.")
|
||||
|
||||
try:
|
||||
var exeBytes = readFile(unpatchedExePath)
|
||||
@@ -103,17 +103,17 @@ proc patch(cq: Conquest, unpatchedExePath: string, configuration: seq[byte]): bo
|
||||
if placeholderPos == -1:
|
||||
raise newException(CatchableError, "Placeholder not found.")
|
||||
|
||||
cq.writeLine(fgBlack, styleBright, "[+] ", resetStyle, fmt"Placeholder found at offset 0x{placeholderPos:08X}.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] [ + ] ", resetStyle, fmt"Placeholder found at offset 0x{placeholderPos:08X}.")
|
||||
|
||||
# Patch placeholder bytes
|
||||
for i, c in Bytes.toString(configuration):
|
||||
exeBytes[placeholderPos + i] = c
|
||||
|
||||
writeFile(unpatchedExePath, exeBytes)
|
||||
cq.writeLine(fgGreen, "[+] ", resetStyle, fmt"Agent payload patched successfully: {unpatchedExePath}.")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] ", fgGreen, "[ + ] ", resetStyle, fmt"Agent payload patched successfully: {unpatchedExePath}.")
|
||||
|
||||
except CatchableError as err:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", resetStyle, "An error occurred: ", err.msg)
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] ", fgRed, styleBright, "[ - ] ", resetStyle, "An error occurred: ", err.msg)
|
||||
return false
|
||||
|
||||
return true
|
||||
@@ -123,7 +123,7 @@ proc agentBuild*(cq: Conquest, listener, sleep: string): bool {.discardable.} =
|
||||
|
||||
# Verify that listener exists
|
||||
if not cq.dbListenerExists(listener.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Listener {listener.toUpperAscii} does not exist.")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] Listener {listener.toUpperAscii} does not exist.")
|
||||
return false
|
||||
|
||||
let listener = cq.listeners[listener.toUpperAscii]
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import strformat, strutils, sequtils, terminal
|
||||
import strformat, strutils, terminal
|
||||
import prologue, parsetoml
|
||||
import sugar
|
||||
|
||||
|
||||
import ../utils
|
||||
import ../api/routes
|
||||
@@ -42,7 +40,7 @@ proc listenerStart*(cq: Conquest, host: string, portStr: string) =
|
||||
# Validate arguments
|
||||
try:
|
||||
if not validatePort(portStr):
|
||||
raise newException(CatchableError,fmt"[-] Invalid port number: {portStr}")
|
||||
raise newException(CatchableError,fmt"[ - ] Invalid port number: {portStr}")
|
||||
|
||||
let port = portStr.parseInt
|
||||
|
||||
@@ -90,10 +88,10 @@ proc listenerStart*(cq: Conquest, host: string, portStr: string) =
|
||||
# Start serving
|
||||
discard listener.runAsync()
|
||||
cq.add(listenerInstance)
|
||||
cq.writeLine(fgGreen, "[+] ", resetStyle, "Started listener", fgGreen, fmt" {name} ", resetStyle, fmt"on {host}:{portStr}.")
|
||||
cq.writeLine(fgGreen, "[ + ] ", resetStyle, "Started listener", fgGreen, fmt" {name} ", resetStyle, fmt"on {host}:{portStr}.")
|
||||
|
||||
except CatchableError as err:
|
||||
cq.writeLine(fgRed, styleBright, "[-] Failed to start listener: ", err.msg)
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] Failed to start listener: ", err.msg)
|
||||
|
||||
proc restartListeners*(cq: Conquest) =
|
||||
let listeners: seq[Listener] = cq.dbGetAllListeners()
|
||||
@@ -131,13 +129,13 @@ proc restartListeners*(cq: Conquest) =
|
||||
|
||||
discard listener.runAsync()
|
||||
cq.add(l)
|
||||
cq.writeLine(fgGreen, "[+] ", resetStyle, "Restarted listener", fgGreen, fmt" {l.listenerId} ", resetStyle, fmt"on {l.address}:{$l.port}.")
|
||||
cq.writeLine(fgGreen, "[ + ] ", resetStyle, "Restarted listener", fgGreen, fmt" {l.listenerId} ", resetStyle, fmt"on {l.address}:{$l.port}.")
|
||||
|
||||
# Delay before serving another listener to avoid crashing the application
|
||||
waitFor sleepAsync(100)
|
||||
|
||||
except CatchableError as err:
|
||||
cq.writeLine(fgRed, styleBright, "[-] Failed to restart listener: ", err.msg)
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] Failed to restart listener: ", err.msg)
|
||||
|
||||
cq.writeLine("")
|
||||
|
||||
@@ -147,14 +145,14 @@ proc listenerStop*(cq: Conquest, name: string) =
|
||||
|
||||
# Check if listener supplied via -n parameter exists in database
|
||||
if not cq.dbListenerExists(name.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Listener {name.toUpperAscii} does not exist.")
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] Listener {name.toUpperAscii} does not exist.")
|
||||
return
|
||||
|
||||
# Remove database entry
|
||||
if not cq.dbDeleteListenerByName(name.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, "[-] Failed to stop listener: ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] Failed to stop listener: ", getCurrentExceptionMsg())
|
||||
return
|
||||
|
||||
cq.delListener(name)
|
||||
cq.writeLine(fgGreen, "[+] ", resetStyle, "Stopped listener ", fgGreen, name.toUpperAscii, resetStyle, ".")
|
||||
cq.writeLine(fgGreen, "[ + ] ", resetStyle, "Stopped listener ", fgGreen, name.toUpperAscii, resetStyle, ".")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import terminal, times, strformat, strutils
|
||||
import times, strformat, strutils
|
||||
import std/[dirs, paths]
|
||||
import ../../common/[types, profile]
|
||||
|
||||
@@ -11,21 +11,17 @@ proc makeAgentLogDirectory*(cq: Conquest, agentId: string): bool =
|
||||
return false
|
||||
|
||||
proc log*(cq: Conquest, logEntry: string) =
|
||||
if cq.interactAgent == nil:
|
||||
return
|
||||
|
||||
let
|
||||
date = now().format("dd-MM-yyyy")
|
||||
timestamp = now().format("dd-MM-yyyy HH:mm:ss")
|
||||
cqDir = cq.profile.getString("conquest_directory")
|
||||
agentLogPath = fmt"{cqDir}/data/logs/{cq.interactAgent.agentId}/{date}.log"
|
||||
agentLogPath = fmt"{cqDir}/data/logs/{cq.interactAgent.agentId}/{date}.session.log"
|
||||
|
||||
# Write log entry to file
|
||||
let file = open(agentLogPath, fmAppend)
|
||||
file.writeLine(fmt"[{timestamp}] {logEntry}")
|
||||
file.writeLine(fmt"{logEntry}")
|
||||
file.flushFile()
|
||||
|
||||
proc extractStrings(args: string): string =
|
||||
proc extractStrings*(args: string): string =
|
||||
if not args.startsWith("("):
|
||||
return args
|
||||
|
||||
@@ -34,24 +30,4 @@ proc extractStrings(args: string): string =
|
||||
for str in args[1..^2].split(", "):
|
||||
if str.startsWith("\""):
|
||||
message &= str
|
||||
return message.replace("\"", "")
|
||||
|
||||
template info*(cq: Conquest, args: varargs[untyped]) =
|
||||
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, args)
|
||||
cq.log("[*] " & extractStrings($(args)))
|
||||
|
||||
template error*(cq: Conquest, args: varargs[untyped]) =
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", resetStyle, args)
|
||||
cq.log("[-] " & extractStrings($(args)))
|
||||
|
||||
template warn*(cq: Conquest, args: varargs[untyped]) =
|
||||
cq.writeLine(fgYellow, "[!] ", resetStyle, args)
|
||||
cq.log("[!] " & extractStrings($(args)))
|
||||
|
||||
template success*(cq: Conquest, args: varargs[untyped]) =
|
||||
cq.writeLine(fgGreen, "[+] ", resetStyle, args)
|
||||
cq.log("[+] " & extractStrings($(args)))
|
||||
|
||||
template output*(cq: Conquest, args: varargs[untyped]) =
|
||||
cq.writeLine(args)
|
||||
cq.log("[>] " & extractStrings($(args)))
|
||||
return message.replace("\"", "")
|
||||
@@ -1,10 +1,10 @@
|
||||
import prompt, terminal, argparse, parsetoml
|
||||
import strutils, strformat, times, system, tables
|
||||
|
||||
import ./[agent, listener, builder, logger]
|
||||
import ./[agent, listener, builder]
|
||||
import ../[globals, utils]
|
||||
import ../db/database
|
||||
import ../../common/[types, utils, crypto, profile]
|
||||
import ../../common/[types, crypto, profile]
|
||||
|
||||
#[
|
||||
Argument parsing
|
||||
@@ -67,8 +67,7 @@ proc handleConsoleCommand(cq: Conquest, args: string) =
|
||||
# Return if no command (or just whitespace) is entered
|
||||
if args.replace(" ", "").len == 0: return
|
||||
|
||||
let date: string = now().format("dd-MM-yyyy HH:mm:ss")
|
||||
cq.writeLine(fgBlue, styleBright, fmt"[{date}] ", resetStyle, styleBright, args)
|
||||
cq.writeLine(fgBlue, styleBright, fmt"[{getTimestamp()}] ", resetStyle, styleBright, args)
|
||||
|
||||
try:
|
||||
let opts = parser.parse(args.split(" ").filterIt(it.len > 0))
|
||||
@@ -115,7 +114,7 @@ proc handleConsoleCommand(cq: Conquest, args: string) =
|
||||
|
||||
# Handle invalid arguments
|
||||
except CatchableError:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
|
||||
cq.writeLine("")
|
||||
|
||||
@@ -150,8 +149,8 @@ proc startServer*(profilePath: string) =
|
||||
try:
|
||||
# Load and parse profile
|
||||
let profile = parseFile(profilePath)
|
||||
styledEcho(fgBlack, styleBright, "[*] ", "Using profile \"", profile.getString("name"), "\" (", profilePath ,").")
|
||||
styledEcho(fgBlack, styleBright, "[*] ", "Using private key \"", profile.getString("private_key_file"), "\".")
|
||||
styledEcho(fgBlack, styleBright, "[ * ] ", "Using profile \"", profile.getString("name"), "\" (", profilePath ,").")
|
||||
styledEcho(fgBlack, styleBright, "[ * ] ", "Using private key \"", profile.getString("private_key_file"), "\".")
|
||||
|
||||
# Initialize framework context
|
||||
cq = Conquest.init(profile)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import times, strformat, terminal, tables, sequtils, strutils
|
||||
|
||||
import ./logger
|
||||
import ../utils
|
||||
import ../protocol/parser
|
||||
import ../../modules/manager
|
||||
@@ -49,15 +48,13 @@ proc handleHelp(cq: Conquest, parsed: seq[string]) =
|
||||
cq.displayHelp()
|
||||
except ValueError:
|
||||
# Command was not found
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] The command '{parsed[1]}' does not exist." & '\n')
|
||||
cq.writeLine(fgRed, styleBright, fmt"[ - ] The command '{parsed[1]}' does not exist." & '\n')
|
||||
|
||||
proc handleAgentCommand*(cq: Conquest, input: string) =
|
||||
# Return if no command (or just whitespace) is entered
|
||||
if input.replace(" ", "").len == 0: return
|
||||
|
||||
let date: string = now().format("dd-MM-yyyy HH:mm:ss")
|
||||
cq.writeLine(fgBlue, styleBright, fmt"[{date}] ", fgYellow, fmt"[{cq.interactAgent.agentId}] ", resetStyle, styleBright, input)
|
||||
cq.log(fmt"Agent command received: {input}")
|
||||
cq.writeLine(fgBlue, styleBright, fmt"[{getTimestamp()}] ", fgYellow, fmt"[{cq.interactAgent.agentId}] ", resetStyle, styleBright, input)
|
||||
|
||||
# Convert user input into sequence of string arguments
|
||||
let parsedArgs = parseInput(input)
|
||||
@@ -80,8 +77,8 @@ proc handleAgentCommand*(cq: Conquest, input: string) =
|
||||
|
||||
# Add task to queue
|
||||
cq.interactAgent.tasks.add(task)
|
||||
cq.info(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, fmt"Tasked agent to {command.description.toLowerAscii()}")
|
||||
cq.writeLine(fgBlack, styleBright, fmt"[{getTimestamp()}] [ * ] ", resetStyle, fmt"Tasked agent to {command.description.toLowerAscii()}")
|
||||
|
||||
except CatchableError:
|
||||
cq.error(getCurrentExceptionMsg() & "\n")
|
||||
cq.writeLine(getCurrentExceptionMsg() & "\n")
|
||||
return
|
||||
@@ -2,7 +2,7 @@ import system, terminal, tiny_sqlite
|
||||
|
||||
import ./[dbAgent, dbListener]
|
||||
import ../utils
|
||||
import ../../common/[types, utils]
|
||||
import ../../common/types
|
||||
|
||||
# Export functions so that only ./db/database is required to be imported
|
||||
export dbAgent, dbListener
|
||||
@@ -41,7 +41,7 @@ proc dbInit*(cq: Conquest) =
|
||||
|
||||
""")
|
||||
|
||||
cq.writeLine(fgBlack, styleBright, "[*] Using new database: \"", cq.dbPath, "\".\n")
|
||||
cq.writeLine(fgBlack, styleBright, "[ * ] Using new database: \"", cq.dbPath, "\".\n")
|
||||
conquestDb.close()
|
||||
except SqliteError as err:
|
||||
cq.writeLine(fgBlack, styleBright, "[*] Using existing database: \"", cq.dbPath, "\".\n")
|
||||
cq.writeLine(fgBlack, styleBright, "[ * ] Using existing database: \"", cq.dbPath, "\".\n")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import system, terminal, tiny_sqlite, times, sequtils
|
||||
|
||||
import ../utils
|
||||
import ../../common/[types, utils]
|
||||
import ../../common/types
|
||||
|
||||
#[
|
||||
Agent database functions - Updated with session key support (no jitter)
|
||||
@@ -21,7 +21,7 @@ proc dbStoreAgent*(cq: Conquest, agent: Agent): bool =
|
||||
|
||||
conquestDb.close()
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
return false
|
||||
|
||||
return true
|
||||
@@ -65,7 +65,7 @@ proc dbGetAllAgents*(cq: Conquest): seq[Agent] =
|
||||
|
||||
conquestDb.close()
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
|
||||
return agents
|
||||
|
||||
@@ -107,7 +107,7 @@ proc dbGetAllAgentsByListener*(cq: Conquest, listenerName: string): seq[Agent] =
|
||||
|
||||
conquestDb.close()
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
|
||||
return agents
|
||||
|
||||
@@ -119,7 +119,7 @@ proc dbDeleteAgentByName*(cq: Conquest, name: string): bool =
|
||||
|
||||
conquestDb.close()
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
return false
|
||||
|
||||
return true
|
||||
@@ -134,7 +134,7 @@ proc dbAgentExists*(cq: Conquest, agentName: string): bool =
|
||||
|
||||
return res.isSome
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
return false
|
||||
|
||||
proc dbUpdateCheckin*(cq: Conquest, agentName: string, timestamp: string): bool =
|
||||
@@ -146,7 +146,7 @@ proc dbUpdateCheckin*(cq: Conquest, agentName: string, timestamp: string): bool
|
||||
conquestDb.close()
|
||||
return true
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
return false
|
||||
|
||||
proc dbUpdateSleep*(cq: Conquest, agentName: string, delay: int): bool =
|
||||
@@ -158,5 +158,5 @@ proc dbUpdateSleep*(cq: Conquest, agentName: string, delay: int): bool =
|
||||
conquestDb.close()
|
||||
return true
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
return false
|
||||
@@ -1,7 +1,7 @@
|
||||
import system, terminal, tiny_sqlite
|
||||
|
||||
import ../utils
|
||||
import ../../common/[types, utils]
|
||||
import ../../common/types
|
||||
|
||||
# Utility functions
|
||||
proc stringToProtocol*(protocol: string): Protocol =
|
||||
@@ -25,7 +25,7 @@ proc dbStoreListener*(cq: Conquest, listener: Listener): bool =
|
||||
|
||||
conquestDb.close()
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
return false
|
||||
|
||||
return true
|
||||
@@ -50,7 +50,7 @@ proc dbGetAllListeners*(cq: Conquest): seq[Listener] =
|
||||
|
||||
conquestDb.close()
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
|
||||
return listeners
|
||||
|
||||
@@ -76,5 +76,5 @@ proc dbListenerExists*(cq: Conquest, listenerName: string): bool =
|
||||
|
||||
return res.isSome
|
||||
except:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
cq.writeLine(fgRed, styleBright, "[ - ] ", getCurrentExceptionMsg())
|
||||
return false
|
||||
@@ -1,5 +1,4 @@
|
||||
import strutils, streams, times, tables
|
||||
import ../utils
|
||||
import ../../common/[types, utils, serialize, sequence, crypto]
|
||||
|
||||
proc serializeTask*(cq: Conquest, task: var Task): seq[byte] =
|
||||
|
||||
@@ -11,9 +11,14 @@ proc validatePort*(portStr: string): bool =
|
||||
except ValueError:
|
||||
return false
|
||||
|
||||
proc getTimestamp*(): string =
|
||||
return now().format("dd-MM-yyyy HH:mm:ss")
|
||||
|
||||
# Function templates and overwrites
|
||||
template writeLine*(cq: Conquest, args: varargs[untyped]) =
|
||||
template writeLine*(cq: Conquest, args: varargs[untyped] = "") =
|
||||
cq.prompt.writeLine(args)
|
||||
if cq.interactAgent != nil:
|
||||
cq.log(extractStrings($(args)))
|
||||
|
||||
proc readLine*(cq: Conquest): string =
|
||||
return cq.prompt.readLine()
|
||||
|
||||
Reference in New Issue
Block a user