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

More Misc Bugfixes #2105

Merged
merged 5 commits into from
Dec 20, 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
5 changes: 4 additions & 1 deletion bbot/core/event/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def parent(self, parent):
if t in ("spider-danger", "spider-max"):
self.add_tag(t)
elif not self._dummy:
log.warning(f"Tried to set invalid parent on {self}: (got: {parent})")
log.warning(f"Tried to set invalid parent on {self}: (got: {repr(parent)} ({type(parent)}))")

@property
def parent_id(self):
Expand Down Expand Up @@ -1042,6 +1042,9 @@ def sanitize_data(self, data):
blob = None
try:
self._data_path = Path(data["path"])
# prepend the scan's home dir if the path is relative
if not self._data_path.is_absolute():
self._data_path = self.scan.home / self._data_path
if self._data_path.is_file():
self.add_tag("file")
if file_blobs:
Expand Down
4 changes: 3 additions & 1 deletion bbot/modules/filedownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ def make_filename(self, url, content_type=None):
if extension:
filename = f"{filename}.{extension}"
orig_filename = f"{orig_filename}.{extension}"
return orig_filename, self.download_dir / filename, base_url
file_destination = self.download_dir / filename
file_destination = self.helpers.truncate_filename(file_destination)
return orig_filename, file_destination, base_url

async def report(self):
if self.files_downloaded > 0:
Expand Down
3 changes: 3 additions & 0 deletions bbot/modules/gowitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ async def handle_batch(self, *events):
url = screenshot["url"]
final_url = screenshot["final_url"]
filename = self.screenshot_path / screenshot["filename"]
filename = filename.relative_to(self.scan.home)
# NOTE: this prevents long filenames from causing problems in BBOT, but gowitness will still fail to save it.
filename = self.helpers.truncate_filename(filename)
webscreenshot_data = {"path": str(filename), "url": final_url}
parent_event = event_dict[url]
await self.emit_event(
Expand Down
25 changes: 25 additions & 0 deletions bbot/test/test_step_2/module_tests/test_module_filedownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,28 @@ def check(self, module_test, events):
# we don't want html files
html_files = list(download_dir.glob("*.html"))
assert len(html_files) == 0, "HTML files were erroneously downloaded"


class TestFileDownloadLongFilename(TestFileDownload):
async def setup_after_prep(self, module_test):
module_test.set_expect_requests(
{"uri": "/"},
{
"response_data": '<a href="/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity.txt"/>'
},
)
module_test.set_expect_requests(
{
"uri": "/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity.txt"
},
{
"response_data": "juicy stuff",
},
)

def check(self, module_test, events):
filesystem_events = [e for e in events if e.type == "FILESYSTEM"]
assert len(filesystem_events) == 1
file_path = Path(filesystem_events[0].data["path"])
assert file_path.is_file(), f"File not found at {file_path}"
assert file_path.read_text() == "juicy stuff", f"File at {file_path} does not contain the correct content"
32 changes: 32 additions & 0 deletions bbot/test/test_step_2/module_tests/test_module_gowitness.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from .base import ModuleTestBase


Expand Down Expand Up @@ -102,3 +104,33 @@ def check(self, module_test, events):
webscreenshots = [e for e in events if e.type == "WEBSCREENSHOT"]
assert webscreenshots, "failed to raise WEBSCREENSHOT events"
assert all("blob" in e.data and e.data["blob"] for e in webscreenshots), "blob not found in WEBSCREENSHOT data"


class TestGoWitnessLongFilename(TestGowitness):
"""
Make sure long filenames are truncated properly
"""

targets = [
"http://127.0.0.1:8888/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity"
]
config_overrides = {"file_blobs": True}

async def setup_after_prep(self, module_test):
request_args = {
"uri": "/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity/blacklanternsecurity"
}
respond_args = {
"response_data": "<html><head><title>BBOT is life</title></head><body>BBOT is life</body></html>",
"headers": {"Server": "Apache/2.4.41 (Ubuntu)"},
}
module_test.set_expect_requests(request_args, respond_args)

def check(self, module_test, events):
webscreenshots = [e for e in events if e.type == "WEBSCREENSHOT"]
assert webscreenshots, "failed to raise WEBSCREENSHOT events"
assert len(webscreenshots) == 1
webscreenshot = webscreenshots[0]
filename = Path(webscreenshot.data["path"])
# sadly this file doesn't exist because gowitness doesn't truncate properly
assert not filename.exists()
Loading