mirror of
https://github.com/dobin/SuperMega
synced 2026-06-02 17:27:10 +00:00
refactor: move directories around 1/2
This commit is contained in:
@@ -14,7 +14,6 @@ from model.carrier import Carrier
|
||||
from model.exehost import ExeHost
|
||||
|
||||
logger = logging.getLogger("Compiler")
|
||||
use_templates = True
|
||||
|
||||
# NOTE: Mostly copy-pasted from compiler.py::compile()
|
||||
def compile_dev(
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ logger = logging.getLogger("Injector")
|
||||
|
||||
|
||||
def inject_exe(
|
||||
main_shc_file: FilePath,
|
||||
main_shc_path: FilePath,
|
||||
settings: Settings,
|
||||
project: Project,
|
||||
):
|
||||
@@ -32,7 +32,7 @@ def inject_exe(
|
||||
|
||||
# Read prepared loader shellcode
|
||||
# And check if it fits into the target code section
|
||||
main_shc = file_readall_binary(main_shc_file)
|
||||
main_shc = file_readall_binary(main_shc_path)
|
||||
l = len(main_shc)
|
||||
if l + 128 > project.exe_host.code_section.Misc_VirtualSize:
|
||||
logger.error("Error: Shellcode {}+128 too small for target code section {}".format(
|
||||
|
||||
+34
-76
@@ -1,98 +1,56 @@
|
||||
from jinja2 import Template
|
||||
import pprint
|
||||
import shutil
|
||||
import logging
|
||||
|
||||
from helper import *
|
||||
from observer import observer
|
||||
from model.defs import *
|
||||
from model.settings import Settings
|
||||
|
||||
use_templates = True
|
||||
logger = logging.getLogger("Assembler")
|
||||
|
||||
|
||||
# INPUT:
|
||||
# data/plugins/
|
||||
# data/source/
|
||||
#
|
||||
# Output:
|
||||
# build/main.c
|
||||
# build/*.h
|
||||
def create_c_from_template(
|
||||
source_style: SourceStyle,
|
||||
alloc_style: AllocStyle,
|
||||
exec_style: ExecStyle,
|
||||
decoder_style: DecoderStyle,
|
||||
payload_len: int,
|
||||
):
|
||||
plugin_allocator = ""
|
||||
plugin_decoder = ""
|
||||
plugin_executor = ""
|
||||
|
||||
def create_c_from_template(settings: Settings, payload_len: int):
|
||||
logger.info("--[ Create C from template")
|
||||
plugin_decoder = ""
|
||||
|
||||
#filepath = "data/plugins/allocator/{}.c".format(alloc_style.value)
|
||||
#with open(filepath, "r", encoding='utf-8') as file:
|
||||
# plugin_allocator = file.read()
|
||||
# plugin_allocator = Template(plugin_allocator).render({
|
||||
# 'PAYLOAD_LEN': payload_len,
|
||||
# })
|
||||
|
||||
filepath = PATH_DECODER + "{}.c".format(decoder_style.value)
|
||||
with open(filepath, "r", encoding='utf-8') as file:
|
||||
# Decoder
|
||||
filepath_decoder = PATH_DECODER + "{}.c".format(settings.decoder_style.value)
|
||||
with open(filepath_decoder, "r", encoding='utf-8') as file:
|
||||
plugin_decoder = file.read()
|
||||
plugin_decoder = Template(plugin_decoder).render({
|
||||
'PAYLOAD_LEN': payload_len,
|
||||
'XOR_KEY': config.xor_key,
|
||||
})
|
||||
|
||||
#filepath = "data/plugins/executor/{}.c".format(exec_style.value)
|
||||
#with open("data/plugins/executor/direct_1.c", "r", encoding='utf-8') as file:
|
||||
# plugin_executor = file.read()
|
||||
# plugin_executor = Template(plugin_executor).render({
|
||||
# 'PAYLOAD_LEN': payload_len,
|
||||
# })
|
||||
|
||||
if source_style == SourceStyle.peb_walk:
|
||||
if use_templates:
|
||||
with open(PATH_PEB_WALK + "template.c", 'r', encoding='utf-8') as file:
|
||||
template_content = file.read()
|
||||
observer.add_text_file("main_c_template", template_content)
|
||||
# C Template: peb_walk
|
||||
if settings.source_style == SourceStyle.peb_walk:
|
||||
with open(settings.template_path, 'r', encoding='utf-8') as file:
|
||||
template_content = file.read()
|
||||
observer.add_text_file("main_c_template", template_content)
|
||||
|
||||
template = Template(template_content)
|
||||
rendered_template = template.render({
|
||||
'plugin_allocator': plugin_allocator,
|
||||
'plugin_decoder': plugin_decoder,
|
||||
'plugin_executor': plugin_executor,
|
||||
'PAYLOAD_LEN': payload_len,
|
||||
})
|
||||
with open(main_c_file, "w", encoding='utf-8') as file:
|
||||
file.write(rendered_template)
|
||||
observer.add_text_file("main_c_rendered", rendered_template)
|
||||
template = Template(template_content)
|
||||
rendered_template = template.render({
|
||||
'plugin_decoder': plugin_decoder,
|
||||
'PAYLOAD_LEN': payload_len,
|
||||
})
|
||||
with open(settings.main_c_path, "w", encoding='utf-8') as file:
|
||||
file.write(rendered_template)
|
||||
observer.add_text_file("main_c_rendered", rendered_template)
|
||||
|
||||
# TODO PEB
|
||||
shutil.copy(PATH_PEB_WALK + "peb_lookup.h", f"{build_dir}/peb_lookup.h")
|
||||
else:
|
||||
observer.add_text_file("main_c", file_readall_text(PATH_PEB_WALK + "main.c"))
|
||||
shutil.copy(PATH_PEB_WALK + "main.c", main_c_file)
|
||||
# TODO PEB
|
||||
shutil.copy(PATH_PEB_WALK + "peb_lookup.h", f"{build_dir}/peb_lookup.h")
|
||||
# C Template: iat_reuse
|
||||
elif settings.source_style == SourceStyle.iat_reuse:
|
||||
with open(PATH_IAT_REUSE + "template.c", 'r', encoding='utf-8') as file:
|
||||
template_content = file.read()
|
||||
observer.add_text_file("main_c_template", template_content)
|
||||
template = Template(template_content)
|
||||
rendered_template = template.render({
|
||||
'plugin_decoder': plugin_decoder,
|
||||
'PAYLOAD_LEN': payload_len,
|
||||
})
|
||||
with open(settings.main_c_path, "w", encoding='utf-8') as file:
|
||||
file.write(rendered_template)
|
||||
observer.add_text_file("main_c_rendered", rendered_template)
|
||||
|
||||
elif source_style == SourceStyle.iat_reuse:
|
||||
if use_templates:
|
||||
with open(PATH_IAT_REUSE + "template.c", 'r', encoding='utf-8') as file:
|
||||
template_content = file.read()
|
||||
observer.add_text_file("main_c_template", template_content)
|
||||
template = Template(template_content)
|
||||
rendered_template = template.render({
|
||||
'plugin_allocator': plugin_allocator,
|
||||
'plugin_decoder': plugin_decoder,
|
||||
'plugin_executor': plugin_executor,
|
||||
'PAYLOAD_LEN': payload_len,
|
||||
})
|
||||
with open(main_c_file, "w", encoding='utf-8') as file:
|
||||
file.write(rendered_template)
|
||||
observer.add_text_file("main_c_rendered", rendered_template)
|
||||
else:
|
||||
observer.add_text_file("main_c", file_readall_text(PATH_IAT_REUSE + "main.c"))
|
||||
shutil.copy(PATH_IAT_REUSE + "main.c", main_c_file)
|
||||
else:
|
||||
raise Exception("Invalid source style: {}".format(settings.source_style))
|
||||
|
||||
Reference in New Issue
Block a user