Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bbot/core/helpers/asn.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def client(self):
from asndb import ASNDB

ssl_verify = self.parent_helper.web_config.get("ssl_verify", False)
self._client = ASNDB(verify=ssl_verify)
api_key = self.parent_helper.config.get("bbot_io_api_key", None)
self._client = ASNDB(bbot_io_api_key=api_key, verify=ssl_verify)
return self._client

def _normalize(self, response):
Expand Down
4 changes: 4 additions & 0 deletions bbot/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,7 @@ omit_event_types:
interactsh_server: null
interactsh_token: null
interactsh_disable: false

# API key for bbot.io services (currently used by ASN lookups via the asndb library)
# Can also be set via the BBOT_IO_API_KEY environment variable, which takes precedence.
bbot_io_api_key: null
24 changes: 24 additions & 0 deletions bbot/test/test_step_1/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,3 +1146,27 @@ def test_clean_dns_record():
assert clean_dns_record("'d1jwhzvlef5tfb.example.com'") == "d1jwhzvlef5tfb.example.com"
# quotes + trailing dot
assert clean_dns_record('"d1jwhzvlef5tfb.example.com."') == "d1jwhzvlef5tfb.example.com"


@pytest.mark.asyncio
async def test_asn_helper_passes_api_key(bbot_scanner, monkeypatch):
"""ASNHelper should forward the configured bbot_io_api_key to ASNDB."""
captured = {}

class FakeASNDB:
def __init__(self, bbot_io_api_key=None, verify=True):
captured["bbot_io_api_key"] = bbot_io_api_key
captured["verify"] = verify

import asndb

monkeypatch.setattr(asndb, "ASNDB", FakeASNDB)

scan = bbot_scanner("8.8.8.8", config={"bbot_io_api_key": "test-key-xyz"})
_ = scan.helpers.asn.client
assert captured["bbot_io_api_key"] == "test-key-xyz"

captured.clear()
scan2 = bbot_scanner("8.8.8.8")
_ = scan2.helpers.asn.client
assert captured["bbot_io_api_key"] is None
Loading