Implemented switch to agent interaction mode.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import terminal, strformat, strutils, tables
|
||||
import ./commands
|
||||
import ../[types, globals, utils]
|
||||
import ../db/database
|
||||
|
||||
@@ -84,12 +85,27 @@ proc agentKill*(cq: Conquest, name: string) =
|
||||
cq.writeLine(fgYellow, styleBright, "[+] ", resetStyle, "Terminated agent ", fgYellow, styleBright, name.toUpperAscii, resetStyle, ".")
|
||||
|
||||
# Switch to interact mode
|
||||
proc agentInteract*(cq: Conquest, args: varargs[string]) =
|
||||
proc agentInteract*(cq: Conquest, name: string) =
|
||||
|
||||
cq.setIndicator("[AGENT] (username@hostname)> ")
|
||||
cq.setStatusBar(@[("[mode]", "interact"), ("[username]", "X"), ("[hostname]", "4"), ("[ip]", "127.0.0.1"), ("[domain]", "domain.local")])
|
||||
# Verify that agent exists
|
||||
if not cq.dbAgentExists(name.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Agent {name.toUpperAscii} does not exist.")
|
||||
return
|
||||
|
||||
var command: string = cq.readLine()
|
||||
let agent = cq.agents[name.toUpperAscii]
|
||||
var command: string = ""
|
||||
|
||||
# Change prompt indicator to show agent interaction
|
||||
cq.setIndicator(fmt"[{agent.name}]> ")
|
||||
cq.setStatusBar(@[("[mode]", "interact"), ("[username]", fmt"{agent.username}"), ("[hostname]", fmt"{agent.hostname}"), ("[ip]", fmt"{agent.ip}"), ("[domain]", fmt"{agent.domain}")])
|
||||
cq.writeLine(fgYellow, "[+] ", resetStyle, fmt"Started interacting with agent ", fgYellow, agent.name, resetStyle, ". Type 'help' to list available commands.\n")
|
||||
cq.interactAgent = agent
|
||||
|
||||
while command != "exit":
|
||||
command = cq.readLine()
|
||||
cq.withOutput(handleAgentCommand, command)
|
||||
|
||||
cq.interactAgent = nil
|
||||
|
||||
#[
|
||||
Agent API
|
||||
|
||||
47
server/agent/commands.nim
Normal file
47
server/agent/commands.nim
Normal file
@@ -0,0 +1,47 @@
|
||||
import argparse, times, strformat, terminal
|
||||
import ../[types]
|
||||
|
||||
#[
|
||||
Agnet Argument parsing
|
||||
]#
|
||||
var parser = newParser:
|
||||
help("Conquest Command & Control")
|
||||
|
||||
command("shell"):
|
||||
help("Execute a shell command.")
|
||||
|
||||
command("help"):
|
||||
nohelpflag()
|
||||
|
||||
command("exit"):
|
||||
nohelpflag()
|
||||
|
||||
proc handleAgentCommand*(cq: Conquest, args: varargs[string]) =
|
||||
|
||||
# Return if no command (or just whitespace) is entered
|
||||
if args[0].replace(" ", "").len == 0: return
|
||||
|
||||
let date: string = now().format("dd-MM-yyyy HH:mm:ss")
|
||||
cq.writeLine(fgCyan, fmt"[{date}] ", fgYellow, fmt"[{cq.interactAgent.name}] ", resetStyle, styleBright, args[0])
|
||||
|
||||
try:
|
||||
let opts = parser.parse(args[0].split(" ").filterIt(it.len > 0))
|
||||
|
||||
case opts.command
|
||||
|
||||
of "exit": # Exit program
|
||||
discard
|
||||
|
||||
of "help": # Display help menu
|
||||
cq.writeLine(parser.help())
|
||||
|
||||
# Handle help flag
|
||||
except ShortCircuit as err:
|
||||
if err.flag == "argparse_help":
|
||||
cq.writeLine(err.help)
|
||||
|
||||
# Handle invalid arguments
|
||||
except UsageError:
|
||||
cq.writeLine(fgRed, styleBright, "[-] ", getCurrentExceptionMsg())
|
||||
|
||||
cq.writeLine("")
|
||||
Reference in New Issue
Block a user