Implemented encryption for embedded profile.

This commit is contained in:
Jakob Friedl
2025-08-19 20:03:34 +02:00
parent 72fcb0d610
commit b023fca124
17 changed files with 79 additions and 49 deletions

View File

@@ -1,4 +1,4 @@
import terminal, strformat, strutils, sequtils, tables, json, times, base64, system
import terminal, strformat, strutils, sequtils, tables, times, system
import ../[utils, globals]
import ../db/database
@@ -44,7 +44,7 @@ proc getTasks*(heartbeat: seq[byte]): seq[seq[byte]] =
listenerId = Uuid.toString(request.listenerId)
timestamp = request.timestamp
var result: seq[seq[byte]]
var tasks: seq[seq[byte]]
# Check if listener exists
if not cq.dbListenerExists(listenerId):
@@ -62,9 +62,9 @@ proc getTasks*(heartbeat: seq[byte]): seq[seq[byte]] =
# Return tasks
for task in cq.agents[agentId].tasks.mitems: # Iterate over agents as mutable items in order to modify GMAC tag
let taskData = cq.serializeTask(task)
result.add(taskData)
tasks.add(taskData)
return result
return tasks
proc handleResult*(resultData: seq[byte]) =

View File

@@ -1,6 +1,6 @@
import prologue, json, terminal, strformat, parsetoml, tables
import sequtils, strutils, times, base64
import sugar
import prologue, terminal, strformat, parsetoml, tables
import strutils, times, base64
import ./handlers
import ../[utils, globals]
import ../../common/[types, utils, serialize, profile]

View File

@@ -1,9 +1,9 @@
import terminal, strformat, strutils, tables, times, system, osproc, streams, base64, parsetoml
import terminal, strformat, strutils, tables, times, system, parsetoml
import ./task
import ../utils
import ../db/database
import ../../common/[types, utils]
import ../../common/types
# Utility functions
proc addMultiple*(cq: Conquest, agents: seq[Agent]) =

View File

@@ -1,7 +1,7 @@
import terminal, strformat, strutils, tables, system, osproc, streams, parsetoml
import ../utils
import ../../common/[types, utils, profile, serialize]
import ../../common/[types, utils, profile, serialize, crypto]
import ../db/database
const PLACEHOLDER = "PLACEHOLDER"
@@ -20,9 +20,25 @@ proc serializeConfiguration(cq: Conquest, listener: Listener, sleep: int): seq[b
packer.addDataWithLengthPrefix(string.toBytes(cq.profile.toTomlString()))
let data = packer.pack()
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, "Profile configuration serialized.")
packer.reset()
return data
# Encrypt profile configuration data with a newly generated encryption key
var aesKey = generateKey()
let iv = generateIV()
let (encData, gmac) = encrypt(aesKey, iv, data)
# Add plaintext encryption material in front of the
packer.addData(aesKey)
packer.addData(iv)
packer.addData(gmac)
packer.add(uint32(encData.len()))
let encMaterial = packer.pack()
wipeKey(aesKey)
cq.writeLine(fgBlack, styleBright, "[*] ", resetStyle, "Profile configuration serialized.")
return encMaterial & encData
proc compile(cq: Conquest, placeholderLength: int): string =

View File

@@ -1,9 +1,9 @@
import times, strformat, terminal, tables, json, sequtils, strutils
import times, strformat, terminal, tables, sequtils, strutils
import ../utils
import ../protocol/parser
import ../../modules/manager
import ../../common/[types, utils]
import ../../common/types
proc displayHelp(cq: Conquest) =
cq.writeLine("Available commands:")

View File

@@ -1,4 +1,4 @@
import ../common/[types, utils]
import ../common/types
# Global variable for handling listeners, agents and console output
var cq*: Conquest

View File

@@ -1,4 +1,4 @@
import strutils, strformat, streams, times, tables
import strutils, streams, times, tables
import ../utils
import ../../common/[types, utils, serialize, sequence, crypto]

View File

@@ -1,7 +1,6 @@
import strutils, strformat, times
import strutils, times
import ../utils
import ../../common/[types, utils, sequence, crypto]
import ../../common/[types, sequence, crypto, utils]
proc parseInput*(input: string): seq[string] =
var i = 0
@@ -36,15 +35,15 @@ proc parseInput*(input: string): seq[string] =
proc parseArgument*(argument: Argument, value: string): TaskArg =
var result: TaskArg
result.argType = cast[uint8](argument.argumentType)
var arg: TaskArg
arg.argType = cast[uint8](argument.argumentType)
case argument.argumentType:
of INT:
# Length: 4 bytes
let intValue = cast[uint32](parseUInt(value))
result.data = @[byte(intValue and 0xFF), byte((intValue shr 8) and 0xFF), byte((intValue shr 16) and 0xFF), byte((intValue shr 24) and 0xFF)]
arg.data = @[byte(intValue and 0xFF), byte((intValue shr 8) and 0xFF), byte((intValue shr 16) and 0xFF), byte((intValue shr 24) and 0xFF)]
of LONG:
# Length: 8 bytes
@@ -52,26 +51,26 @@ proc parseArgument*(argument: Argument, value: string): TaskArg =
let intValue = cast[uint64](parseUInt(value))
for i in 0..7:
data[i] = byte((intValue shr (i * 8)) and 0xFF)
result.data = data
arg.data = data
of BOOL:
# Length: 1 byte
if value == "true":
result.data = @[1'u8]
arg.data = @[1'u8]
elif value == "false":
result.data = @[0'u8]
arg.data = @[0'u8]
else:
raise newException(ValueError, "Invalid value for boolean argument.")
of STRING:
result.data = cast[seq[byte]](value)
arg.data = cast[seq[byte]](value)
of BINARY:
# Read file as binary stream
discard
return result
return arg
proc createTask*(cq: Conquest, command: Command, arguments: seq[string]): Task =

View File

@@ -1,7 +1,7 @@
import strutils, terminal, tables, sequtils, times, strformat, random, prompt
import strutils, terminal, tables, sequtils, times, strformat, prompt
import std/wordwrap
import ../common/[types, utils]
import ../common/types
# Utility functions
proc parseOctets*(ip: string): tuple[first, second, third, fourth: int] =