The recursive internet scanner for hackers. 🧡
Python asmattack-surface-managementautomationbugbountyclieasmhackingneo4josintosint-frameworkpentestingpythonreconrecursionscannersubdomain-enumerationsubdomain-scannersubdomainsthreat-intelligencethreatintel
Require new content for an access bypass, and show the blocked and bypassed responses
liquidsec77b8714f9010
diff --git a/bbot/core/helpers/web/response_event.py b/bbot/core/helpers/web/response_event.pyindex bf1b07851..2c63c8937 100644--- a/bbot/core/helpers/web/response_event.py+++ b/bbot/core/helpers/web/response_event.py@@ -11,6 +11,12 @@ from urllib.parse import urlparse_TITLE_REGEX = re.compile(r"<title[^>]*>(.*?)</title>", re.IGNORECASE | re.DOTALL)+def extract_title(body):+ """The page's <title>, or "" if it has none."""+ match = _TITLE_REGEX.search(body or "")+ return match.group(1).strip() if match else ""++def response_to_event_dict(response, url_input, method="GET"):"""Convert a blasthttp.Response into the dict format HTTP_RESPONSE events expect.@@ -50,9 +56,7 @@ def response_to_event_dict(response, url_input, method="GET"):title = ""if not decode_error:body = response.body- title_match = _TITLE_REGEX.search(body)- if title_match:- title = title_match.group(1).strip()+ title = extract_title(body)j = {"url": response.url,diff --git a/bbot/modules/access_bypass/access_bypass.py b/bbot/modules/access_bypass/access_bypass.pyindex 326c828fd..48b5d345d 100644--- a/bbot/modules/access_bypass/access_bypass.py+++ b/bbot/modules/access_bypass/access_bypass.py@@ -31,8 +31,8 @@ class access_bypass(BaseModule):)state_changing_methods: bool = Field(False,- description="Let the 'method' submodule send state-changing verbs (POST/PUT/PATCH/DELETE) and "- "method-override headers. These can modify the target, so enabling this makes the module invasive.",+ description="Send state-changing verbs (POST/PUT/PATCH/DELETE), method-override headers, and an empty "+ "POST. These can modify the target, so enabling this makes the module invasive.",)# when more than this many signatures fire on one URL, collapse into a single findingdiff --git a/bbot/modules/access_bypass/submodules/auth.py b/bbot/modules/access_bypass/submodules/auth.pyindex 2982b4cd5..7a4a407f1 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, is_allowed_status+from .base import BaseAccessBypass, has_content, 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.@@ -35,15 +35,17 @@ class auth(BaseAccessBypass):except HttpCompareError as e:self.access_bypass.debug(e)return- if await self.is_bypass_from_match(match, response):+ if await self.is_bypass_from_match(match, reasons, response):self.add_result(- f"{self.friendly_name}: [{','.join(reasons)}] Sig: [Added Header: Authorization: Bearer <garbage>]",+ await self.describe(f"Added Header: Authorization: Bearer {token}", reasons, response),confidence="MEDIUM",)- async def is_bypass_from_match(self, match, response):+ async def is_bypass_from_match(self, match, reasons, response):if match is not False or response is None or not is_allowed_status(response.status_code):return False+ if not has_content(response, reasons):+ return Falsereturn not await self.access_bypass.is_waf_response(response)async def run_apigw(self, baseline):@@ -55,8 +57,8 @@ class auth(BaseAccessBypass):continueif self.is_apigw_bypass(response):self.add_result(- f"{self.friendly_name}: API Gateway authorizer bypass via 'Authorization: {sentinel}' "- f"(backend reached, x-amzn-remapped-* headers present)",+ f"{self.friendly_name}. Technique: [API Gateway Authorizer] Signature: [Added Header: "+ f"Authorization: {sentinel}] Indicator: [x-amzn-remapped-* headers, backend reached]",severity="HIGH",confidence="HIGH",)@@ -72,8 +74,8 @@ class auth(BaseAccessBypass):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 "- f"('Authorization: {sentinel}'); {root} reached the backend",+ f"{self.friendly_name}. Technique: [API Gateway Authorizer, cached Deny policy] Signature: "+ f"[Added Header: Authorization: {sentinel}] Indicator: [x-amzn-remapped-* headers, backend reached at {root}]",severity="HIGH",confidence="HIGH",url=root,diff --git a/bbot/modules/access_bypass/submodules/base.py b/bbot/modules/access_bypass/submodules/base.pyindex 1eb112df3..5a1b842f5 100644--- a/bbot/modules/access_bypass/submodules/base.py+++ b/bbot/modules/access_bypass/submodules/base.py@@ -1,6 +1,7 @@from dataclasses import dataclassfrom bbot.errors import HttpCompareError+from bbot.core.helpers.web.response_event import extract_title# URLs answering with these codes are treated as access-controlledBLOCKED_STATUS_CODES = (401, 403, 406, 429)@@ -27,6 +28,20 @@ def is_allowed_status(status_code):return 200 <= int(status_code) < 300+def has_content(response, reasons):+ """A bypass has to show us something: a body, and not the one the block answered with."""+ return "body" in reasons and bool((response.text or "").strip())+++def summarize(response):+ """Status, size and title, for showing a response in a finding."""+ summary = f"{response.status_code}, {len(response.content)} bytes"+ title = " ".join(extract_title(response.text).split())+ if title:+ summary += f", '{title[:50]}'"+ return summary++class BaseAccessBypass:"""A family of access-bypass probes.@@ -64,8 +79,13 @@ class BaseAccessBypass:"""Submodule-specific acceptance check, run after the common success rules."""return True- def describe(self, probe, reasons):- return f"{self.friendly_name}: [{','.join(reasons)}] Sig: [{probe.label}]"+ async def describe(self, label, reasons, response):+ """The signature, and the blocked response next to the one that got through."""+ baseline = await self.compare_helper.get_baseline()+ return (+ f"{self.friendly_name}. Signature: [{label}] Baseline: [{summarize(baseline)}] -> "+ f"Probe: [{summarize(response)}] Differences: [{','.join(reasons)}]"+ )def add_result(self, description, severity=None, confidence=None, url=None):self.results.append(@@ -92,18 +112,21 @@ class BaseAccessBypass:error_count += 1self.access_bypass.debug(e)continue- if await self.is_bypass(probe, match, response):- self.add_result(self.describe(probe, reasons))+ if await self.is_bypass(probe, match, reasons, response):+ self.add_result(await self.describe(probe.label, reasons, response))async def get_probes(self):return list(self.probes())- async def is_bypass(self, probe, match, response):+ async def is_bypass(self, probe, match, reasons, response):if match is not False or response is None:return Falseif not is_allowed_status(response.status_code):self.access_bypass.debug(f"Status code is {response.status_code} (not 2xx), not a bypass")return False+ if not has_content(response, reasons):+ self.access_bypass.debug(f"Rejecting {probe.label}: the {response.status_code} brought no new content")+ 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 Falsediff --git a/bbot/modules/access_bypass/submodules/extension_routing.py b/bbot/modules/access_bypass/submodules/extension_routing.pyindex 7adc72a31..b09eac6dc 100644--- a/bbot/modules/access_bypass/submodules/extension_routing.py+++ b/bbot/modules/access_bypass/submodules/extension_routing.py@@ -37,7 +37,4 @@ class extension_routing(BaseAccessBypass):self.access_bypass.debug("Ignoring positive result due to presence of parameter name in result")continueif match is False and str(response.status_code).startswith("2") and "body" in reasons:- self.add_result(- f"{self.friendly_name}: [{','.join(reasons)}] Sig: [Modified URL: {url}]",- confidence="LOW",- )+ self.add_result(await self.describe(f"Modified URL: {url}", reasons, response), confidence="LOW")diff --git a/bbot/modules/access_bypass/submodules/headers.py b/bbot/modules/access_bypass/submodules/headers.pyindex ef286337a..76edd6e9a 100644--- a/bbot/modules/access_bypass/submodules/headers.py+++ b/bbot/modules/access_bypass/submodules/headers.py@@ -57,10 +57,12 @@ class headers(BaseAccessBypass):url=url,headers={"X-rewrite-url": "nonsense"},)- yield Probe(- key="cl0",- label="Modified URL: POST (Content-Length: 0)",- url=url,- method="POST",- headers={"Content-Length": "0"},- )+ # a POST on the wire may trigger actions, so it waits for state_changing_methods like the method submodule's+ if self.access_bypass.config.get("state_changing_methods", False):+ yield Probe(+ key="cl0",+ label="Modified Method: POST, Added Header: Content-Length: 0",+ url=url,+ method="POST",+ headers={"Content-Length": "0"},+ )diff --git a/bbot/modules/access_bypass/submodules/method.py b/bbot/modules/access_bypass/submodules/method.pyindex 0b86d52a1..43a2e6e51 100644--- a/bbot/modules/access_bypass/submodules/method.py+++ b/bbot/modules/access_bypass/submodules/method.py@@ -1,8 +1,11 @@+import re+from .base import BaseAccessBypass, Probe-# Side-effect-free verbs. HEAD/OPTIONS can't modify state; an unknown verb (ACB) is routed as GET+# Side-effect-free verbs. OPTIONS can't modify state; an unknown verb (ACB) is routed as GET# by servers that don't recognize it, bypassing GET-specific deny rules without touching anything.-safe_methods = ["HEAD", "OPTIONS", "ACB"]+# HEAD is left out: it never carries a body, so it can't show we reached anything.+safe_methods = ["OPTIONS", "ACB"]# State-changing verbs. Only sent when `state_changing_methods` is enabled (makes the module invasive).state_changing_verbs = ["POST", "PUT", "PATCH", "DELETE"]@@ -11,6 +14,9 @@ state_changing_verbs = ["POST", "PUT", "PATCH", "DELETE"]# A POST on the wire may trigger actions, so these are gated behind `state_changing_methods` too.override_headers = ["X-HTTP-Method-Override", "X-HTTP-Method", "X-Method-Override"]+# an OPTIONS body that only lists the allowed methods, e.g. "GET,HEAD,POST"+method_list_regex = re.compile(r"^[A-Z]+(\s*,\s*[A-Z]+)*$")+class method(BaseAccessBypass):friendly_name = "Method Manipulation"@@ -38,10 +44,16 @@ class method(BaseAccessBypass):for header in override_headers:yield Probe(key=f"override:{header}",- label=f"Added Header: {header}: GET (POST)",+ label=f"Modified Method: POST, Added Header: {header}: GET",url=url,method="POST",headers={header: "GET"},sibling_url=sibling,sibling_url_2=sibling_2,)++ async def confirm(self, probe, response):+ if probe.method == "OPTIONS" and method_list_regex.match(response.text.strip()):+ self.access_bypass.debug(f"Rejecting {probe.label}: the body only lists the allowed methods")+ return False+ return Truediff --git a/bbot/modules/access_bypass/submodules/nextjs.py b/bbot/modules/access_bypass/submodules/nextjs.pyindex 9ff03300f..cb5dd75f0 100644--- a/bbot/modules/access_bypass/submodules/nextjs.py+++ b/bbot/modules/access_bypass/submodules/nextjs.py@@ -48,8 +48,9 @@ class nextjs(BaseAccessBypass):page_props = self.extract_page_props(response.text or "")if page_props is not None:self.add_result(- f"{self.friendly_name}: {self.event.url} redirects to "- f"{self.event.redirect_location}, but its data route {data_url} returned page data unauthenticated",+ f"{self.friendly_name}. Signature: [Modified URL: {data_url}] "+ f"Indicator: [{self.event.url} redirects to {self.event.redirect_location}, its data route "+ f"returned page data unauthenticated]",confidence="HIGH",url=data_url,)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 212a08bc7..c40058d7c 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@@ -428,6 +428,63 @@ class TestAccessBypass_method_options_catchall(ModuleTestBase):assert not any("Modified Method: OPTIONS" in f.data["description"] for f in findings)+class TestAccessBypass_method_options_no_content(ModuleTestBase):+ """OPTIONS answering 200 on the blocked path only, with no content, is not a bypass."""++ targets = [f"{HTTPSERVER_URL}/secure"]+ modules_overrides = ["access_bypass", "http"]+ module_name = "access_bypass"+ options_body = ""++ async def setup_after_prep(self, module_test):+ def handler(request):+ if request.method == "OPTIONS":+ if request.path == "/secure":+ return Response(self.options_body, status=200, headers={"Allow": "GET,HEAD,POST"})+ return Response("not found", status=404)+ return Response("access denied", status=403)++ module_test.httpserver.expect_request(re.compile(r"/.*")).respond_with_handler(handler)++ def check(self, module_test, events):+ findings = [e for e in events if e.type == "FINDING"]+ assert not any("Method Manipulation" in f.data["description"] for f in findings), (+ f"OPTIONS without content produced a finding: {[f.data['description'] for f in findings]}"+ )+++class TestAccessBypass_method_options_method_list(TestAccessBypass_method_options_no_content):+ """An OPTIONS body that only lists the allowed methods is not content."""++ options_body = "GET,HEAD,POST"+++class TestAccessBypass_method_unknown_verb(ModuleTestBase):+ """An unknown verb routed to the real page is a bypass, shown next to the blocked response."""++ targets = [f"{HTTPSERVER_URL}/secure"]+ modules_overrides = ["access_bypass", "http"]+ module_name = "access_bypass"++ async def setup_after_prep(self, module_test):+ def handler(request):+ if request.method == "ACB" and request.path == "/secure":+ return Response("<html><title>Admin Panel</title>admin area reached</html>", status=200)+ if request.method == "ACB":+ return Response("not found", status=404)+ return Response("access denied", status=403)++ module_test.httpserver.expect_request(re.compile(r"/.*")).respond_with_handler(handler)++ def check(self, module_test, events):+ findings = [e for e in events if e.type == "FINDING" and "Method Manipulation" in e.data["description"]]+ assert len(findings) == 1+ assert findings[0].data["description"] == (+ "Method Manipulation. Signature: [Modified Method: ACB] Baseline: [403, 13 bytes] -> "+ "Probe: [200, 57 bytes, 'Admin Panel'] Differences: [code,body]"+ )++class TestAccessBypass_encoded_qmark(ModuleTestBase):"""Family 1: /admin%3F truncates at the origin to /admin, bypassing the block on /admin."""diff --git a/docs/scanning/configuration.md b/docs/scanning/configuration.mdindex 4f0c9d7aa..3992cff42 100644--- a/docs/scanning/configuration.md+++ b/docs/scanning/configuration.md@@ -479,7 +479,7 @@ In addition to the stated options for each module, the following universal optio|--------------------------------------------------------|------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|| modules.access_bypass.allow_redirects | bool | Follow redirects when comparing responses. Disabling trades false positives for false negatives. | True || modules.access_bypass.enabled_submodules | list[str] | Which access_bypass submodules to run. Empty list enables all. | ['path', 'headers', 'method', 'auth', 'extension_routing', 'nextjs'] |-| modules.access_bypass.state_changing_methods | bool | Let the 'method' submodule send state-changing verbs (POST/PUT/PATCH/DELETE) and method-override headers. These can modify the target, so enabling this makes the module invasive. | False |+| modules.access_bypass.state_changing_methods | bool | Send state-changing verbs (POST/PUT/PATCH/DELETE), method-override headers, and an empty POST. These can modify the target, so enabling this makes the module invasive. | False || modules.baddns.custom_nameservers | list[str] | Force BadDNS to use a list of custom nameservers | [] || modules.baddns.enabled_submodules | list[str] | A list of submodules to enable. Empty list (default) enables CNAME, MX, TXT and DELEGATION Only | [] || modules.baddns.min_confidence | ConfidenceLiteral | Minimum confidence to emit | MEDIUM |