-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b62645
commit 45df5ae
Showing
10 changed files
with
89 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from bbot.modules.base import BaseModule | ||
import xml.etree.ElementTree as ET | ||
|
||
|
||
class bucket_file_enum(BaseModule): | ||
""" | ||
Enumerate files in a public bucket | ||
""" | ||
|
||
watched_events = ["STORAGE_BUCKET"] | ||
produced_events = ["URL_UNVERIFIED"] | ||
meta = { | ||
"description": "Works in conjunction with the filedownload module to download files from open storage buckets. Currently supported cloud providers: AWS" | ||
} | ||
flags = ["passive", "safe", "cloud-enum"] | ||
scope_distance_modifier = 2 | ||
|
||
async def handle_event(self, event): | ||
cloud_tags = (t for t in event.tags if t.startswith("cloud-")) | ||
if any(t.endswith("-amazon") or t.endswith("-digitalocean") for t in cloud_tags): | ||
await self.handle_aws(event) | ||
|
||
async def handle_aws(self, event): | ||
url = event.data["url"] | ||
response = await self.helpers.request(url) | ||
status_code = getattr(response, "status_code", 0) | ||
if status_code == 200: | ||
content = response.text | ||
root = ET.fromstring(content) | ||
namespace = {"s3": "http://s3.amazonaws.com/doc/2006-03-01/"} | ||
keys = [key.text for key in root.findall(".//s3:Key", namespace)] | ||
for key in keys: | ||
bucket_file = url + "/" + key | ||
self.emit_event(bucket_file, "URL_UNVERIFIED", source=event, tags="filedownload") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
bbot/test/test_step_2/module_tests/test_module_bucket_file_enum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from .base import ModuleTestBase | ||
|
||
|
||
class TestBucket_File_Enum(ModuleTestBase): | ||
targets = ["http://127.0.0.1:8888"] | ||
modules_overrides = ["bucket_file_enum", "filedownload", "httpx", "excavate"] | ||
|
||
open_bucket_url = "https://testbucket.s3.amazonaws.com/" | ||
open_bucket_body = """<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>testbucket</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>index.html</Key><LastModified>2023-05-22T23:04:38.000Z</LastModified><ETag>"4a2d2d114f3abf90f8bd127c1f25095a"</ETag><Size>5</Size><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>test.pdf</Key><LastModified>2022-04-30T21:13:40.000Z</LastModified><ETag>"723b0018c2f5a7ef06a34f84f6fa97e4"</ETag><Size>388901</Size><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>""" | ||
|
||
pdf_data = """%PDF-1. | ||
1 0 obj<</Pages 2 0 R>>endobj | ||
2 0 obj<</Kids[3 0 R]/Count 1>>endobj | ||
3 0 obj<</Parent 2 0 R>>endobj | ||
trailer <</Root 1 0 R>>""" | ||
|
||
async def setup_before_prep(self, module_test): | ||
module_test.httpserver.expect_request("/").respond_with_data(f'<a href="{self.open_bucket_url}"/>') | ||
module_test.httpx_mock.add_response( | ||
url=self.open_bucket_url, | ||
text=self.open_bucket_body, | ||
) | ||
module_test.httpx_mock.add_response( | ||
url=f"{self.open_bucket_url}test.pdf", | ||
text=self.pdf_data, | ||
headers={"Content-Type": "application/pdf"}, | ||
) | ||
|
||
def check(self, module_test, events): | ||
download_dir = module_test.scan.home / "filedownload" | ||
files = list(download_dir.glob("*.pdf")) | ||
assert any(f.name.endswith("test.pdf") for f in files), "Failed to download PDF file from open bucket" |