From b7ac5938a41bbfa738e5be40f5257b7b12e2b3ac Mon Sep 17 00:00:00 2001 From: Dobin Date: Mon, 19 Feb 2024 20:39:00 +0000 Subject: [PATCH] debug: config.debug feature for more logs/ --- config.py | 1 + phases/compiler.py | 11 ++++++++--- phases/injector.py | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/config.py b/config.py index 279e752..1bfecbc 100644 --- a/config.py +++ b/config.py @@ -8,6 +8,7 @@ class Config(object): def __init__(self): self.data = {} self.ShowCommandOutput: bool = False + self.debug: bool = False def getConfigPath(self): return CONFIG_FILE diff --git a/phases/compiler.py b/phases/compiler.py index 45f075d..9cb8a05 100644 --- a/phases/compiler.py +++ b/phases/compiler.py @@ -37,7 +37,9 @@ def compile( logger.info("---[ ASM Fixup : {} ".format(asm_out)) if not fixup_asm_file(asm_out, payload_len, short_call_patching=short_call_patching): raise Exception("Error: Fixup failed") - #observer.add_text("carrier_asm_fixup", file_readall_text(asm_out)) + + if config.debug: + observer.add_text("carrier_asm_fixup", file_readall_text(asm_out)) # Assembly cleanup (masm_shc) asm_clean_file = asm_out + ".clean" @@ -52,7 +54,8 @@ def compile( # Move to destination we expect shutil.move(asm_clean_file, asm_out) - #observer.add_text("carrier_asm_cleanup", file_readall_text(asm_out)) + if config.debug: + observer.add_text("carrier_asm_cleanup", file_readall_text(asm_out)) def bytes_to_asm_db(byte_data: bytes) -> bytes: @@ -151,4 +154,6 @@ def fixup_iat_reuse(filename: FilePath, exe_info): with open(filename, 'w') as asmfile: asmfile.writelines(lines) - #observer.add_text("carrier_asm_iat_patch", file_readall_text(filename)) + + if config.debug: + observer.add_text("carrier_asm_iat_patch", file_readall_text(filename)) diff --git a/phases/injector.py b/phases/injector.py index f41780d..af7f718 100644 --- a/phases/injector.py +++ b/phases/injector.py @@ -47,8 +47,9 @@ def inject_exe( code = extract_code_from_exe(exe_out) in_code = code[peinj.shellcodeOffsetRel:peinj.shellcodeOffsetRel+shellcode_len] jmp_code = code[peinj.backdoorOffsetRel:peinj.backdoorOffsetRel+12] - observer.add_code("exe_extracted_loader", in_code) - observer.add_code("exe_extracted_jmp", jmp_code) + if config.debug: + observer.add_code("exe_extracted_loader", in_code) + observer.add_code("exe_extracted_jmp", jmp_code) if in_code != shellcode: raise Exception("Shellcode injection error")