Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance boost - cloudcheck, httpx #2065

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bbot/modules/httpx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
import json
import orjson
import tempfile
import subprocess
from pathlib import Path
Expand Down Expand Up @@ -142,11 +142,11 @@ async def handle_batch(self, *events):
proxy = self.scan.http_proxy
if proxy:
command += ["-http-proxy", proxy]
async for line in self.run_process_live(command, input=list(stdin), stderr=subprocess.DEVNULL):
async for line in self.run_process_live(command, text=False, input=list(stdin), stderr=subprocess.DEVNULL):
try:
j = json.loads(line)
except json.decoder.JSONDecodeError:
self.debug(f"Failed to decode line: {line}")
j = await self.helpers.run_in_executor(orjson.loads, line)
except orjson.JSONDecodeError:
self.warning(f"httpx failed to decode line: {line}")
continue

url = j.get("url", "")
Expand Down
7 changes: 4 additions & 3 deletions bbot/modules/internal/cloudcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ async def handle_event(self, event, **kwargs):
base_kwargs["event_type"] = event_type
for sig in sigs:
matches = []
if event.type == "HTTP_RESPONSE":
matches = await self.helpers.re.findall(sig, event.data.get("body", ""))
elif event.type.startswith("DNS_NAME"):
# TODO: convert this to an excavate YARA hook
# if event.type == "HTTP_RESPONSE":
# matches = await self.helpers.re.findall(sig, event.data.get("body", ""))
if event.type.startswith("DNS_NAME"):
for host in str_hosts_to_check:
match = sig.match(host)
if match:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TestCloudCheck(ModuleTestBase):
modules_overrides = ["httpx", "excavate", "cloudcheck"]

async def setup_after_prep(self, module_test):
module_test.set_expect_requests({"uri": "/"}, {"response_data": "<a href='asdf.s3.amazonaws.com'/>"})
module_test.set_expect_requests({"uri": "/"}, {"response_data": "<a href='http://asdf.s3.amazonaws.com'/>"})

scan = Scanner(config={"cloudcheck": True})
await scan._prep()
Expand Down
86 changes: 85 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ httpx = "^0.27.0"
puremagic = "^1.28"
cloudcheck = "^6.0.0.602"
radixtarget = "^2.0.0.50"
orjson = "^3.10.12"

[tool.poetry.group.dev.dependencies]
poetry-dynamic-versioning = ">=0.21.4,<1.5.0"
Expand Down
Loading