feature: rwx execution

This commit is contained in:
Dobin
2024-02-11 20:46:33 +00:00
parent 547cd94dd5
commit 6fe1f192b7
9 changed files with 166 additions and 76 deletions
+2 -1
View File
@@ -6,6 +6,7 @@ from helper import *
from config import config
from observer import observer
from project import project
from pehelper import *
def make_shc_from_asm(asm_file, exe_file, shc_file):
@@ -24,7 +25,7 @@ def make_shc_from_asm(asm_file, exe_file, shc_file):
return
print("---[ EXE to SHC: {} -> {} ]".format(exe_file, shc_file))
code = get_code_section(exe_file)
code = get_code_section_data(exe_file)
with open(shc_file, 'wb') as f:
f.write(code)
+1
View File
@@ -45,6 +45,7 @@ def create_c_from_template():
with open("build/main.c", "w", encoding='utf-8') as file:
file.write(rendered_template)
observer.add_text("main_c_rendered", rendered_template)
shutil.copy("source/peb_walk/peb_lookup.h", "build/peb_lookup.h")
else:
observer.add_text("main_c", file_readall_text("source/peb_walk/main.c"))
+19 -19
View File
@@ -29,27 +29,27 @@ def inject_exe(shc_file: FilePath):
exe_out
])
# get code section of exe_out
code = get_code_section(exe_out)
# replace IAT in shellcode in code
# and re-implant it
for cap in exe_capabilities.get_all().values():
if not cap.id in code:
print("Capability ID {} not found, abort".format(cap.id))
raise Exception()
off = code.index(cap.id)
current_address = off + exe_capabilities.image_base + exe_capabilities.text_virtaddr
destination_address = cap.addr
print(" Replace at 0x{:x} with call to 0x{:x}".format(
current_address, destination_address
))
jmp = assemble_and_disassemble_jump(
current_address, destination_address
)
code = code.replace(cap.id, jmp)
write_code_section(exe_out, code)
if project.source_style == SourceStyle.iat_reuse:
# get code section of exe_out
code = get_code_section_data(exe_out)
for cap in exe_capabilities.get_all().values():
if not cap.id in code:
print("Capability ID {} not found, abort".format(cap.id))
raise Exception()
off = code.index(cap.id)
current_address = off + exe_capabilities.image_base + exe_capabilities.text_virtaddr
destination_address = cap.addr
print(" Replace at 0x{:x} with call to 0x{:x}".format(
current_address, destination_address
))
jmp = assemble_and_disassemble_jump(
current_address, destination_address
)
code = code.replace(cap.id, jmp)
write_code_section(exe_out, code)
def verify_injected_exe(exefile):