refactor: better logs/ output to parse

This commit is contained in:
Dobin
2024-02-17 14:19:32 +00:00
parent b4ec9031cb
commit c63e16ffab
6 changed files with 23 additions and 16 deletions
+2 -1
View File
@@ -38,7 +38,8 @@
role="tabpanel" role="tabpanel"
aria-labelledby="project-{{log_file['id']}}-tab" aria-labelledby="project-{{log_file['id']}}-tab"
> >
<div style="white-space: pre-wrap; font-family: 'Consolas', monospace;">{{log_file['content']|safe}}</div> <div style="white-space: pre-wrap; font-family: 'Consolas', monospace;">{{log_file['content']|safe}}
</div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
+10 -5
View File
@@ -24,13 +24,14 @@ def index():
@views.route("/project") @views.route("/project")
def project(): def project():
# read the content of all files in logs
log_files = [] log_files = []
id = 0 id = 0
asm_a = "" # for diff asm_a = "" # for diff
asm_b = "" asm_b = ""
for file in os.listdir("logs"): for file in os.listdir("logs"):
if file.startswith("."):
continue
print("Handle: ", file) print("Handle: ", file)
with open(os.path.join("logs", file), "r") as f: with open(os.path.join("logs", file), "r") as f:
@@ -38,7 +39,7 @@ def project():
if 'main_c' in file: if 'main_c' in file:
data = highlight(data, CLexer(), HtmlFormatter(full=False)) data = highlight(data, CLexer(), HtmlFormatter(full=False))
elif 'payload_asm' in file: elif '_asm_' in file:
# handle special cases # handle special cases
if '_orig' in file: if '_orig' in file:
asm_a = data asm_a = data
@@ -46,7 +47,7 @@ def project():
asm_b = data asm_b = data
data = highlight(data, NasmLexer(), HtmlFormatter(full=False)) data = highlight(data, NasmLexer(), HtmlFormatter(full=False))
elif 'shc_from_asm' in file: elif '_shc' in file:
if '.txt' in file: if '.txt' in file:
# skip it # skip it
continue continue
@@ -58,7 +59,11 @@ def project():
#data = highlight(data, HexdumpLexer(), HtmlFormatter(full=False)) #data = highlight(data, HexdumpLexer(), HtmlFormatter(full=False))
#data = data.replace("\n", "<br>") #data = data.replace("\n", "<br>")
#data = data.replace(" ", "&nbsp;") #data = data.replace(" ", "&nbsp;")
data = data data = data.replace("<", "&lt;")
data = data.replace(">", "&gt;")
elif '.log' in file:
data = data.replace("<", "&lt;")
data = data.replace(">", "&gt;")
entry = { entry = {
"name": file, "name": file,
@@ -77,7 +82,7 @@ def project():
diff_string = '\n'.join(diff_generator) diff_string = '\n'.join(diff_generator)
diff_l = highlight(diff_string, DiffLexer(), HtmlFormatter(full=False)) diff_l = highlight(diff_string, DiffLexer(), HtmlFormatter(full=False))
entry = { entry = {
"name": "_asm_diff".format(), "name": "Summary: ASM Diff".format(),
"id": str(id), "id": str(id),
"content": diff_l, "content": diff_l,
} }
+2 -2
View File
@@ -39,9 +39,9 @@ def run_process_checkret(args, check=True):
ret = subprocess.run(args, ret = subprocess.run(args,
capture_output=True) capture_output=True)
with open("logs/log.txt", "ab") as f: with open("logs/cmdoutput.log", "ab") as f:
cmd = "------------------------------------\n" cmd = "------------------------------------\n"
cmd += "--- " + " ".join(args) cmd += "--- " + " ".join(args) + "\n"
f.write(cmd.encode('utf-8')) f.write(cmd.encode('utf-8'))
if ret.stdout != None: if ret.stdout != None:
f.write(ret.stdout) f.write(ret.stdout)
+2 -2
View File
@@ -22,7 +22,7 @@ def asm_to_shellcode(asm_in: FilePath, build_exe: FilePath, shellcode_out: FileP
if not os.path.isfile(build_exe): if not os.path.isfile(build_exe):
raise Exception("Compiling failed") raise Exception("Compiling failed")
code = extract_code_from_exe(build_exe) code = extract_code_from_exe(build_exe)
observer.add_code("generate_shc_from_asm", code) observer.add_code("carrier_shc", code)
with open(shellcode_out, 'wb') as f: with open(shellcode_out, 'wb') as f:
f.write(code) f.write(code)
@@ -54,4 +54,4 @@ def merge_loader_payload(
# append them # append them
data = data_stager + payload_data data = data_stager + payload_data
output.write(data) output.write(data)
observer.add_code("final_shellcode", data) observer.add_code("loader_shc", data)
+3 -3
View File
@@ -31,13 +31,13 @@ def compile(
]) ])
if not os.path.isfile(asm_out): if not os.path.isfile(asm_out):
raise Exception("Error: Compiling failed") raise Exception("Error: Compiling failed")
observer.add_text("payload_asm_orig", file_readall_text(asm_out)) observer.add_text("carrier_asm_orig", file_readall_text(asm_out))
# Assembly text fixup (SuperMega) # Assembly text fixup (SuperMega)
logger.info("---[ Fixup : {} ".format(asm_out)) logger.info("---[ Fixup : {} ".format(asm_out))
if not fixup_asm_file(asm_out, payload_len): if not fixup_asm_file(asm_out, payload_len):
raise Exception("Error: Fixup failed") raise Exception("Error: Fixup failed")
observer.add_text("payload_asm_fixup", file_readall_text(asm_out)) observer.add_text("carrier_asm_fixup", file_readall_text(asm_out))
# Assembly cleanup (masm_shc) # Assembly cleanup (masm_shc)
asm_clean_file = asm_out + ".clean" asm_clean_file = asm_out + ".clean"
@@ -52,7 +52,7 @@ def compile(
# Move to destination we expect # Move to destination we expect
shutil.move(asm_clean_file, asm_out) shutil.move(asm_clean_file, asm_out)
observer.add_text("payload_asm_cleanup", file_readall_text(asm_out)) observer.add_text("carrier_asm_cleanup", file_readall_text(asm_out))
def bytes_to_asm_db(byte_data: bytes) -> bytes: def bytes_to_asm_db(byte_data: bytes) -> bytes:
+4 -3
View File
@@ -14,19 +14,20 @@ def r2_disas(data: bytes):
ret["hexdump"] = hexdump(data) ret["hexdump"] = hexdump(data)
# fucking r2 cant handle shellcode when not in files... # r2 cant really handle shellcode when not in files...
with open(filename, "wb") as f: with open(filename, "wb") as f:
f.write(data) f.write(data)
code_len = len(data)
r2 = r2pipe.open(filename) r2 = r2pipe.open(filename)
r2.cmd('aaa') r2.cmd('aaa')
r2.cmd('e scr.color=0') r2.cmd('e scr.color=0')
ret['text'] = r2.cmd('pd') ret['text'] = r2.cmd('pD {}'.format(code_len))
ret['text'] = '\n'.join(ret['text'].splitlines()) # fix newlines ret['text'] = '\n'.join(ret['text'].splitlines()) # fix newlines
r2.cmd('e scr.color=2') r2.cmd('e scr.color=2')
ret['color'] = r2.cmd('pd') ret['color'] = r2.cmd('pD {}'.format(code_len))
ret['color'] = '\n'.join(ret['color'].splitlines()) # fix newlines ret['color'] = '\n'.join(ret['color'].splitlines()) # fix newlines
r2.quit() r2.quit()