Skip to content

armgit / bbot

Public Imported from GitHub
0

The recursive internet scanner for hackers. 🧡

Add favicon module for technology detection (#3532)

Paul Mueller9598f7d223ab
diff --git a/bbot/modules/favicon.py b/bbot/modules/favicon.py
new file mode 100644
index 000000000..095eb0dea
--- /dev/null
+++ b/bbot/modules/favicon.py
@@ -0,0 +1,108 @@
+import re
+import base64
+import mmh3
+import yaml
+from urllib.parse import urljoin
+
+from bbot.modules.base import BaseModule
+from bbot.core.config.models import BaseModuleConfig, Field
+
+
+class favicon(BaseModule):
+ watched_events = ["HTTP_RESPONSE"]
+ produced_events = ["TECHNOLOGY"]
+ flags = ["safe", "active", "web-heavy"]
+ meta = {
+ "description": "Identify web technologies by the mmh3 hash of their favicon",
+ "created_date": "2026-10-16",
+ "author": "@liquidsec",
+ }
+
+ class Config(BaseModuleConfig):
+ signatures_url: str = Field(
+ "https://raw.githubusercontent.com/projectdiscovery/nuclei-templates/main/http/technologies/favicon-detect.yaml",
+ description="URL of the nuclei favicon-detect template to load favicon signatures from",
+ )
+
+ _module_threads = 4
+
+ link_tag_regex = re.compile(r"<link\b[^>]*>", re.I)
+ link_rel_regex = re.compile(r"""\brel\s*=\s*["']?([^"'>]+)""", re.I)
+ link_href_regex = re.compile(r"""\bhref\s*=\s*["']?([^"'\s>]+)""", re.I)
+ signature_regex = re.compile(r'"(-?\d+)"\s*==\s*mmh3\(base64_py\(body\)\)')
+ # some signature names end in a redundant "favicon" (e.g. "asp.net-favicon")
+ name_favicon_suffix_regex = re.compile(r"[-_ ]+(?:default[-_ ]+)?favicon$", re.I)
+
+ async def setup(self):
+ signatures_url = self.config.get("signatures_url")
+ signatures_file = await self.helpers.download(signatures_url, cache_hrs=24)
+ if not signatures_file:
+ return None, f"Failed to download favicon signatures from {signatures_url}"
+ self.signatures = self.parse_signatures(yaml.safe_load(signatures_file.read_text()))
+ if not self.signatures:
+ return None, f"No favicon signatures could be parsed from {signatures_url}"
+ self.verbose(f"Loaded {len(self.signatures):,} favicon signatures")
+ return True
+
+ def parse_signatures(self, template):
+ signatures = {}
+ for request in template.get("http", []):
+ for matcher in request.get("matchers", []):
+ name = self.name_favicon_suffix_regex.sub("", matcher.get("name", ""))
+ hashes = [int(h) for dsl in matcher.get("dsl", []) for h in self.signature_regex.findall(dsl)]
+ if not hashes:
+ self.warning(f"Skipping favicon signature with unrecognized format: {name}")
+ continue
+ for h in hashes:
+ signatures.setdefault(h, set()).add(name)
+ return signatures
+
+ def icon_urls(self, event):
+ """
+ Icons declared by the page via <link rel="icon">, followed by the default /favicon.ico.
+
+ If the page declares none and lives in a subdirectory, the subdirectory's favicon.ico is tried
+ first, since it may belong to a different app mounted there.
+ """
+ page_url = event.data["url"]
+ urls = []
+ for tag in self.link_tag_regex.findall(event.body or ""):
+ rel = self.link_rel_regex.search(tag)
+ href = self.link_href_regex.search(tag)
+ if rel and href and "icon" in rel.group(1).lower().split():
+ url = urljoin(page_url, href.group(1))
+ if url.startswith(("http://", "https://")):
+ urls.append(url)
+ if not urls:
+ path_segments = event.parsed_url.path.split("/")
+ if len(path_segments) > 2:
+ urls.append(urljoin(page_url, f"/{path_segments[1]}/favicon.ico"))
+ urls.append(urljoin(page_url, "/favicon.ico"))
+ return list(dict.fromkeys(urls))
+
+ def _incoming_dedup_hash(self, event):
+ return hash(tuple(self.icon_urls(event))), "already checked these favicons"
+
+ def _outgoing_dedup_hash(self, event):
+ # the same favicon across ports, schemes, or subdirectories is the same app
+ return hash((event.host, event.data["technology"]))
+
+ async def handle_event(self, event):
+ for icon_url in self.icon_urls(event):
+ r = await self.helpers.request(icon_url, follow_redirects=True)
+ if r is None or r.status_code != 200 or not r.content:
+ continue
+ if "html" in r.headers.get("content-type", "").lower():
+ continue
+ favicon_hash = mmh3.hash(base64.encodebytes(r.content))
+ names = self.signatures.get(favicon_hash)
+ if not names:
+ continue
+ for technology in sorted(names):
+ await self.emit_event(
+ {"host": str(event.host), "url": event.data["url"], "technology": technology},
+ "TECHNOLOGY",
+ parent=event,
+ context=f"{{module}} matched favicon hash {favicon_hash} at {r.url} to {{event.type}}: {technology}",
+ )
+ return
diff --git a/bbot/presets/tech-detect.yml b/bbot/presets/tech-detect.yml
index aebd2781a..96b88569e 100644
--- a/bbot/presets/tech-detect.yml
+++ b/bbot/presets/tech-detect.yml
@@ -1,8 +1,9 @@
-description: Detect technologies via Nuclei, and FingerprintX
+description: Detect technologies via Nuclei, FingerprintX, and favicon hashes
modules:
- nuclei
- fingerprintx
+ - favicon
config:
modules:
diff --git a/bbot/test/test_step_2/module_tests/test_module_favicon.py b/bbot/test/test_step_2/module_tests/test_module_favicon.py
new file mode 100644
index 000000000..2917d6673
--- /dev/null
+++ b/bbot/test/test_step_2/module_tests/test_module_favicon.py
@@ -0,0 +1,140 @@
+import re
+import yaml
+
+from .base import ModuleTestBase
+from bbot.test.worker import HTTPSERVER_SSL_URL, HTTPSERVER_URL
+
+# icons are longer than 57 bytes so the newlines inserted by base64.encodebytes affect the hash
+LINKED_ICON = b"\x00\x00\x01\x00\x01\x00" + bytes(range(256)) * 2
+DEFAULT_ICON = b"\x00\x00\x01\x00\x02\x00" + bytes(range(255, -1, -1)) * 2
+SOFT_404 = "<html><body>Not Found</body></html>"
+
+SIGNATURES = yaml.safe_dump(
+ {
+ "id": "favicon-detect",
+ "http": [
+ {
+ "method": "GET",
+ "path": ["{{BaseURL}}/favicon.ico"],
+ "matchers": [
+ {
+ "type": "dsl",
+ # redundant "favicon" suffixes are stripped from names
+ "name": "linked-app-favicon",
+ "dsl": ['status_code==200 && ("1059184575" == mmh3(base64_py(body)))'],
+ },
+ {
+ "type": "dsl",
+ "name": "default-app-default-favicon",
+ "dsl": ['status_code==200 && ("1852949020" == mmh3(base64_py(body)))'],
+ },
+ {
+ "type": "dsl",
+ "name": "soft-404-app",
+ "dsl": ['status_code==200 && ("-186779990" == mmh3(base64_py(body)))'],
+ },
+ {"type": "word", "name": "unparseable-app", "words": ["something"]},
+ ],
+ }
+ ],
+ }
+)
+
+
+class TestFavicon(ModuleTestBase):
+ module_name = "favicon"
+ targets = [HTTPSERVER_URL]
+ modules_overrides = ["http", "favicon"]
+ config_overrides = {"modules": {"favicon": {"signatures_url": f"{HTTPSERVER_URL}/favicon-detect.yaml"}}}
+ page = '<html><head><link rel="shortcut icon" href="/static/app.ico"></head><body>hi</body></html>'
+ # (technology, page path, icon path)
+ expected = {("linked-app", "/", "/static/app.ico")}
+
+ async def setup_before_prep(self, module_test):
+ module_test.set_expect_requests({"uri": "/favicon-detect.yaml"}, {"response_data": SIGNATURES})
+
+ async def setup_after_prep(self, module_test):
+ module_test.set_expect_requests({"uri": "/"}, {"response_data": self.page, "content_type": "text/html"})
+ module_test.set_expect_requests({"uri": "/static/app.ico"}, {"response_data": LINKED_ICON})
+ module_test.set_expect_requests({"uri": "/favicon.ico"}, {"response_data": DEFAULT_ICON})
+
+ def check(self, module_test, events):
+ technologies = [
+ (e.data["technology"], e.data["url"], re.search(r" at (\S+) to ", e.discovery_context).group(1))
+ for e in events
+ if e.type == "TECHNOLOGY"
+ ]
+ expected = {(t, f"{HTTPSERVER_URL}{page}", f"{HTTPSERVER_URL}{icon}") for t, page, icon in self.expected}
+ assert sorted(technologies) == sorted(expected), f"Expected {expected}, got {technologies}"
+ assert module_test.module.signatures == {
+ 1059184575: {"linked-app"},
+ 1852949020: {"default-app"},
+ -186779990: {"soft-404-app"},
+ }
+
+
+class TestFaviconDefaultPath(TestFavicon):
+ page = "<html><body>no icon declared</body></html>"
+ expected = {("default-app", "/", "/favicon.ico")}
+
+
+class TestFaviconSoft404(TestFavicon):
+ page = "<html><body>no icon declared</body></html>"
+ expected = set()
+
+ async def setup_after_prep(self, module_test):
+ module_test.set_expect_requests({"uri": "/"}, {"response_data": self.page, "content_type": "text/html"})
+ module_test.set_expect_requests(
+ {"uri": "/favicon.ico"}, {"response_data": SOFT_404, "content_type": "text/html"}
+ )
+
+
+class TestFaviconRedirect(TestFavicon):
+ page = "<html><body>no icon declared</body></html>"
+ expected = {("default-app", "/", "/app/favicon.ico")}
+
+ async def setup_after_prep(self, module_test):
+ module_test.set_expect_requests({"uri": "/"}, {"response_data": self.page, "content_type": "text/html"})
+ module_test.set_expect_requests(
+ {"uri": "/favicon.ico"}, {"status": 302, "headers": {"Location": "/app/favicon.ico"}}
+ )
+ module_test.set_expect_requests({"uri": "/app/favicon.ico"}, {"response_data": DEFAULT_ICON})
+
+
+class TestFaviconSubdirectory(TestFavicon):
+ targets = [HTTPSERVER_URL, f"{HTTPSERVER_URL}/app/", f"{HTTPSERVER_URL}/same/"]
+ page = "<html><body>no icon declared</body></html>"
+ # /same/ serves the root's favicon, so it must not produce a second default-app
+
+ async def setup_after_prep(self, module_test):
+ for path in ("/", "/app/", "/same/"):
+ module_test.set_expect_requests({"uri": path}, {"response_data": self.page, "content_type": "text/html"})
+ module_test.set_expect_requests({"uri": "/favicon.ico"}, {"response_data": DEFAULT_ICON})
+ module_test.set_expect_requests({"uri": "/app/favicon.ico"}, {"response_data": LINKED_ICON})
+ module_test.set_expect_requests({"uri": "/same/favicon.ico"}, {"response_data": DEFAULT_ICON})
+
+ def check(self, module_test, events):
+ technologies = [e for e in events if e.type == "TECHNOLOGY"]
+ assert sorted(e.data["technology"] for e in technologies) == ["default-app", "linked-app"], technologies
+ # whichever of / or /same/ is processed first claims default-app
+ default_app = next(e for e in technologies if e.data["technology"] == "default-app")
+ assert default_app.data["url"] in (f"{HTTPSERVER_URL}/", f"{HTTPSERVER_URL}/same/")
+ linked_app = next(e for e in technologies if e.data["technology"] == "linked-app")
+ assert linked_app.data["url"] == f"{HTTPSERVER_URL}/app/"
+ assert f" at {HTTPSERVER_URL}/app/favicon.ico " in linked_app.discovery_context
+
+
+class TestFaviconSameIconAcrossPorts(TestFavicon):
+ targets = [HTTPSERVER_URL, HTTPSERVER_SSL_URL]
+ page = "<html><body>no icon declared</body></html>"
+
+ async def setup_after_prep(self, module_test):
+ for server in (module_test.httpserver, module_test.httpserver_ssl):
+ server.expect_request("/").respond_with_data(self.page, content_type="text/html")
+ server.expect_request("/favicon.ico").respond_with_data(DEFAULT_ICON)
+
+ def check(self, module_test, events):
+ technologies = [e for e in events if e.type == "TECHNOLOGY"]
+ assert len(technologies) == 1, f"Expected a single default-app event, got {technologies}"
+ assert technologies[0].data["technology"] == "default-app"
+ assert technologies[0].data["url"] in (f"{HTTPSERVER_URL}/", f"{HTTPSERVER_SSL_URL}/")