mirror of
https://github.com/dobin/SuperMega
synced 2026-06-03 01:27:11 +00:00
refactor: payload data into project
This commit is contained in:
+15
-10
@@ -26,26 +26,31 @@ def asm_to_shellcode(asm_in: FilePath, build_exe: FilePath, shellcode_out: FileP
|
|||||||
f.write(code)
|
f.write(code)
|
||||||
|
|
||||||
|
|
||||||
def merge_loader_payload(shellcode_in: FilePath, shellcode_out: FilePath, payload: FilePath, decoder_style: DecoderStyle):
|
def merge_loader_payload(
|
||||||
logger.info("--[ Merge stager: {} + {} -> {}".format(
|
shellcode_in: FilePath,
|
||||||
shellcode_in, project.payload, shellcode_out))
|
shellcode_out: FilePath,
|
||||||
|
payload_data: bytes,
|
||||||
|
decoder_style: DecoderStyle
|
||||||
|
):
|
||||||
|
logger.info("--[ Merge stager with payload -> {}".format(
|
||||||
|
shellcode_out))
|
||||||
|
|
||||||
with open(shellcode_in, 'rb') as input1:
|
with open(shellcode_in, 'rb') as input1:
|
||||||
data_stager = input1.read()
|
data_stager = input1.read()
|
||||||
with open(project.payload, 'rb') as input2:
|
|
||||||
data_payload = input2.read()
|
|
||||||
|
|
||||||
if project.decoder_style == DecoderStyle.PLAIN_1:
|
if decoder_style == DecoderStyle.PLAIN_1:
|
||||||
# Nothing to do
|
# Nothing to do
|
||||||
pass
|
pass
|
||||||
elif project.decoder_style == DecoderStyle.XOR_1:
|
elif decoder_style == DecoderStyle.XOR_1:
|
||||||
xor_key = 0x42
|
xor_key = 0x42
|
||||||
logger.info("---[ XOR payload with key 0x{:x}".format(xor_key))
|
logger.info("---[ XOR payload with key 0x{:x}".format(xor_key))
|
||||||
data_payload = bytes([byte ^ xor_key for byte in data_payload])
|
payload_data = bytes([byte ^ xor_key for byte in payload_data])
|
||||||
|
|
||||||
logger.info("---[ Size: Stager: {} and Payload: {} Sum: {} ".format(
|
logger.info("---[ Size: Stager: {} and Payload: {} Sum: {} ".format(
|
||||||
len(data_stager), len(data_payload), len(data_stager)+len(data_payload)))
|
len(data_stager), len(payload_data), len(data_stager)+len(payload_data)))
|
||||||
|
|
||||||
with open(shellcode_out, 'wb') as output:
|
with open(shellcode_out, 'wb') as output:
|
||||||
data = data_stager + data_payload
|
# append them
|
||||||
|
data = data_stager + payload_data
|
||||||
output.write(data)
|
output.write(data)
|
||||||
observer.add_code("final_shellcode", data)
|
observer.add_code("final_shellcode", data)
|
||||||
|
|||||||
+7
-1
@@ -5,7 +5,8 @@ from defs import *
|
|||||||
class Project():
|
class Project():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# User, generating normally
|
# User, generating normally
|
||||||
self.payload: FilePath = ""
|
self.payload_path: FilePath = ""
|
||||||
|
self.payload_data: bytes = b""
|
||||||
|
|
||||||
self.source_style: SourceStyle = SourceStyle.peb_walk
|
self.source_style: SourceStyle = SourceStyle.peb_walk
|
||||||
self.alloc_style: AllocStyle = AllocStyle.RWX
|
self.alloc_style: AllocStyle = AllocStyle.RWX
|
||||||
@@ -36,4 +37,9 @@ class Project():
|
|||||||
self.verify_filename: FilePath = r'C:\Temp\a'
|
self.verify_filename: FilePath = r'C:\Temp\a'
|
||||||
|
|
||||||
|
|
||||||
|
def load_payload(self):
|
||||||
|
with open(self.payload_path, 'rb') as input2:
|
||||||
|
self.payload_data = input2.read()
|
||||||
|
|
||||||
|
|
||||||
project = Project()
|
project = Project()
|
||||||
|
|||||||
+7
-8
@@ -74,7 +74,7 @@ def main():
|
|||||||
project.show_command_output = True
|
project.show_command_output = True
|
||||||
|
|
||||||
if args.verify:
|
if args.verify:
|
||||||
project.payload = "shellcodes/createfile.bin"
|
project.payload_path = "shellcodes/createfile.bin"
|
||||||
project.verify = True
|
project.verify = True
|
||||||
|
|
||||||
project.try_start_final_infected_exe = False
|
project.try_start_final_infected_exe = False
|
||||||
@@ -119,7 +119,7 @@ def main():
|
|||||||
if not os.path.isfile(args.shellcode):
|
if not os.path.isfile(args.shellcode):
|
||||||
logger.info("Could not find: {}".format(args.shellcode))
|
logger.info("Could not find: {}".format(args.shellcode))
|
||||||
return
|
return
|
||||||
project.payload = args.shellcode
|
project.payload_path = args.shellcode
|
||||||
if args.inject:
|
if args.inject:
|
||||||
if not os.path.isfile(args.inject):
|
if not os.path.isfile(args.inject):
|
||||||
logger.info("Could not find: {}".format(args.inject))
|
logger.info("Could not find: {}".format(args.inject))
|
||||||
@@ -137,6 +137,9 @@ def start():
|
|||||||
clean_files()
|
clean_files()
|
||||||
delete_all_files_in_directory("logs/")
|
delete_all_files_in_directory("logs/")
|
||||||
|
|
||||||
|
# Load our payload
|
||||||
|
project.load_payload()
|
||||||
|
|
||||||
# Check: Destination EXE capabilities
|
# Check: Destination EXE capabilities
|
||||||
project.exe_capabilities = ExeCapabilities([
|
project.exe_capabilities = ExeCapabilities([
|
||||||
"GetEnvironmentVariableW",
|
"GetEnvironmentVariableW",
|
||||||
@@ -163,14 +166,10 @@ def start():
|
|||||||
|
|
||||||
# Compile: C -> ASM
|
# Compile: C -> ASM
|
||||||
if project.generate_asm_from_c:
|
if project.generate_asm_from_c:
|
||||||
# Find payload size
|
|
||||||
with open(project.payload, 'rb') as input2:
|
|
||||||
data_payload = input2.read()
|
|
||||||
payload_length = len(data_payload)
|
|
||||||
phases.compiler.compile(
|
phases.compiler.compile(
|
||||||
c_in = main_c_file,
|
c_in = main_c_file,
|
||||||
asm_out = main_asm_file,
|
asm_out = main_asm_file,
|
||||||
payload_len = payload_length,
|
payload_len = project.payload_length,
|
||||||
exe_capabilities = project.exe_capabilities)
|
exe_capabilities = project.exe_capabilities)
|
||||||
|
|
||||||
# Assemble: ASM -> Shellcode
|
# Assemble: ASM -> Shellcode
|
||||||
@@ -189,7 +188,7 @@ def start():
|
|||||||
phases.assembler.merge_loader_payload(
|
phases.assembler.merge_loader_payload(
|
||||||
shellcode_in = main_shc_file,
|
shellcode_in = main_shc_file,
|
||||||
shellcode_out = main_shc_file,
|
shellcode_out = main_shc_file,
|
||||||
payload = project.payload,
|
payload_data = project.payload_data,
|
||||||
decoder_style = project.decoder_style)
|
decoder_style = project.decoder_style)
|
||||||
|
|
||||||
if project.verify and project.source_style == SourceStyle.peb_walk:
|
if project.verify and project.source_style == SourceStyle.peb_walk:
|
||||||
|
|||||||
Reference in New Issue
Block a user