The recursive internet scanner for hackers. 🧡
Python asmattack-surface-managementautomationbugbountyclieasmhackingneo4josintosint-frameworkpentestingpythonreconrecursionscannersubdomain-enumerationsubdomain-scannersubdomainsthreat-intelligencethreatintel
access_bypass: three more checks before reporting a bypass
liquidsec3572bd5cbb76
diff --git a/bbot/modules/access_bypass/submodules/base.py b/bbot/modules/access_bypass/submodules/base.pyindex 5c447c35b..27258bd6c 100644--- a/bbot/modules/access_bypass/submodules/base.py+++ b/bbot/modules/access_bypass/submodules/base.py@@ -146,14 +146,18 @@ class BaseAccessBypass:async def block_changed(self):"""- 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.+ Whether the URL itself no longer answers as it did: its baseline isn't the status it was found blocked with,+ or now it doesn't answer with its baseline's status, or can't be asked. A block that lifts or changes, 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_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_changed = response is None or response.status_code != baseline.status_code+ if baseline.status_code != self.event.http_status:+ self._block_changed = True+ else:+ response = await self.helpers.request(self.event.url, follow_redirects=self.follow_redirects)+ self._block_changed = response is None or response.status_code != baseline.status_codereturn self._block_changedasync def is_catch_all(self, probe):diff --git a/bbot/modules/access_bypass/submodules/extension_routing.py b/bbot/modules/access_bypass/submodules/extension_routing.pyindex c5b814a98..f48801775 100644--- a/bbot/modules/access_bypass/submodules/extension_routing.py+++ b/bbot/modules/access_bypass/submodules/extension_routing.py@@ -37,11 +37,26 @@ 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:- if await self.page_changed(path, rand_string):+ if not await self.routes_again(url, path, rand_string):self.access_bypass.debug(f"Rejecting {url}: the page changes without the extension too")continueself.add_result(await self.describe(f"Modified URL: {url}", reasons, response), confidence="LOW")+ async def routes_again(self, url, path, rand_string):+ """+ Whether the page keeps answering without the extension as it did at baseline, while `url` differs again: a+ routing rule answers the same way every time, where a page that changes on its own differs now and then.+ """+ if await self.page_changed(path, rand_string):+ return False+ try:+ match, reasons, _, response = await self.compare_helper.compare(url, allow_redirects=True)+ except HttpCompareError:+ return False+ if response is None or match is not False or "body" not in reasons:+ return False+ return not await self.page_changed(path, rand_string)+async def page_changed(self, path, rand_string):"""Whether the page now differs from its baseline with the same parameter and no extension in it: content thatdiff --git a/bbot/modules/access_bypass/submodules/path.py b/bbot/modules/access_bypass/submodules/path.pyindex c793e048c..2be3a8b5e 100644--- a/bbot/modules/access_bypass/submodules/path.py+++ b/bbot/modules/access_bypass/submodules/path.py@@ -55,6 +55,8 @@ class path(BaseAccessBypass):friendly_name = "Path Manipulation"# what the URL's path answers without its trailing slash (see reaches_path_without_slash)_without_slash = None+ # what made-up paths inside the URL's path answer (see reaches_catch_all_inside)+ _inside = Nonedef probes(self):# random sibling paths, so the catch-all control can baseline against the junk template: two, and two more for@@ -134,8 +136,33 @@ class path(BaseAccessBypass):f"Rejecting {probe.label}: it gets what {self.event.url} answers without its trailing slash")return False+ if await self.reaches_catch_all_inside(probe):+ self.access_bypass.debug(+ f"Rejecting {probe.label}: it gets what made-up paths inside {self.event.url} get"+ )+ return Falsereturn True+ async def reaches_catch_all_inside(self, probe):+ """+ Whether the probe gets what two made-up paths inside the URL's path get: a catch-all, like the page an+ application folder answers any path in it with, rather than what's blocked. The sibling controls are made up+ next to the URL, outside such a folder. Two that aren't answered alike can't tell a catch-all from a bypass.+ """+ if self._inside is None:+ path = self.parsed_url.path.rstrip("/")+ self._inside = self.helpers.http_compare(+ f"{self.base_url}{path}/{self.helpers.rand_string(8, digits=False)}",+ baseline_url_2=f"{self.base_url}{path}/{self.helpers.rand_string(8, digits=False)}",+ allow_redirects=self.follow_redirects,+ include_cache_buster=False,+ )+ try:+ match, _, _, _ = await self._inside.compare(probe.url, headers=probe.headers, method=probe.method)+ except HttpCompareError:+ return True+ return match is True+async def reaches_path_without_slash(self, probe):"""For a URL ending in a slash: whether the probe gets what the same path answers without it. Mutations are builtdiff --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 4d2791faa..3d53d6782 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@@ -221,6 +221,80 @@ class TestAccessBypass_unstable_control(ModuleTestBase):assert not findings, findings+class TestAccessBypass_extension_routing_differs_once(TestAccessBypass_extension_routing_page_changes):+ """A page that differs once, on one extension's probe, changes on its own rather than routing by extension"""++ async def setup_after_prep(self, module_test):+ rand_string = module_test.scan.modules["access_bypass"].rand_string+ answered = []++ def handler(request):+ # only the first .pdf probe, as a page that changes on its own now and then would+ if request.query_string.decode() == f"{rand_string}=.pdf" and not answered:+ answered.append(True)+ return Response(self.body_changed, content_type="text/html")+ return Response(self.body, content_type="text/html")++ module_test.set_expect_requests_handler(expect_args=re.compile("/.*"), request_handler=handler)+++class TestAccessBypass_unblocked_before_baseline(ModuleTestBase):+ """A URL found blocked that answers by the time it's probed, like a rate limit giving way, has no block left to get+ past, so a header that changes the page isn't a bypass"""++ targets = [f"{HTTPSERVER_URL}/search"]+ modules_overrides = ["access_bypass", "http"]+ module_name = "access_bypass"+ config_overrides = {"modules": {"access_bypass": {"enabled_submodules": ["headers"]}}}++ async def setup_after_prep(self, module_test):+ requests = []++ def page(request):+ requests.append(True)+ if len(requests) == 1:+ return Response("blocked", status=403)+ # the page shows where the visitor came from+ referer = request.headers.get("Referer", "")+ return Response(+ f"<html><title>Search</title><body>Back to {referer}</body></html>", content_type="text/html"+ )++ module_test.set_expect_requests_handler(expect_args="/search", request_handler=page)+ module_test.httpserver.no_handler_status_code = 404++ def check(self, module_test, events):+ findings = [e.data["description"] for e in events if e.type == "FINDING"]+ assert not findings, findings+++class TestAccessBypass_folder_catchall(ModuleTestBase):+ """An application that answers any path in its blocked folder with one page: a probe that gets that page reached+ the catch-all, not what's blocked"""++ targets = [f"{HTTPSERVER_URL}/app/"]+ 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):+ catch_all = "<html><title></title><body>community home</body></html>"++ def handler(request):+ if request.path == "/app/":+ return Response("Forbidden: directory listing is denied", status=403)+ # any path inside the folder, and the folder's name with a semicolon after it, reach the application+ if re.fullmatch(r"/app(;|/;)/|/app/[a-zA-Z]+", request.path):+ return Response(catch_all, content_type="text/html")+ return Response("not found", status=404)++ 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."""