ui: nicer output

This commit is contained in:
Dobin
2024-02-19 20:34:31 +00:00
parent 2f9ba27ed1
commit fb23835d51
9 changed files with 22 additions and 22 deletions
+2 -3
View File
@@ -43,9 +43,8 @@ def project():
# handle special cases # handle special cases
if '_orig' in file: if '_orig' in file:
asm_a = data asm_a = data
if '_cleanup' in file: if '_updated' in file:
asm_b = data asm_b = data
data = highlight(data, NasmLexer(), HtmlFormatter(full=False)) data = highlight(data, NasmLexer(), HtmlFormatter(full=False))
elif '_shc' in file: elif '_shc' in file:
if '.txt' in file: if '.txt' in file:
@@ -88,7 +87,7 @@ def project():
} }
log_files.append(entry) log_files.append(entry)
id += 1 id += 1
asm_a = "" #asm_a = ""
asm_b = "" asm_b = ""
+1 -1
View File
@@ -13,7 +13,7 @@ SHC_VERIFY_SLEEP = 0.1
def clean_files(): def clean_files():
logger.info("--[ Remove old files") logger.info("--( Remove old files")
files_to_clean = [ files_to_clean = [
# compile artefacts in current dir # compile artefacts in current dir
+3 -2
View File
@@ -43,6 +43,7 @@ class ExeInfo():
def parse_from_exe(self, filepath): def parse_from_exe(self, filepath):
logger.info("--[ Analyzing: {}".format(filepath))
pe = pefile.PE(filepath) pe = pefile.PE(filepath)
if pe.FILE_HEADER.Machine != 0x8664: if pe.FILE_HEADER.Machine != 0x8664:
@@ -61,7 +62,7 @@ class ExeInfo():
self.code_section = pehelper.get_code_section(pe) self.code_section = pehelper.get_code_section(pe)
self.code_virtaddr = self.code_section.VirtualAddress self.code_virtaddr = self.code_section.VirtualAddress
self.code_size = self.code_section.Misc_VirtualSize self.code_size = self.code_section.Misc_VirtualSize
logger.info("--[ Injectable: Chosen code section: {} at 0x{:x} size: {}".format( logger.info("---[ Injectable: Chosen code section: {} at 0x{:x} size: {}".format(
self.code_section.Name.decode().rstrip('\x00'), self.code_section.Name.decode().rstrip('\x00'),
self.code_virtaddr, self.code_virtaddr,
self.code_size)) self.code_size))
@@ -93,7 +94,7 @@ class ExeInfo():
for func_name in needs: for func_name in needs:
addr = pehelper.get_addr_for(self.iat, func_name) addr = pehelper.get_addr_for(self.iat, func_name)
if addr == 0: if addr == 0:
logging.info("Not available as import: {}".format(func_name)) logging.info("---( Function not available as import: {}".format(func_name))
is_ok = False is_ok = False
return is_ok return is_ok
+1 -1
View File
@@ -15,7 +15,7 @@ def extract_code_from_exe(exe_file: FilePath) -> bytes:
section = get_code_section(pe) section = get_code_section(pe)
data: bytes = section.get_data() data: bytes = section.get_data()
data = remove_trailing_null_bytes(data) data = remove_trailing_null_bytes(data)
logger.info("---[ Extract code section size: {} / {}".format( logger.debug("---[ Extract code section size: {} / {}".format(
len(data), section.Misc_VirtualSize)) len(data), section.Misc_VirtualSize))
pe.close() pe.close()
return data return data
+7 -7
View File
@@ -21,7 +21,6 @@ def compile(
logger.info("--[ Compile C to ASM: {} -> {} ".format(c_in, asm_out)) logger.info("--[ Compile C to ASM: {} -> {} ".format(c_in, asm_out))
# Compile C To Assembly (text) # Compile C To Assembly (text)
logger.info("---[ Make ASM from C: {} ".format(c_in))
run_process_checkret([ run_process_checkret([
config.get("path_cl"), config.get("path_cl"),
"/c", "/c",
@@ -35,14 +34,14 @@ def compile(
observer.add_text("carrier_asm_orig", file_readall_text(asm_out)) observer.add_text("carrier_asm_orig", file_readall_text(asm_out))
# Assembly text fixup (SuperMega) # Assembly text fixup (SuperMega)
logger.info("---[ Fixup : {} ".format(asm_out)) logger.info("---[ ASM Fixup : {} ".format(asm_out))
if not fixup_asm_file(asm_out, payload_len, short_call_patching=short_call_patching): if not fixup_asm_file(asm_out, payload_len, short_call_patching=short_call_patching):
raise Exception("Error: Fixup failed") raise Exception("Error: Fixup failed")
observer.add_text("carrier_asm_fixup", file_readall_text(asm_out)) #observer.add_text("carrier_asm_fixup", file_readall_text(asm_out))
# Assembly cleanup (masm_shc) # Assembly cleanup (masm_shc)
asm_clean_file = asm_out + ".clean" asm_clean_file = asm_out + ".clean"
logger.info("---[ Cleanup: {} ".format(asm_out)) logger.info("---[ ASM masm_shc: {} ".format(asm_out))
run_process_checkret([ run_process_checkret([
config.get("path_masmshc"), config.get("path_masmshc"),
asm_out, asm_out,
@@ -53,7 +52,7 @@ def compile(
# Move to destination we expect # Move to destination we expect
shutil.move(asm_clean_file, asm_out) shutil.move(asm_clean_file, asm_out)
observer.add_text("carrier_asm_cleanup", file_readall_text(asm_out)) #observer.add_text("carrier_asm_cleanup", file_readall_text(asm_out))
def bytes_to_asm_db(byte_data: bytes) -> bytes: def bytes_to_asm_db(byte_data: bytes) -> bytes:
@@ -148,7 +147,8 @@ def fixup_iat_reuse(filename: FilePath, exe_info):
exe_info.add_iat_resolve(func_name, randbytes) exe_info.add_iat_resolve(func_name, randbytes)
logger.info(" > Replace func name: {} with {}".format( logger.info(" > Replace func name: {} with {}".format(
func_name, randbytes)) func_name, randbytes.hex()))
with open(filename, 'w') as asmfile: with open(filename, 'w') as asmfile:
asmfile.writelines(lines) asmfile.writelines(lines)
#observer.add_text("carrier_asm_iat_patch", file_readall_text(filename))
+2 -4
View File
@@ -20,12 +20,10 @@ def inject_exe(
exe_out: FilePath, exe_out: FilePath,
inject_mode: int, inject_mode: int,
): ):
logger.info("--[ Injecting: {} into: {} -> {} mode {}".format( logger.info("--[ Injecting: {} into: {} -> {} (mode: {})".format(
shellcode_in, exe_in, exe_out, inject_mode shellcode_in, exe_in, exe_out, inject_mode
)) ))
logger.warn("--[ Inject mode: {}".format(rbrunmode_str(inject_mode))) logger.warn("---[ Inject mode: {}".format(rbrunmode_str(inject_mode)))
# create copy of file exe_in to exe_out # create copy of file exe_in to exe_out
shutil.copyfile(exe_in, exe_out) shutil.copyfile(exe_in, exe_out)
+1 -1
View File
@@ -30,7 +30,7 @@ def create_c_from_template(
plugin_executor = "" plugin_executor = ""
logger.info("--[ Create C from template: {} {} {} {} {}".format( logger.info("--[ Create C from template: {} {} {} {} {}".format(
source_style, alloc_style, exec_style, decoder_style, payload_len source_style.value, alloc_style.value, exec_style.value, decoder_style.value, payload_len
)) ))
filepath = "plugins/allocator/{}.c".format(alloc_style.value) filepath = "plugins/allocator/{}.c".format(alloc_style.value)
+2 -2
View File
@@ -38,13 +38,13 @@ class Project():
def load_payload(self): def load_payload(self):
logging.info("Load payload: {}".format(self.payload_path)) logging.info("--( Load payload: {}".format(self.payload_path))
with open(self.payload_path, 'rb') as input2: with open(self.payload_path, 'rb') as input2:
self.payload_data = input2.read() self.payload_data = input2.read()
def load_injectable(self): def load_injectable(self):
logging.info("Load injectable: {}".format(self.inject_exe_in)) logging.info("--( Load injectable: {}".format(self.inject_exe_in))
self.exe_info = ExeInfo() self.exe_info = ExeInfo()
self.exe_info.parse_from_exe(self.inject_exe_in) self.exe_info.parse_from_exe(self.inject_exe_in)
+3 -1
View File
@@ -135,7 +135,7 @@ def start(project: Project):
asm_out = main_asm_file, asm_out = main_asm_file,
payload_len = len(project.payload_data), payload_len = len(project.payload_data),
short_call_patching = project.short_call_patching) short_call_patching = project.short_call_patching)
# Decide if we can use IAT_REUSE (all function calls available as import) # Decide if we can use IAT_REUSE (all function calls available as import)
required_functions = phases.compiler.get_function_stubs(main_asm_file) required_functions = phases.compiler.get_function_stubs(main_asm_file)
if project.exe_info.has_all_functions(required_functions): if project.exe_info.has_all_functions(required_functions):
@@ -143,6 +143,7 @@ def start(project: Project):
logger.warning("--[ SourceStyle: Using IAT_REUSE".format()) logger.warning("--[ SourceStyle: Using IAT_REUSE".format())
# all good, patch ASM # all good, patch ASM
phases.compiler.fixup_iat_reuse(main_asm_file, project.exe_info) phases.compiler.fixup_iat_reuse(main_asm_file, project.exe_info)
observer.add_text("carrier_asm_updated", file_readall_text(main_asm_file))
else: else:
# Not good, Fall back to PEB_WALK # Not good, Fall back to PEB_WALK
project.source_style = SourceStyle.peb_walk project.source_style = SourceStyle.peb_walk
@@ -163,6 +164,7 @@ def start(project: Project):
c_in = main_c_file, c_in = main_c_file,
asm_out = main_asm_file, asm_out = main_asm_file,
payload_len = len(project.payload_data)) payload_len = len(project.payload_data))
observer.add_text("carrier_asm_updated", file_readall_text(main_asm_file))
# Assemble: ASM -> Shellcode # Assemble: ASM -> Shellcode
if project.generate_shc_from_asm: if project.generate_shc_from_asm: