Skip to content

Commit

Permalink
ui: refining report pages
Browse files Browse the repository at this point in the history
  • Loading branch information
l4rzy committed Mar 15, 2024
1 parent abacad7 commit 1049dbc
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 26 deletions.
4 changes: 2 additions & 2 deletions lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_MAJOR = 0
VERSION_MINOR = 4
VERSION_PATCH = 2
VERSION_DATE = "2024 Mar 14"
VERSION_PATCH = 4
VERSION_DATE = "2024 Mar 15"
File renamed without changes
10 changes: 8 additions & 2 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ def process_tunnel_obj(target: TunnelObject) -> TunnelObject:
if "Key" in h and h != "Key: None":
return target
logger.warn("missing api key for abuseipdb, using default")
target.headers.remove("Key: None")
try:
target.headers.remove("Key: None")
except Exception:
pass
target.headers.append(f"Key: {ABUSEIPDB_KEY}")

elif target.service == "virustotal" or "virustotal.com" in target.url:
for h in target.headers:
if "x-apikey" in h and "x-apikey: None" != h:
return target
logger.warn("missing api key for virustotal, using default")
target.headers.remove("x-apikey: None")
try:
target.headers.remove("x-apikey: None")
except Exception:
pass
target.headers.append(f"x-apikey: {VIRUSTOTAL_KEY}")
else:
pass
Expand Down
39 changes: 36 additions & 3 deletions widgets/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
self.cbtn = None
self.wbtn = None
self.abtn = None
self.dbtn = None

if copy_btn:
icpy = Image.open(resource_path("lib/icons/copy.png"))
Expand Down Expand Up @@ -68,6 +69,17 @@ def __init__(
dark_image=ianalyze, light_image=ianalyze, size=(15, 15)
),
)
if direct_btn:
idirect = Image.open(resource_path("lib/icons/direct.png"))
self.dbtn = widget.CTkButton(
self,
text="",
width=30,
height=20,
image=widget.CTkImage(
dark_image=idirect, light_image=idirect, size=(15, 15)
),
)

self.label.grid(column=0, row=0, padx=2, pady=4)
self.content.grid(column=1, row=0, padx=2, pady=4)
Expand All @@ -79,6 +91,9 @@ def __init__(
self.wbtn.bind("<Button-1>", self.cb_on_web_btn_click)
if analyze_btn:
self.abtn.bind("<Button-1>", self.cb_on_analyze_btn_click)
if direct_btn:
self.directLink = ""
self.dbtn.bind("<Button-1>", self.cb_on_direct_btn_click)

def cb_on_copy_btn_click(self, event):
self.clipboard_clear()
Expand All @@ -98,18 +113,33 @@ def cb_on_analyze_btn_click(self, event):
source=DTSInputSource.GENERIC_REPORT, text=self.content.cget("text")
)

def set(self, label, content):
def cb_on_direct_btn_click(self, event):
import webbrowser

webbrowser.open_new_tab(self.directLink)

def set(self, label, content, directLink=""):
self.label.configure(text=f"{label}:")
self.content.configure(text=content)
if self.cbtn:
self.cbtn.grid(column=self.currentCol, row=0, padx=4, pady=4)
self.currentCol += 1
if label != "Error":
self.cbtn.grid(column=self.currentCol, row=0, padx=4, pady=4)
self.currentCol += 1
else:
self.cbtn.grid_remove()
if self.wbtn:
self.wbtn.grid(column=self.currentCol, row=0, padx=4, pady=4)
self.currentCol += 1
if self.abtn:
self.abtn.grid(column=self.currentCol, row=0, padx=4, pady=4)
self.currentCol += 1
if self.dbtn:
if directLink != "":
self.dbtn.grid(column=self.currentCol, row=0, padx=4, pady=4)
self.currentCol += 1
self.directLink = directLink
else:
self.dbtn.grid_remove()

