mirror of
https://github.com/dobin/SuperMega
synced 2026-06-02 17:27:10 +00:00
refactor: less files generated
This commit is contained in:
@@ -16,15 +16,7 @@ path_runshc = r'C:\Users\hacker\Source\Repos\masm_shc\out\build\x64-Debug\runshc
|
||||
#path_shexec = r'C:\Research\hasherezade\exec_fiber\sh-exec-fiber.exe'
|
||||
|
||||
verify_filename = r'C:\Temp\a'
|
||||
|
||||
build_dir = "build"
|
||||
main_c_file = os.path.join(build_dir, "main.c")
|
||||
main_asm_file = os.path.join(build_dir, "main.asm")
|
||||
main_asm_clean_file = os.path.join(build_dir, "main-clean.asm")
|
||||
|
||||
main_exe_clean_file = os.path.join(build_dir, "main-clean.exe")
|
||||
main_bin_clean_file = os.path.join(build_dir, "main-clean.bin")
|
||||
main_bin_clean_append_file = os.path.join(build_dir, "main-clean-append.bin")
|
||||
|
||||
|
||||
def clean_files():
|
||||
@@ -49,7 +41,7 @@ def clean_files():
|
||||
pathlib.Path(file).unlink(missing_ok=True)
|
||||
|
||||
|
||||
def make_c_to_asm(c_file, asm_file, asm_clean_file, payload_len):
|
||||
def make_c_to_asm(c_file, asm_file, payload_len):
|
||||
print("--[ Compile C source to ASM: {} -> {} ]".format(c_file, asm_file))
|
||||
subprocess.run([
|
||||
path_cl,
|
||||
@@ -65,6 +57,8 @@ def make_c_to_asm(c_file, asm_file, asm_clean_file, payload_len):
|
||||
else:
|
||||
print(" > Generated {}".format(asm_file))
|
||||
|
||||
# need different file
|
||||
asm_clean_file = asm_file + ".clean"
|
||||
print("--[ Cleanup ASM: {} -> {} ]".format(asm_file, asm_clean_file))
|
||||
subprocess.run([
|
||||
path_masmshc,
|
||||
@@ -76,9 +70,13 @@ def make_c_to_asm(c_file, asm_file, asm_clean_file, payload_len):
|
||||
return
|
||||
else:
|
||||
print(" > Generated {}".format(asm_clean_file))
|
||||
shutil.move(asm_clean_file, asm_file)
|
||||
|
||||
print("--[ Fixup ASM: {} ]".format(asm_clean_file))
|
||||
fixup_asm_file(asm_clean_file, payload_len)
|
||||
fixup_asm_file(asm_file, payload_len)
|
||||
|
||||
input("Press Enter to continue...")
|
||||
|
||||
|
||||
|
||||
def fixup_asm_file(filename, payload_len):
|
||||
@@ -114,13 +112,14 @@ def fixup_asm_file(filename, payload_len):
|
||||
|
||||
def make_shc_from_asm(asm_clean_file, exe_file, shc_file):
|
||||
print("--[ Assemble to exe ]")
|
||||
print("AAAAAA: {}".format(exe_file))
|
||||
subprocess.run([
|
||||
path_ml64,
|
||||
asm_clean_file,
|
||||
"/link",
|
||||
"/OUT:build\main-clean.exe",
|
||||
"/OUT:{}".format(exe_file),
|
||||
"/entry:AlignRSP"
|
||||
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
], check=True)
|
||||
if not os.path.isfile(exe_file):
|
||||
print("Error")
|
||||
return
|
||||
|
||||
+17
-10
@@ -75,6 +75,13 @@ options_verify = {
|
||||
options = options_verify
|
||||
|
||||
|
||||
main_c_file = os.path.join(build_dir, "main.c")
|
||||
main_asm_file = os.path.join(build_dir, "main.asm")
|
||||
main_exe_file = os.path.join(build_dir, "main.exe")
|
||||
main_shc_file = os.path.join(build_dir, "main.bin")
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
print("Super Mega")
|
||||
|
||||
@@ -85,13 +92,13 @@ def main():
|
||||
with open(options["payload"], 'rb') as input2:
|
||||
data_payload = input2.read()
|
||||
l = len(data_payload)
|
||||
make_c_to_asm(main_c_file, main_asm_file, main_asm_clean_file, l)
|
||||
make_c_to_asm(main_c_file, main_asm_file, l)
|
||||
|
||||
if options["generate_asm_from_c"]:
|
||||
make_shc_from_asm(main_asm_clean_file, main_exe_clean_file, main_bin_clean_file)
|
||||
make_shc_from_asm(main_asm_file, main_exe_file, main_shc_file)
|
||||
|
||||
if options["test_loader_shellcode"]:
|
||||
test_shellcode(main_bin_clean_file)
|
||||
test_shellcode(main_shc_file)
|
||||
|
||||
# SGN seems buggy atm
|
||||
#if options["obfuscate_shc_loader"]:
|
||||
@@ -102,7 +109,7 @@ def main():
|
||||
# return
|
||||
|
||||
if options["dataref_style"] == DataRefStyle.APPEND:
|
||||
with open(main_bin_clean_file, 'rb') as input1:
|
||||
with open(main_shc_file, 'rb') as input1:
|
||||
data_stager = input1.read()
|
||||
|
||||
with open(options["payload"], 'rb') as input2:
|
||||
@@ -111,26 +118,26 @@ def main():
|
||||
print("--[ Integrate Stager: {} Payload: {} (sum: {})]".format(
|
||||
len(data_stager), len(data_payload), len(data_stager)+len(data_payload)))
|
||||
|
||||
with open(main_bin_clean_append_file, 'wb') as output:
|
||||
with open(main_shc_file, 'wb') as output:
|
||||
output.write(data_stager)
|
||||
output.write(data_payload)
|
||||
|
||||
print("---[ Final shellcode available at: {} ]".format(main_bin_clean_append_file))
|
||||
print("---[ Final shellcode available at: {} ]".format(main_shc_file))
|
||||
|
||||
if options["verify"]:
|
||||
print("--[ Verify final shellcode ]")
|
||||
if not verify_shellcode(main_bin_clean_append_file):
|
||||
if not verify_shellcode(main_shc_file):
|
||||
return
|
||||
|
||||
if options["exec_final_shellcode"]:
|
||||
print("--[ Test Append shellcode ]")
|
||||
test_shellcode(main_bin_clean_append_file)
|
||||
test_shellcode(main_shc_file)
|
||||
|
||||
# copy it to out
|
||||
shutil.copyfile(main_bin_clean_append_file, os.path.join("out/", os.path.basename(main_bin_clean_append_file)))
|
||||
#shutil.copyfile(main_shc_file, os.path.join("out/", os.path.basename(main_bin_clean_append_file)))
|
||||
|
||||
if options["inject_exe"]:
|
||||
inject_exe(main_bin_clean_append_file, options["inject_exe_in"], options["inject_exe_out"])
|
||||
inject_exe(main_shc_file, options["inject_exe_in"], options["inject_exe_out"])
|
||||
if options["verify"]:
|
||||
print("--[ Verify final exe ]")
|
||||
verify_injected_exe(options["inject_exe_out"])
|
||||
|
||||
Reference in New Issue
Block a user