The recursive internet scanner for hackers. 🧡
Python asmattack-surface-managementautomationbugbountyclieasmhackingneo4josintosint-frameworkpentestingpythonreconrecursionscannersubdomain-enumerationsubdomain-scannersubdomainsthreat-intelligencethreatintel
Keep inherited port on ClosestHostEvent and restore port from JSON (#3462)
Paul Mueller5cccd2cd7b75
diff --git a/bbot/core/event/base.py b/bbot/core/event/base.pyindex efcf12c68..f3e3f2b13 100644--- a/bbot/core/event/base.py+++ b/bbot/core/event/base.py@@ -1208,7 +1208,7 @@ class DictHostEvent(DictEvent):class ClosestHostEvent(DictHostEvent):- # if a host/path/url isn't specified, this event type grabs it from the closest parent+ # if a host isn't specified, this event type grabs host, port, url and path from the closest parent# inherited by FINDINGdef __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)@@ -1227,9 +1227,9 @@ class ClosestHostEvent(DictHostEvent):# inherit closest host+portif parent.host:self.data["host"] = str(parent.host)- self._port = parent.port- # we do this to refresh the hash+ # we do this to refresh the hash (this also clears _port, so it must come first)self.data = self.data+ self._port = parent.portbreak# die if we still haven't found a hostif not self.host and not self.data.get("path", ""):@@ -2509,6 +2509,11 @@ def event_from_json(j):resolved_hosts = j.get("resolved_hosts", [])event._resolved_hosts = frozenset(resolved_hosts) if resolved_hosts else None+ # some events (e.g. FINDING) carry a port that isn't derivable from their data+ port = j.get("port", None)+ if port is not None:+ event._port = port+http_title = j.get("http_title", "")if http_title:try:diff --git a/bbot/test/test_step_1/test_events.py b/bbot/test/test_step_1/test_events.pyindex b43bc8b2f..a33117218 100644--- a/bbot/test/test_step_1/test_events.py+++ b/bbot/test/test_step_1/test_events.py@@ -1175,6 +1175,31 @@ async def test_event_closest_host():assert vuln.data["path"] == "/tmp/asdf.txt"assert vuln.host == "www.evilcorp.com"+ # finding inherits the port from its parent, and keeps it across a json round trip+ from bbot.core.event import event_from_json++ open_port = scan.make_event("8.8.8.8:53", "OPEN_TCP_PORT", parent=scan.root_event)+ port_finding = scan.make_event(+ {"description": "test", "severity": "LOW", "confidence": "MEDIUM", "name": "Test Finding"},+ "FINDING",+ parent=open_port,+ )+ assert port_finding.host == ipaddress.ip_address("8.8.8.8")+ assert port_finding.port == 53+ assert port_finding.json()["port"] == 53+ reconstituted_finding = event_from_json(port_finding.json())+ assert reconstituted_finding.port == 53+ assert reconstituted_finding.id == port_finding.id+ # a finding with its own host doesn't inherit anything+ own_host_finding = scan.make_event(+ {"host": "1.2.3.4", "description": "test", "severity": "LOW", "confidence": "MEDIUM", "name": "Test Finding"},+ "FINDING",+ parent=open_port,+ )+ assert own_host_finding.port is None+ assert "port" not in own_host_finding.json()+ assert event_from_json(own_host_finding.json()).port is None+# no host and no path == not allowedevent3 = scan.make_event("wat", "ASDF", parent=scan.root_event)assert not event3.host