diff --git a/src/core/events/types/common.py b/src/core/events/types/common.py index ffe60a4..2ec8acf 100644 --- a/src/core/events/types/common.py +++ b/src/core/events/types/common.py @@ -16,6 +16,17 @@ class Event(object): if name in event.__dict__: return event.__dict__[name] + # Event's logical location to be used mainly for reports. + # If event don't implement it check previous event + # This is because events are composed (previous -> previous ...) + # and not inheritted + def location(self): + location = None + if self.previous: + location = self.previous.location() + + return location + # returns the event history ordered from newest to oldest @property def history(self): @@ -85,7 +96,10 @@ class NewHostEvent(Event): def __str__(self): return str(self.host) - + + # Event's logical location to be used mainly for reports. + def location(self): + return str(self.host) class OpenPortEvent(Event): def __init__(self, port): @@ -93,7 +107,14 @@ class OpenPortEvent(Event): def __str__(self): return str(self.port) - + + # Event's logical location to be used mainly for reports. + def location(self): + if self.host: + location = str(self.host) + ":" + str(self.port) + else: + location = str(self.port) + return location class HuntFinished(Event): pass diff --git a/src/modules/discovery/hosts.py b/src/modules/discovery/hosts.py index b942ce3..afce667 100644 --- a/src/modules/discovery/hosts.py +++ b/src/modules/discovery/hosts.py @@ -22,6 +22,14 @@ class RunningAsPodEvent(Event): self.auth_token = self.get_auth_token() self.client_cert = self.get_client_cert() + # Event's logical location to be used mainly for reports. + def location(self): + location = "Local to Pod" + if 'HOSTNAME' in os.environ: + location += "(" + os.environ['HOSTNAME'] + ")" + + return location + def get_auth_token(self): try: with open("/var/run/secrets/kubernetes.io/serviceaccount/token") as token_file: diff --git a/src/modules/report/base.py b/src/modules/report/base.py index 36dda55..786cf26 100644 --- a/src/modules/report/base.py +++ b/src/modules/report/base.py @@ -24,7 +24,7 @@ class BaseReporter(object): def get_vulnerabilities(self): vulnerabilities_lock.acquire() - vulnerabilities_data = [{"location": "{}:{}".format(vuln.host, vuln.port) if vuln.host else "", + vulnerabilities_data = [{"location": vuln.location(), "category": vuln.category.name, "vulnerability": vuln.get_name(), "description": vuln.explain(), diff --git a/src/modules/report/plain.py b/src/modules/report/plain.py index 282035a..70b88eb 100644 --- a/src/modules/report/plain.py +++ b/src/modules/report/plain.py @@ -82,7 +82,7 @@ class PlainReporter(object): vulnerabilities_lock.acquire() for vuln in vulnerabilities: - row = ["{}:{}".format(vuln.host, vuln.port) if vuln.host else "", vuln.category.name, vuln.get_name(), vuln.explain()] + row = [vuln.location(), vuln.category.name, vuln.get_name(), vuln.explain()] evidence = str(vuln.evidence)[:EVIDENCE_PREVIEW] + "..." if len(str(vuln.evidence)) > EVIDENCE_PREVIEW else str(vuln.evidence) row.append(evidence) vuln_table.add_row(row)