The recursive internet scanner for hackers. 🧡
Python asmattack-surface-managementautomationbugbountyclieasmhackingneo4josintosint-frameworkpentestingpythonreconrecursionscannersubdomain-enumerationsubdomain-scannersubdomainsthreat-intelligencethreatintel
Fix access_bypass false positives: 2xx-only, suppress overflow, reflection-aware catch-all guard
liquidsec08057be41c79
diff --git a/bbot/core/helpers/helper.py b/bbot/core/helpers/helper.pyindex ef3d78f98..afc1a3c0b 100644--- a/bbot/core/helpers/helper.py+++ b/bbot/core/helpers/helper.py@@ -187,6 +187,7 @@ class ConfigAwareHelper:json=None,timeout=10,on_baseline_ready=None,+ baseline_url_2=None,):return HttpCompare(url,@@ -200,6 +201,7 @@ class ConfigAwareHelper:data=data,json=json,on_baseline_ready=on_baseline_ready,+ baseline_url_2=baseline_url_2,)def temp_filename(self, extension=None):diff --git a/bbot/modules/access_bypass/access_bypass.py b/bbot/modules/access_bypass/access_bypass.pyindex 9a368d152..7ffb1a4ba 100644--- a/bbot/modules/access_bypass/access_bypass.py+++ b/bbot/modules/access_bypass/access_bypass.py@@ -69,9 +69,12 @@ class access_bypass(BaseModule):return False, "no access_bypass submodule applies to this URL"async def handle_event(self, event):+ # blocked-mode checks must not follow redirects (a 302 to /login is not a bypass);+ # the 2xx extension-routing mode keeps the configured behavior+ follow_redirects = self.allow_redirects if event.http_status not in (401, 403, 406, 429) else Falsetry:compare_helper = self.helpers.http_compare(- event.url, allow_redirects=self.allow_redirects, include_cache_buster=False+ event.url, allow_redirects=follow_redirects, include_cache_buster=False)except HttpCompareError as e:self.debug(e)@@ -88,19 +91,12 @@ class access_bypass(BaseModule):if not results:return+ # A host that trips many signatures at once is an unstable baseline or a catch-all,+ # not a stack of real bypasses. Suppress rather than emit a low-signal finding.if len(results) > self.collapse_threshold:- await self.emit_event(- {- "name": "Access Control Bypass",- "description": f"Multiple access-control bypass signatures (exceeded threshold {self.collapse_threshold})",- "host": str(event.host),- "url": event.url,- "severity": "MEDIUM",- "confidence": "LOW",- },- "FINDING",- parent=event,- context=f"{{module}} discovered multiple access-control bypasses ({{event.type}}) for {event.url}",+ self.verbose(+ f"Suppressing {len(results)} access_bypass signatures for {event.url}: "+ f"too many to be real (likely catch-all or unstable baseline)")returndiff --git a/bbot/modules/access_bypass/submodules/auth.py b/bbot/modules/access_bypass/submodules/auth.pyindex 0a23d1dca..2982b4cd5 100644--- a/bbot/modules/access_bypass/submodules/auth.py+++ b/bbot/modules/access_bypass/submodules/auth.py@@ -1,6 +1,6 @@from bbot.errors import HttpCompareError-from .base import BaseAccessBypass+from .base import BaseAccessBypass, is_allowed_status# AWS API Gateway custom-authorizer blueprint sentinels; "deny" returns a single-resource# Deny policy that the gateway caches by token value, authorizing every other resource.@@ -30,7 +30,7 @@ class auth(BaseAccessBypass):token = self.helpers.rand_string(8)try:match, reasons, _, response = await self.compare_helper.compare(- self.event.url, headers={"Authorization": f"Bearer {token}"}, allow_redirects=True+ self.event.url, headers={"Authorization": f"Bearer {token}"}, allow_redirects=self.follow_redirects)except HttpCompareError as e:self.access_bypass.debug(e)@@ -42,14 +42,14 @@ class auth(BaseAccessBypass):)async def is_bypass_from_match(self, match, response):- if match is not False or response is None or str(response.status_code).startswith("4"):+ if match is not False or response is None or not is_allowed_status(response.status_code):return Falsereturn not await self.access_bypass.is_waf_response(response)async def run_apigw(self, baseline):for sentinel in apigw_sentinels:response = await self.helpers.request(- self.event.url, headers={"Authorization": sentinel}, follow_redirects=True+ self.event.url, headers={"Authorization": sentinel}, follow_redirects=False)if response is None:continue@@ -69,7 +69,7 @@ class auth(BaseAccessBypass):root = f"{self.base_url}/"if root == self.event.url:return- response = await self.helpers.request(root, headers={"Authorization": sentinel}, follow_redirects=True)+ response = await self.helpers.request(root, headers={"Authorization": sentinel}, follow_redirects=False)if response is not None and self.is_apigw_bypass(response):self.add_result(f"{self.friendly_name}: API Gateway authorizer bypass via cached Deny policy "@@ -81,6 +81,6 @@ class auth(BaseAccessBypass):@staticmethoddef is_apigw_bypass(response):- if str(response.status_code).startswith("4"):+ if not is_allowed_status(response.status_code):return Falsereturn any(h.lower().startswith("x-amzn-remapped-") for h in response.headers.keys())diff --git a/bbot/modules/access_bypass/submodules/base.py b/bbot/modules/access_bypass/submodules/base.pyindex 3a0615a00..1eb112df3 100644--- a/bbot/modules/access_bypass/submodules/base.py+++ b/bbot/modules/access_bypass/submodules/base.py@@ -15,15 +15,23 @@ class Probe:url: strmethod: str = "GET"headers: dict | None = None- # the same mutation applied to a random sibling path (catch-all control)+ # the same mutation applied to two random nonexistent paths; the catch-all+ # control baselines against these, so a host that answers everything the same+ # way (reflected paths, timestamps and all) is filtered out by HttpCompare itselfsibling_url: str | None = None+ sibling_url_2: str | None = None+++def is_allowed_status(status_code):+ """A bypass means we reached the resource: a 2xx. 3xx (usually to auth) and 5xx are not bypasses."""+ return 200 <= int(status_code) < 300class BaseAccessBypass:"""A family of access-bypass probes.The default `run()` sends each probe from `probes()` against the event's shared- HttpCompare and keeps those that turn a blocked response into a non-4xx one.+ HttpCompare and keeps those that turn a blocked response into a 2xx one.Submodules with their own detection logic override `run()`."""@@ -39,6 +47,9 @@ class BaseAccessBypass:self.helpers = access_bypass.helpersself.event = eventself.compare_helper = compare_helper+ # blocked-mode checks never follow redirects (a 302 to /login is not a bypass);+ # the shared helper already carries the right setting for this event+ self.follow_redirects = getattr(compare_helper, "allow_redirects", False)self.parsed_url = event.parsed_urlself.base_url = f"{self.parsed_url.scheme}://{self.parsed_url.netloc}"self.results = []@@ -75,7 +86,7 @@ class BaseAccessBypass:returntry:match, reasons, _, response = await self.compare_helper.compare(- probe.url, headers=probe.headers, method=probe.method, allow_redirects=True+ probe.url, headers=probe.headers, method=probe.method, allow_redirects=self.follow_redirects)except HttpCompareError as e:error_count += 1@@ -90,26 +101,37 @@ class BaseAccessBypass:async def is_bypass(self, probe, match, response):if match is not False or response is None:return False- if str(response.status_code).startswith("4"):- self.access_bypass.debug(f"Status code changed to {response.status_code}, ignoring")+ if not is_allowed_status(response.status_code):+ self.access_bypass.debug(f"Status code is {response.status_code} (not 2xx), not a bypass")return Falseif await self.access_bypass.is_waf_response(response):self.access_bypass.debug(f"Rejecting {probe.label} based on presence of WAF string")return False- if probe.sibling_url and await self.is_catch_all(probe, response):+ if probe.sibling_url and await self.is_catch_all(probe):self.access_bypass.debug(f"Rejecting {probe.label}: the same mutation succeeds on a nonexistent path")return Falsereturn await self.confirm(probe, response)- async def is_catch_all(self, probe, response):- """Whether the mutation produces the same response against a random sibling path."""- control = await self.helpers.request(- probe.sibling_url, method=probe.method, headers=probe.headers, follow_redirects=True- )- if control is None or str(control.status_code).startswith("4"):+ async def is_catch_all(self, probe):+ """Whether the mutation reaches nothing special: a nonexistent sibling path gets the same treatment.++ Baselines against the mutation applied to two random paths, so HttpCompare filters out+ reflected paths, timestamps and other volatile content before deciding whether the real+ target's response matches the junk template.+ """+ if not probe.sibling_url_2:return False- if control.status_code != response.status_code:+ try:+ control = self.helpers.http_compare(+ probe.sibling_url,+ baseline_url_2=probe.sibling_url_2,+ method=probe.method,+ headers=probe.headers,+ allow_redirects=self.follow_redirects,+ include_cache_buster=False,+ )+ match, _, _, _ = await control.compare(probe.url, headers=probe.headers, method=probe.method)+ except HttpCompareError:+ # the two junk samples disagreed (unstable), so we can't call it a catch-allreturn False- return self.compare_helper.compare_body(- self.compare_helper.parse_body(response.text or ""), self.compare_helper.parse_body(control.text or "")- )+ return match is Truediff --git a/bbot/modules/access_bypass/submodules/headers.py b/bbot/modules/access_bypass/submodules/headers.pyindex 31ef7ab93..5389dd79e 100644--- a/bbot/modules/access_bypass/submodules/headers.py+++ b/bbot/modules/access_bypass/submodules/headers.py@@ -25,6 +25,7 @@ class headers(BaseAccessBypass):path = self.parsed_url.path.lstrip("/")url = f"{self.base_url}/{path}"sibling = f"{self.base_url}/{self.helpers.rand_string(8, digits=False)}"+ sibling_2 = f"{self.base_url}/{self.helpers.rand_string(8, digits=False)}"for header in ip_headers:for value in ip_values:@@ -34,6 +35,7 @@ class headers(BaseAccessBypass):url=url,headers={header: value},sibling_url=sibling,+ sibling_url_2=sibling_2,)yield Probe(key="xfport",@@ -41,6 +43,7 @@ class headers(BaseAccessBypass):url=url,headers={"X-Forwarded-Port": "80"},sibling_url=sibling,+ sibling_url_2=sibling_2,)yield Probe(key="xoriginal",diff --git a/bbot/modules/access_bypass/submodules/path.py b/bbot/modules/access_bypass/submodules/path.pyindex d4421bdb2..8243cd48d 100644--- a/bbot/modules/access_bypass/submodules/path.py+++ b/bbot/modules/access_bypass/submodules/path.py@@ -42,20 +42,23 @@ class path(BaseAccessBypass):friendly_name = "Path Manipulation"def probes(self):- sibling_path = self.sibling_path(self.parsed_url.path)- sibling_mutations = self.mutations(sibling_path)+ # two random sibling paths, so the catch-all control can baseline against the junk template+ sibling_mutations_1 = self.mutations(self.sibling_path(self.parsed_url.path))+ sibling_mutations_2 = self.mutations(self.sibling_path(self.parsed_url.path))seen = set()for key, mutated in self.mutations(self.parsed_url.path).items():if mutated in seen:continueseen.add(mutated)url = f"{self.base_url}{mutated}"- sibling = sibling_mutations.get(key)+ sibling_1 = sibling_mutations_1.get(key)+ sibling_2 = sibling_mutations_2.get(key)yield Probe(key=key,label=f"Modified URL: GET {url}",url=url,- sibling_url=f"{self.base_url}{sibling}" if sibling else None,+ sibling_url=f"{self.base_url}{sibling_1}" if sibling_1 else None,+ sibling_url_2=f"{self.base_url}{sibling_2}" if sibling_2 else None,)def sibling_path(self, path):diff --git a/bbot/test/test_step_2/module_tests/test_module_access_bypass.py b/bbot/test/test_step_2/module_tests/test_module_access_bypass.pyindex 69e6415d8..5fc9d99e2 100644--- a/bbot/test/test_step_2/module_tests/test_module_access_bypass.py+++ b/bbot/test/test_step_2/module_tests/test_module_access_bypass.py@@ -57,9 +57,8 @@ class TestAccessBypass_collapse(ModuleTestBase):module_test.httpserver.no_handler_status_code = 403def check(self, module_test, events):- findings = [e for e in events if e.type == "FINDING"]- assert len(findings) == 1- assert "Multiple access-control bypass signatures" in findings[0].data["description"]+ # many signatures at once = unstable/catch-all host => suppressed entirely+ assert not [e for e in events if e.type == "FINDING"]class TestAccessBypass_aspnetcookieless(ModuleTestBase):@@ -267,25 +266,51 @@ class TestAccessBypass_extension_append_realfile(ModuleTestBase):class TestAccessBypass_catchall(ModuleTestBase):- """A host that answers every path must not produce path-bypass findings."""+ """A blocked target whose every other path 200s (with the path reflected into the body,+ so bodies are all unique) must still be recognized as a catch-all and produce nothing."""targets = [f"{HTTPSERVER_URL}/test"]modules_overrides = ["access_bypass", "http"]module_name = "access_bypass"async def setup_after_prep(self, module_test):- # every unmatched path returns the same 200 bodydef handler(request):- return Response("catch all body", status=200)+ if request.path == "/test":+ return Response("", status=403)+ # reflect the path so every junk response is byte-different (defeats a naive body diff)+ return Response(f"welcome, you asked for {request.path}", status=200)module_test.httpserver.expect_request(re.compile(r"/.*")).respond_with_handler(handler)- # the target itself must read as blocked so the blocked-mode submodules run- module_test.httpserver.no_handler_status_code = 403def check(self, module_test, events):- # /test is 200 (catch-all) so it runs in 2xx mode only; no path/header bypass findingsfindings = [e for e in events if e.type == "FINDING"]- assert not any("Path Manipulation" in f.data["description"] for f in findings)+ assert not any("Path Manipulation" in f.data["description"] for f in findings), (+ f"catch-all host produced path findings: {[f.data['description'] for f in findings]}"+ )+++class TestAccessBypass_5xx_not_bypass(ModuleTestBase):+ """Regression for a Cloudflare+Spring host: blocked baseline, malformed paths 500 (echoing the+ path). A 5xx is not a bypass, and the reflected-path 500s must not each count as a signature."""++ targets = [f"{HTTPSERVER_URL}/test"]+ modules_overrides = ["access_bypass", "http"]+ module_name = "access_bypass"++ async def setup_after_prep(self, module_test):+ def handler(request):+ if request.path == "/test":+ return Response("", status=401)+ return Response(+ json.dumps({"status": 500, "error": "Internal Server Error", "path": request.path}),+ status=500,+ headers={"Content-Type": "application/json"},+ )++ module_test.httpserver.expect_request(re.compile(r"/.*")).respond_with_handler(handler)++ def check(self, module_test, events):+ assert not [e for e in events if e.type == "FINDING"]class TestAccessBypass_apigw_negative(ModuleTestBase):