Skip to content

armgit / bbot

Public Imported from GitHub
0

The recursive internet scanner for hackers. 🧡

access_bypass: reject a probe that only gets the path without the URL's trailing slash

liquidsecc013492e911b
diff --git a/bbot/modules/access_bypass/submodules/path.py b/bbot/modules/access_bypass/submodules/path.py
index b85f8493e..c793e048c 100644
--- a/bbot/modules/access_bypass/submodules/path.py
+++ b/bbot/modules/access_bypass/submodules/path.py
@@ -3,6 +3,7 @@ from contextlib import suppress
import puremagic
+from bbot.errors import HttpCompareError
from .base import BaseAccessBypass, Probe
# appended to (suffix) or prepended before (prefix) the path
@@ -52,6 +53,8 @@ traversal_prefixes = ["..%2f", "%2e%2e/", "..%252f", "..%5c"]
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
def probes(self):
# random sibling paths, so the catch-all control can baseline against the junk template: two, and two more for
@@ -126,8 +129,32 @@ class path(BaseAccessBypass):
if ext in static_extensions and self.is_real_asset(ext, response):
self.access_bypass.debug(f"Rejecting {probe.label}: response is a real {ext} file")
return False
+ if await self.reaches_path_without_slash(probe):
+ self.access_bypass.debug(
+ f"Rejecting {probe.label}: it gets what {self.event.url} answers without its trailing slash"
+ )
+ return False
return 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 built
+ from the path without its slash, which can be a different route than the one blocked, and not blocked at all.
+ """
+ path = self.parsed_url.path
+ if len(path) <= 1 or not path.endswith("/"):
+ return False
+ if self._without_slash is None:
+ self._without_slash = self.helpers.http_compare(
+ f"{self.base_url}{path.rstrip('/')}", allow_redirects=self.follow_redirects, include_cache_buster=False
+ )
+ try:
+ match, _, _, _ = await self._without_slash.compare(probe.url, headers=probe.headers, method=probe.method)
+ except HttpCompareError:
+ # a path that doesn't answer the same way twice tells nothing about the probe
+ return False
+ return match is True
+
@staticmethod
def is_real_asset(ext, response):
"""Whether the response is actually a file of type `ext`, by content type or by magic bytes."""
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 9e12f22b1..4d2791faa 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
@@ -702,3 +702,38 @@ class TestAccessBypass_catch_all_real_bypass(TestAccessBypass_catch_all_changed_
findings = [e.data["description"] for e in events if e.type == "FINDING" and e.data["severity"] == "MEDIUM"]
assert len(findings) == 1, findings
assert f"{HTTPSERVER_URL}/static/app..;/" in findings[0]
+
+
+class TestAccessBypass_trailing_slash(ModuleTestBase):
+ """
+ Mutations are built from the path without its trailing slash, which can be a different, open route: a probe that
+ only gets what that path answers isn't a bypass
+ """
+
+ targets = [f"{HTTPSERVER_URL}/files/list/"]
+ 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):
+ def handler(request):
+ uri = request.environ.get("REQUEST_URI")
+ # how a lenient server reads the path: repeated slashes collapse, and a bare ? is dropped
+ path = re.sub(r"/{2,}", "/", uri.split("?")[0])
+ if path == "/files/list/":
+ return Response("authentication required", status=401)
+ if path == "/files/list":
+ return Response('{"files": ["a.pdf", "b.pdf"]}', content_type="application/json")
+ 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" and e.data["severity"] == "MEDIUM"]
+ assert not findings, findings
+
+
+class TestAccessBypass_path_trailing_slash(TestAccessBypass_path):
+ """A URL ending in a slash whose path without it is blocked too still has its bypasses found"""
+
+ targets = [f"{HTTPSERVER_URL}/test/"]