The recursive internet scanner for hackers. 🧡
Python asmattack-surface-managementautomationbugbountyclieasmhackingneo4josintosint-frameworkpentestingpythonreconrecursionscannersubdomain-enumerationsubdomain-scannersubdomainsthreat-intelligencethreatintel
access_bypass: report nothing when the control or the baseline doesn't hold
liquidsec2d430bba3979
diff --git a/bbot/modules/access_bypass/submodules/auth.py b/bbot/modules/access_bypass/submodules/auth.pyindex c5a5b3664..ac32d7b3c 100644--- a/bbot/modules/access_bypass/submodules/auth.py+++ b/bbot/modules/access_bypass/submodules/auth.py@@ -48,7 +48,7 @@ class auth(BaseAccessBypass):return Falseif await self.access_bypass.is_waf_response(response):return False- return not await self.block_lifted()+ return not await self.block_changed()async def run_apigw(self, baseline):for sentinel in apigw_sentinels:diff --git a/bbot/modules/access_bypass/submodules/base.py b/bbot/modules/access_bypass/submodules/base.pyindex 8d2e7221e..228a3dd32 100644--- a/bbot/modules/access_bypass/submodules/base.py+++ b/bbot/modules/access_bypass/submodules/base.py@@ -68,8 +68,8 @@ class BaseAccessBypass:self.parsed_url = event.parsed_urlself.base_url = f"{self.parsed_url.scheme}://{self.parsed_url.netloc}"self.results = []- # whether the URL itself has stopped being blocked: see block_lifted()- self._block_lifted = None+ # whether the URL itself no longer answers as it did at baseline: see block_changed()+ self._block_changed = Nonedef applies(self):return self.event.http_status in self.trigger_status_codes@@ -133,29 +133,34 @@ class BaseAccessBypass:self.access_bypass.debug(f"Rejecting {probe.label} based on presence of WAF string")return Falseif 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")+ self.access_bypass.debug(+ f"Rejecting {probe.label}: the same mutation succeeds on a nonexistent path, or can't be compared"+ )return False- if await self.block_lifted():- self.access_bypass.debug(f"Rejecting {probe.label}: {self.event.url} itself now answers with a 2xx")+ if await self.block_changed():+ self.access_bypass.debug(f"Rejecting {probe.label}: {self.event.url} no longer answers as it did")return Falsereturn await self.confirm(probe, response)- async def block_lifted(self):+ async def block_changed(self):"""- Whether the URL itself now answers with a 2xx. A block that lifts partway through, like a rate limit or a bot- check, would make every probe after it look like a bypass. Asked once, when a probe first gets through.+ Whether the URL itself no longer answers with its baseline's status, or can't be asked. A block that lifts or+ changes partway through, like a rate limit or a bot check giving way, wasn't the site's own answer, and would+ make every probe after it look like a bypass. Asked once, when a probe first gets through."""- if self._block_lifted is None:+ if self._block_changed is None:+ baseline = await self.compare_helper.get_baseline()response = await self.helpers.request(self.event.url, follow_redirects=self.follow_redirects)- self._block_lifted = response is not None and is_allowed_status(response.status_code)- return self._block_lifted+ self._block_changed = response is None or response.status_code != baseline.status_code+ return self._block_changedasync def is_catch_all(self, probe):- """Whether the mutation reaches nothing special: a nonexistent sibling path gets the same treatment.+ """Whether the mutation may reach nothing special: a nonexistent sibling path gets the same treatment.Baselines against the mutation applied to two random paths, so HttpCompare filters outreflected paths, timestamps and other volatile content before deciding whether the real- target's response matches the junk template.+ target's response matches the junk template. If the two random paths aren't answered alike,+ there's nothing to tell a bypass from, so it may."""if not probe.sibling_url_2:return False@@ -170,6 +175,6 @@ class BaseAccessBypass:)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-all- return False+ # the two junk samples disagreed, so a bypass can't be told from a catch-all+ return Truereturn match is Truediff --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 77bfb7ce4..32de9f670 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@@ -1,5 +1,6 @@import reimport json+import itertoolsfrom werkzeug.wrappers import Response@@ -170,6 +171,56 @@ class TestAccessBypass_block_lifts(ModuleTestBase):assert not [e for e in events if e.type == "FINDING"]+class TestAccessBypass_block_changes(TestAccessBypass_block_lifts):+ """A block that gives way to another answer partway through, like a rate limit to the site's own error, wasn't the+ site's answer, so what got through then isn't a bypass"""++ async def setup_after_prep(self, module_test):+ changed = []++ def bypass(request):+ changed.append(True)+ return Response("alive")++ def page(request):+ if changed and request.environ.get("REQUEST_URI") == "/test":+ return Response("unprocessable", status=422)+ return Response("blocked", status=403)++ module_test.set_expect_requests_handler(expect_args="/test..;/", request_handler=bypass)+ module_test.set_expect_requests_handler(expect_args="/test", request_handler=page)+ module_test.httpserver.no_handler_status_code = 403+++class TestAccessBypass_unstable_control(ModuleTestBase):+ """A probe whose control paths aren't answered alike can't be told from a catch-all, so it isn't reported"""++ targets = [f"{HTTPSERVER_URL}/test"]+ modules_overrides = ["access_bypass", "http"]+ module_name = "access_bypass"+ config_overrides = {"modules": {"access_bypass": {"enabled_submodules": ["path"]}}}++ async def setup_after_prep(self, module_test):+ # the made-up control paths get a page and a not-found in turn, so the control's two samples disagree+ control_answers = itertools.cycle([200, 404])++ def handler(request):+ uri = request.environ.get("REQUEST_URI")+ if uri == "/test..;/":+ return Response("alive")+ # every other mutation of /test, case-swapped too, so only the control's two requests take turns below+ if "test" in uri.lower():+ return Response("blocked", status=403)+ status = next(control_answers)+ return Response("a page" if status == 200 else "not found", status=status)++ module_test.httpserver.expect_request(re.compile(r"/.*")).respond_with_handler(handler)++ def check(self, module_test, events):+ findings = [e.data["description"] for e in events if e.type == "FINDING"]+ assert not findings, findings++class TestAccessBypass_xff(ModuleTestBase):"""T1.1: an IP-spoofing header turns a 406 into a 200."""