def clear(self):
self.label.configure(text="")
Expand All @@ -120,6 +150,9 @@ def clear(self):
self.wbtn.grid_remove()
if self.abtn:
self.abtn.grid_remove()
if self.dbtn:
self.dbtn.grid_remove()
self.directLink = ""


class DTSButton(widget.CTkButton):
Expand Down
68 changes: 50 additions & 18 deletions widgets/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
NISTObject,
CirclCVEObject,
DTSInputSource,
ABUSE_CATEGORIES,
)
from widgets.common import DTSLabelWithBtn

Expand Down Expand Up @@ -68,9 +69,10 @@ def __init__(self, master, **kwargs):
self.title = widget.CTkLabel(
self, justify="center", font=widget.CTkFont(size=18, weight="bold")
)
self.label = widget.CTkLabel(
self, justify="center", font=widget.CTkFont(size=14)
self.label = DTSLabelWithBtn(
self, web_btn=False, copy_btn=True, analyze_btn=False, direct_btn=True
)

self.result = widget.CTkLabel(self, justify="center")
self.rateMeter = Meter(
self,
Expand Down Expand Up @@ -101,7 +103,7 @@ def __init__(self, master, **kwargs):
def render_exception(self, message):
self.rateMeter.set(0)
self.result.configure(text=message)
self.label.configure(text="---")
self.label.set("Error", "Unknown")
self.knownNames.grid_remove()
self.magicInfo.grid_remove()
self.signature.grid_remove()
Expand All @@ -125,7 +127,11 @@ def populate(self, data: VirusTotalObject | None):
try:
firstResult = data.data[0].attributes
firstResultType = data.data[0].type
self.label.configure(text=f"for {data.data[0].type}: {data.data[0].id}")
self.label.set(
"for",
f"({data.data[0].type}) {data.data[0].id}",
f"https://www.virustotal.com/gui/{firstResultType}/{data.data[0].id}",
)
assert isinstance(firstResult, VTAttributes)
except IndexError:
self.render_exception("Resource not found on VirusTotal!")
Expand Down Expand Up @@ -195,8 +201,8 @@ def __init__(self, master, **kwargs):
self.title = widget.CTkLabel(
self, justify="center", font=widget.CTkFont(size=18, weight="bold")
)
self.label = widget.CTkLabel(
self, justify="center", font=widget.CTkFont(size=14)
self.label = DTSLabelWithBtn(
self, web_btn=False, copy_btn=True, analyze_btn=False, direct_btn=True
)
self.result = widget.CTkLabel(self, justify="center")
self.rateMeter = Meter(
Expand All @@ -223,9 +229,11 @@ def __init__(self, master, **kwargs):

self.isp = DTSLabelWithBtn(self)
self.usageType = DTSLabelWithBtn(self)
self.country = DTSLabelWithBtn(self)
self.domain = DTSLabelWithBtn(self, web_btn=True)
# self.hostnames = CTkTable(self, column=2)
self.country = DTSLabelWithBtn(self)
self.reportCategories = widget.CTkTextbox(
self, font=widget.CTkFont(family="Consolas", size=14)
)

def render_exception(self, message):
self.title.grid(row=0, column=0, padx=4, pady=4)
Expand All @@ -234,17 +242,23 @@ def render_exception(self, message):
self.result.grid(row=3, column=0, padx=4, pady=2)

self.title.configure(text="AbuseIPDB Report")
self.label.configure(text="---")
self.label.configure("Error", "Unknown")
self.result.configure(text=message)
self.error = True

def clear(self):
self.reportCategories.delete("0.0", "end")

def populate(self, data: AbuseObject | None):
if data is None:
self.render_exception(
"A network error happened! Check your internet settings."
)
self.error = True
return

self.clear()

self.title.grid(row=0, column=0, padx=4, pady=4)
self.label.grid(row=1, column=0, padx=4, pady=2)
self.rateMeter.grid(row=2, column=0, padx=10, pady=20)
Expand All @@ -253,9 +267,16 @@ def populate(self, data: AbuseObject | None):
self.usageType.grid(row=5, column=0)
self.domain.grid(row=6, column=0)
self.country.grid(row=7, column=0)
self.reportCategories.grid(
row=8, column=0, padx=6, pady=10, columnspan=1, rowspan=1, sticky="NSEW"
)

self.title.configure(text="AbuseIPDB Report")
self.label.configure(text=f"for {data.data.ipAddress}")
self.label.set(
"for",
data.data.ipAddress,
f"https://www.abuseipdb.com/check/{data.data.ipAddress}",
)
if not data.data.isPublic:
self.result.configure(text="This IP is a private IP")
self.rateMeter.set(data.data.abuseConfidenceScore)
Expand All @@ -276,14 +297,24 @@ def populate(self, data: AbuseObject | None):
if data.data.countryCode != "null":
country = countries.get(data.data.countryCode)
self.country.set("Country", f"{country.name}")
else:
self.country.set("Country", "Unknown")

if data.data.abuseConfidenceScore != 0 and data.data.reports is not None:
categories = []
for r in data.data.reports:
categories += r.categories

c = Counter(categories)
print(c)
reportedCats = sorted(
Counter(categories).items(), key=lambda x: x[1], reverse=True
)

textbuf = "Reported reason:\n"
for catnum, times in reportedCats:
textbuf += f"- {ABUSE_CATEGORIES[catnum]}: {times} {'times' if times > 1 else 'time'}\n"
self.reportCategories.insert("0.0", textbuf)
else:
self.reportCategories.insert("0.0", "---")
self.error = False


Expand Down Expand Up @@ -407,8 +438,8 @@ def __init__(self, master, **kwargs):
self.title = widget.CTkLabel(
self, justify="center", font=widget.CTkFont(size=18, weight="bold")
)
self.label = widget.CTkLabel(
self, justify="center", font=widget.CTkFont(size=14)
self.label = DTSLabelWithBtn(
self, web_btn=False, copy_btn=True, analyze_btn=False, direct_btn=True
)
self.result = widget.CTkLabel(self, justify="center")
self.rateMeter = Meter(
Expand Down Expand Up @@ -443,7 +474,7 @@ def clear(self):

def render_exception(self, message="---"):
self.rateMeter.set(0)
self.label.configure(text="An error happened")
self.label.set("Error", "Unknown")
self.result.configure(text=message)
self.desc.grid_remove()
self.metrics.grid_remove()
Expand Down Expand Up @@ -475,7 +506,8 @@ def populate(self, data: CirclCVEObject | None):
return

try:
self.label.configure(text=f"for {data.id}")
# self.label.configure(text=f"for {data.id}")
self.label.set("for", data.id, f"https://cve.circl.lu/cve/{data.id}")
self.result.configure(text=f"Published on {data.Published}")
desc = data.summary
if len(desc) > 450:
Expand Down Expand Up @@ -521,15 +553,15 @@ def __init__(self, master, **kwargs):
self.btnFrame = widget.CTkFrame(self)
self.btnFrame.grid_rowconfigure(0, weight=1)

i = Image.open(resource_path("lib/copy.png"))
i = Image.open(resource_path("lib/icons/copy.png"))
self.copyBtn = widget.CTkButton(
self.btnFrame,
text="Copy",
width=30,
height=20,
image=widget.CTkImage(dark_image=i, light_image=i, size=(15, 15)),
)
ia = Image.open(resource_path("lib/analyze.png"))
ia = Image.open(resource_path("lib/icons/analyze.png"))
self.analyzeBtn = widget.CTkButton(
self.btnFrame,
text="Analyze",
Expand Down
2 changes: 1 addition & 1 deletion widgets/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, **kwargs):
family="Roboto", name="DTSContentFont", size=11, weight="normal"
)
if sys.platform == "win32":
self.iconbitmap(resource_path("lib/icon.ico"))
self.iconbitmap(resource_path("lib/icons/icon.ico"))
self.title("Toolbox")
self.welcomeTexts = [
"How are you doing today?",
Expand Down

0 comments on commit 1049dbc

Please sign in to comment.