From efb7b0b0eec71e506d80fef62eda44ef1fbee61d Mon Sep 17 00:00:00 2001 From: Dobin Date: Thu, 8 Feb 2024 12:38:56 +0000 Subject: [PATCH] feature: config file --- config.py | 34 ++++++++++++++++++++++++++++++++++ config.yaml | 7 +++++++ helper.py | 10 +++------- phases/asmtoshc.py | 6 ++++-- phases/ctoasm.py | 5 +++-- supermega.py | 14 +++++++------- 6 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 config.py create mode 100644 config.yaml diff --git a/config.py b/config.py new file mode 100644 index 0000000..edeccae --- /dev/null +++ b/config.py @@ -0,0 +1,34 @@ +import yaml +import os +import logging + +CONFIG_FILE = os.path.join(os.path.dirname(__file__), "config.yaml") + +class Config(object): + def __init__(self): + self.data = {} + + def getConfigPath(self): + return CONFIG_FILE + + def getConfig(self): + return self.data + + def load(self): + with open(CONFIG_FILE) as jsonfile: + try: + self.data = yaml.safe_load(jsonfile) + except yaml.YAMLError as e: + print('Decoding {} as failed with: {}'.format(CONFIG_FILE, e)) + quit() + + if 'server' in os.environ: + server = os.environ["server"] + self.data["server"] = { "server": server } + print("Using ENV: server={}, overwriting all others from config.yaml".format( + server)) + + def get(self, value): + return self.data.get(value, "") + +config = Config() \ No newline at end of file diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..c264ac1 --- /dev/null +++ b/config.yaml @@ -0,0 +1,7 @@ +path_cl: 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\cl.exe' +path_ml64: 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\ml64.exe' + +path_masmshc: 'C:\Users\hacker\Source\Repos\masm_shc\out\build\x64-Debug\masm_shc\masm_shc.exe' +path_runshc: 'C:\Users\hacker\Source\Repos\masm_shc\out\build\x64-Debug\runshc\runshc.exe' +#- path_shexec = r'C:\Research\hasherezade\exec_fiber\sh-exec-fiber.exe' + diff --git a/helper.py b/helper.py index 3bff2cd..1b7a1d6 100644 --- a/helper.py +++ b/helper.py @@ -5,15 +5,11 @@ import shutil import pathlib import sys +from config import config + SHC_VERIFY_SLEEP = 0.1 -path_cl = r'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\cl.exe' -path_ml64 = r'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\ml64.exe' - -path_masmshc = r'C:\Users\hacker\Source\Repos\masm_shc\out\build\x64-Debug\masm_shc\masm_shc.exe' -path_runshc = r'C:\Users\hacker\Source\Repos\masm_shc\out\build\x64-Debug\runshc\runshc.exe' -#path_shexec = r'C:\Research\hasherezade\exec_fiber\sh-exec-fiber.exe' verify_filename = r'C:\Temp\a' build_dir = "build" @@ -54,7 +50,7 @@ def run_process_checkret(args): def try_start_shellcode(shc_file): print("--[ Blindly execute shellcode: {} ]".format(shc_file)) subprocess.run([ - path_runshc, + config.get["path_runshc"], shc_file, ]) # , check=True diff --git a/phases/asmtoshc.py b/phases/asmtoshc.py index 841396e..d820be8 100644 --- a/phases/asmtoshc.py +++ b/phases/asmtoshc.py @@ -1,13 +1,15 @@ -from helper import * import pefile +from helper import * +from config import config + def make_shc_from_asm(asm_file, exe_file, shc_file): print("--[ Assemble to exe: {} -> {} -> {} ]".format(asm_file, exe_file, shc_file)) print("---[ Assemble ASM to EXE: {} -> {} ]".format(asm_file, exe_file)) run_process_checkret([ - path_ml64, + config.get("path_ml64"), asm_file, "/link", "/OUT:{}".format(exe_file), diff --git a/phases/ctoasm.py b/phases/ctoasm.py index c75f795..c66a322 100644 --- a/phases/ctoasm.py +++ b/phases/ctoasm.py @@ -1,4 +1,5 @@ from helper import * +from config import config def make_c_to_asm(c_file, asm_file, payload_len): @@ -13,7 +14,7 @@ def make_c_to_asm(c_file, asm_file, payload_len): # Phase 1: Compile print("---[ Compile: {} ]".format(c_file)) run_process_checkret([ - path_cl, + config.get("path_cl"), "/c", "/FA", "/GS-", @@ -29,7 +30,7 @@ def make_c_to_asm(c_file, asm_file, payload_len): asm_clean_file = asm_file + ".clean" print("---[ Cleanup: {} ]".format(asm_file)) run_process_checkret([ - path_masmshc, + config.get("path_masmshc"), asm_file, asm_clean_file, ]) diff --git a/supermega.py b/supermega.py index 90d5258..02d9495 100644 --- a/supermega.py +++ b/supermega.py @@ -3,6 +3,7 @@ from enum import Enum from helper import * import argparse +from config import config from phases.ctoasm import * from phases.asmtoshc import * from phases.shctoexe import * @@ -50,8 +51,8 @@ options_default = { "cleanup_files_on_exit": True, # For debugging: Can disable some steps - "generate_asm_from_c": True, - "generate_shc_from_asm": True, + "generate_asm_from_c": True, # phase 2 + "generate_shc_from_asm": True, # phase 3 # Not working atm "obfuscate_shc_loader": False, @@ -86,8 +87,8 @@ options_verify = { "inject_exe_out": "out/procexp64-a.exe", # For debugging: Can disable some steps - "generate_asm_from_c": True, - "generate_shc_from_asm": True, + "generate_asm_from_c": True, # phase 2 + "generate_shc_from_asm": True, # phase 3 # cleanup "cleanup_files_on_start": True, @@ -98,8 +99,6 @@ options_verify = { "test_obfuscated_shc": False, } - - options = None main_c_file = os.path.join(build_dir, "main.c") @@ -123,6 +122,7 @@ debug_data = { def main(): print("Super Mega") + config.load() parser = argparse.ArgumentParser(description='SuperMega shellcode loader') parser.add_argument('--shellcode', type=str, help='The path to the file of your payload shellcode') @@ -255,7 +255,7 @@ def verify_shellcode(shc_name): pathlib.Path(verify_filename).unlink(missing_ok=True) subprocess.run([ - path_runshc, + config.get("path_runshc"), "{}".format(shc_name), ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # , check=True time.sleep(SHC_VERIFY_SLEEP)