ui: better website

This commit is contained in:
Dobin
2024-02-17 13:34:39 +00:00
parent c215ae62f3
commit b4ec9031cb
6 changed files with 130 additions and 50 deletions
+3 -3
View File
@@ -10,7 +10,7 @@
<div class="container-fluid">
<div class="row">
<div class="col-md-2">
<div class="col-md-3">
<ul class="nav nav-tabs flex-column" id="myTab" role="tablist">
{% for log_file in log_files %}
<li class="nav-item" role="presentation">
@@ -29,7 +29,7 @@
</ul>
</div>
<div class="col-md-10">
<div class="col-md-9">
<div class="tab-content" id="myTabContent">
{% for log_file in log_files %}
<div
@@ -38,7 +38,7 @@
role="tabpanel"
aria-labelledby="project-{{log_file['id']}}-tab"
>
{{log_file['content']|safe}}
<div style="white-space: pre-wrap; font-family: 'Consolas', monospace;">{{log_file['content']|safe}}</div>
</div>
{% endfor %}
</div>
+49 -34
View File
@@ -6,12 +6,16 @@ import io
from typing import List, Tuple
from datetime import date
from pygments import highlight
from pygments.lexers import CLexer, NasmLexer, DiffLexer
from pygments.lexers import CLexer, NasmLexer, DiffLexer, HexdumpLexer
from pygments.formatters import HtmlFormatter
import difflib
from ansi2html import Ansi2HTMLConverter
views = Blueprint('views', __name__)
conv = Ansi2HTMLConverter()
@views.route("/")
def index():
@@ -27,49 +31,60 @@ def project():
asm_a = "" # for diff
asm_b = ""
for file in os.listdir("logs"):
if file.endswith(".txt"):
print("Handle: ", file)
print("Handle: ", file)
with open(os.path.join("logs", file), "r") as f:
data = f.read()
with open(os.path.join("logs", file), "r") as f:
data = f.read()
if 'main_c' in file:
data = highlight(data, CLexer(), HtmlFormatter(full=False))
elif '_asm' in file:
# handle special cases
if '_orig' in file:
asm_a = data
if '_cleanup' in file:
asm_b = data
if 'main_c' in file:
data = highlight(data, CLexer(), HtmlFormatter(full=False))
elif 'payload_asm' in file:
# handle special cases
if '_orig' in file:
asm_a = data
if '_cleanup' in file:
asm_b = data
data = highlight(data, NasmLexer(), HtmlFormatter(full=False))
elif 'shc_from_asm' in file:
if '.txt' in file:
# skip it
continue
if '.ascii' in file:
#data = data.replace(" ", "&nbsp;")
data = conv.convert(data, full=False)
#data = data.replace("\n", "<br>")
if '.hex' in file:
#data = highlight(data, HexdumpLexer(), HtmlFormatter(full=False))
#data = data.replace("\n", "<br>")
#data = data.replace(" ", "&nbsp;")
data = data
data = highlight(data, NasmLexer(), HtmlFormatter(full=False))
entry = {
"name": file,
"id": str(id),
"content": data,
}
log_files.append(entry)
id += 1
# more
if asm_a != "" and asm_b != "":
# do the diff from the content of the two files
a = asm_a.splitlines()
b = asm_b.splitlines()
diff_generator = difflib.unified_diff(a, b, lineterm='')
diff_string = '\n'.join(diff_generator)
diff_l = highlight(diff_string, DiffLexer(), HtmlFormatter(full=False))
entry = {
"name": file,
"name": "_asm_diff".format(),
"id": str(id),
"content": data,
"content": diff_l,
}
log_files.append(entry)
id += 1
# more
if asm_a != "" and asm_b != "":
# do the diff from the content of the two files
a = asm_a.splitlines()
b = asm_b.splitlines()
diff_generator = difflib.unified_diff(a, b, lineterm='')
diff_string = '\n'.join(diff_generator)
diff_l = highlight(diff_string, DiffLexer(), HtmlFormatter(full=False))
entry = {
"name": "_asm_diff".format(),
"id": str(id),
"content": diff_l,
}
log_files.append(entry)
id += 1
asm_a = ""
asm_b = ""
asm_a = ""
asm_b = ""
return render_template('project.html',
+30 -1
View File
@@ -100,4 +100,33 @@ def rbrunmode_str(rbrunmode):
elif rbrunmode == "3":
return "setup TLS callback"
else:
return "Invalid"
return "Invalid"
def hexdump(data, addr = 0, num = 0):
s = ''
n = 0
lines = []
if num == 0: num = len(data)
if len(data) == 0:
return '<empty>'
for i in range(0, num, 16):
line = ''
line += '%04x | ' % (addr + i)
n += 16
for j in range(n-16, n):
if j >= len(data): break
line += '%02x ' % (data[j] & 0xff)
line += ' ' * (3 * 16 + 7 - len(line)) + ' | '
for j in range(n-16, n):
if j >= len(data): break
c = data[j] if not (data[j] < 0x20 or data[j] > 0x7e) else '.'
line += '%c' % c
lines.append(line)
return '\n'.join(lines)
+11 -11
View File
@@ -3,6 +3,7 @@ import pprint
from capstone import Cs, CS_ARCH_X86, CS_MODE_64
from model import *
from r2helper import r2_disas
class Observer():
@@ -11,24 +12,23 @@ class Observer():
self.idx = 0
def add_text(self, name, data):
self.write_to_file(name, data)
self.write_to_file(name + ".txt", data)
self.idx += 1
def add_code(self, name, data):
md = Cs(CS_ARCH_X86, CS_MODE_64)
# Disassemble the shellcode
ret = ""
for i in md.disasm(data, 0x0):
ret += "0x%x:\t%s\t%s\n" % (i.address, i.mnemonic, i.op_str)
self.write_to_file(name, ret)
def add_code(self, name, data: bytes):
ret = r2_disas(data)
self.write_to_file(name + ".disas.txt", ret['text'])
self.write_to_file(name + ".disas.ascii", ret['color'])
self.write_to_file(name + ".hex", ret['hexdump'])
self.idx += 1
def add_json(self, name, data):
self.write_to_file(name, pprint.pformat(data, indent=4))
self.idx += 1
def write_to_file(self, filename, data):
with open("logs/{}-{}.txt".format(self.idx, filename), "w") as f:
with open("logs/{}-{}".format(self.idx, filename), "w") as f:
f.write(data)
self.idx += 1
def __str__(self):
s = "<todo>"
+35
View File
@@ -0,0 +1,35 @@
import r2pipe
import os
from defs import *
from helper import hexdump
def r2_disas(data: bytes):
filename = "r2_data.bin"
ret = {
'text': None,
'color': None,
'hexdump': None,
}
ret["hexdump"] = hexdump(data)
# fucking r2 cant handle shellcode when not in files...
with open(filename, "wb") as f:
f.write(data)
r2 = r2pipe.open(filename)
r2.cmd('aaa')
r2.cmd('e scr.color=0')
ret['text'] = r2.cmd('pd')
ret['text'] = '\n'.join(ret['text'].splitlines()) # fix newlines
r2.cmd('e scr.color=2')
ret['color'] = r2.cmd('pd')
ret['color'] = '\n'.join(ret['color'].splitlines()) # fix newlines
r2.quit()
os.remove(filename)
return ret
+2 -1
View File
@@ -3,4 +3,5 @@ pefile
capstone
keystone-engine
jinja2
Pygments
Pygments
ansi2html