Skip to content

Commit

Permalink
fixed resolved_hosts with reserialized events
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechromancer committed Nov 3, 2023
1 parent 892beee commit 46ebd57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions bbot/core/event/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,10 @@ def event_from_json(j):
"dummy": True,
}
event = make_event(**kwargs)

resolved_hosts = j.get("resolved_hosts", [])
event._resolved_hosts = set(resolved_hosts)

event.timestamp = datetime.fromtimestamp(j["timestamp"])
event.scope_distance = j["scope_distance"]
source_id = j.get("source", None)
Expand Down
12 changes: 7 additions & 5 deletions bbot/test/test_step_1/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,21 @@ async def test_events(events, scan, helpers, bbot_config):
# test event serialization
from bbot.core.event import event_from_json

db_event = scan.make_event("127.0.0.1", dummy=True)
db_event = scan.make_event("evilcorp.com", dummy=True)
db_event._resolved_hosts = {"127.0.0.1"}
db_event.scope_distance = 1
timestamp = db_event.timestamp.timestamp()
json_event = db_event.json()
assert json_event["scope_distance"] == 1
assert json_event["data"] == "127.0.0.1"
assert json_event["type"] == "IP_ADDRESS"
assert json_event["data"] == "evilcorp.com"
assert json_event["type"] == "DNS_NAME"
assert json_event["timestamp"] == timestamp
reconstituted_event = event_from_json(json_event)
assert reconstituted_event.scope_distance == 1
assert reconstituted_event.timestamp.timestamp() == timestamp
assert reconstituted_event.data == "127.0.0.1"
assert reconstituted_event.type == "IP_ADDRESS"
assert reconstituted_event.data == "evilcorp.com"
assert reconstituted_event.type == "DNS_NAME"
assert "127.0.0.1" in reconstituted_event.resolved_hosts

http_response = scan.make_event(httpx_response, "HTTP_RESPONSE", source=scan.root_event)
assert http_response.source_id == scan.root_event.id
Expand Down

0 comments on commit 46ebd57

Please sign in to comment.