Skip to content

armgit / bbot

Public Imported from GitHub
0

The recursive internet scanner for hackers. 🧡

access_bypass: recheck the URL itself before reporting a bypass, and the page before reporting extension routing

liquidsecabf0f5e407ae
diff --git a/bbot/modules/access_bypass/submodules/auth.py b/bbot/modules/access_bypass/submodules/auth.py
index 7a4a407f1..c5a5b3664 100644
--- a/bbot/modules/access_bypass/submodules/auth.py
+++ b/bbot/modules/access_bypass/submodules/auth.py
@@ -46,7 +46,9 @@ class auth(BaseAccessBypass):
return False
if not has_content(response, reasons):
return False
- return not await self.access_bypass.is_waf_response(response)
+ if await self.access_bypass.is_waf_response(response):
+ return False
+ return not await self.block_lifted()
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.py
index 5a1b842f5..8d2e7221e 100644
--- a/bbot/modules/access_bypass/submodules/base.py
+++ b/bbot/modules/access_bypass/submodules/base.py
@@ -68,6 +68,8 @@ class BaseAccessBypass:
self.parsed_url = event.parsed_url
self.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
def applies(self):
return self.event.http_status in self.trigger_status_codes
@@ -133,8 +135,21 @@ class BaseAccessBypass:
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 False
+ if await self.block_lifted():
+ self.access_bypass.debug(f"Rejecting {probe.label}: {self.event.url} itself now answers with a 2xx")
+ return False
return await self.confirm(probe, response)
+ async def block_lifted(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.
+ """
+ if self._block_lifted is None:
+ 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
+
async def is_catch_all(self, probe):
"""Whether the mutation reaches nothing special: a nonexistent sibling path gets the same treatment.
diff --git a/bbot/modules/access_bypass/submodules/extension_routing.py b/bbot/modules/access_bypass/submodules/extension_routing.py
index b09eac6dc..c5b814a98 100644
--- a/bbot/modules/access_bypass/submodules/extension_routing.py
+++ b/bbot/modules/access_bypass/submodules/extension_routing.py
@@ -37,4 +37,19 @@ class extension_routing(BaseAccessBypass):
self.access_bypass.debug("Ignoring positive result due to presence of parameter name in result")
continue
if match is False and str(response.status_code).startswith("2") and "body" in reasons:
+ if await self.page_changed(path, rand_string):
+ self.access_bypass.debug(f"Rejecting {url}: the page changes without the extension too")
+ continue
self.add_result(await self.describe(f"Modified URL: {url}", reasons, response), confidence="LOW")
+
+ 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 that
+ changes over time, or a block that starts partway through, rather than routing by extension.
+ """
+ control = f"{self.base_url}/{path}?{rand_string}={self.helpers.rand_string(6)}"
+ try:
+ match, reasons, _, response = await self.compare_helper.compare(control, allow_redirects=True)
+ except HttpCompareError:
+ return True
+ return response is None or (match is False and "body" in reasons)
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.py
index c40058d7c..77bfb7ce4 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
@@ -117,6 +117,59 @@ class TestAccessBypass_extension_routing(ModuleTestBase):
)
+class TestAccessBypass_extension_routing_page_changes(ModuleTestBase):
+ """A page that changes partway through the probes changes without the extension too, so it isn't routing"""
+
+ targets = [HTTPSERVER_URL]
+ modules_overrides = ["http", "access_bypass"]
+ module_name = "access_bypass"
+ body = "<html><title>t</title><body><p>Hello null!</p></body></html>"
+ body_changed = "<html><title>t</title><body><p>Hello AAAAAAAAAAAAAA!</p></body></html>"
+
+ async def setup_after_prep(self, module_test):
+ rand_string = module_test.scan.modules["access_bypass"].rand_string
+ changed = []
+
+ def handler(request):
+ if request.query_string.decode() == f"{rand_string}=.jpg":
+ changed.append(True)
+ return Response(self.body_changed if changed else self.body, content_type="text/html")
+
+ module_test.set_expect_requests_handler(expect_args=re.compile("/.*"), request_handler=handler)
+
+ def check(self, module_test, events):
+ assert not [e for e in events if e.type == "FINDING"]
+
+
+class TestAccessBypass_block_lifts(ModuleTestBase):
+ """A block that lifts partway through makes the URL itself answer, so what got through then isn't a bypass"""
+
+ 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):
+ lifted = []
+
+ def bypass(request):
+ lifted.append(True)
+ return Response("alive")
+
+ def page(request):
+ # the URL itself, not the mutations of it that also land here
+ if lifted and request.environ.get("REQUEST_URI") == "/test":
+ return Response("public page")
+ 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
+
+ def check(self, module_test, events):
+ assert not [e for e in events if e.type == "FINDING"]
+
+
class TestAccessBypass_xff(ModuleTestBase):
"""T1.1: an IP-spoofing header turns a 406 into a 200."""