Skip to content

Commit

Permalink
misc bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Dec 17, 2024
1 parent 05110e4 commit 9b755e4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
4 changes: 1 addition & 3 deletions bbot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ async def akeyboard_listen():
finally:
# save word cloud
with suppress(BaseException):
save_success, filename = scan.helpers.word_cloud.save()
if save_success:
log_to_stderr(f"Saved word cloud ({len(scan.helpers.word_cloud):,} words) to {filename}")
scan.helpers.word_cloud.save()
# remove output directory if empty
with suppress(BaseException):
scan.home.rmdir()
Expand Down
6 changes: 5 additions & 1 deletion bbot/modules/output/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

class MySQL(SQLTemplate):
watched_events = ["*"]
meta = {"description": "Output scan data to a MySQL database", "created_date": "2024-11-13", "author": "@TheTechromancer"}
meta = {
"description": "Output scan data to a MySQL database",
"created_date": "2024-11-13",
"author": "@TheTechromancer",
}
options = {
"username": "root",
"password": "bbotislife",
Expand Down
17 changes: 11 additions & 6 deletions bbot/scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(
self.duration_seconds = None

self._success = False
self._scan_finish_status_message = None

if scan_id is not None:
self.id = str(scan_id)
Expand Down Expand Up @@ -425,14 +426,19 @@ async def async_start(self):

self._stop_log_handlers()

if self._scan_finish_status_message:
log_fn = self.hugesuccess
if self.status.startswith("ABORT"):
log_fn = self.hugewarning
elif not self._success:
log_fn = self.critical
log_fn(self._scan_finish_status_message)

async def _mark_finished(self):
log_fn = self.hugesuccess
if self.status == "ABORTING":
status = "ABORTED"
log_fn = self.hugewarning
elif not self._success:
status = "FAILED"
log_fn = self.critical
else:
status = "FINISHED"

Expand All @@ -441,9 +447,9 @@ async def _mark_finished(self):
self.duration_seconds = self.duration.total_seconds()
self.duration_human = self.helpers.human_timedelta(self.duration)

status_message = f"Scan {self.name} completed in {self.duration_human} with status {status}"
self._scan_finish_status_message = f"Scan {self.name} completed in {self.duration_human} with status {status}"

scan_finish_event = self.finish_event(status_message, status)
scan_finish_event = self.finish_event(self._scan_finish_status_message, status)

# queue final scan event with output modules
output_modules = [m for m in self.modules.values() if m._type == "output" and m.name != "python"]
Expand All @@ -457,7 +463,6 @@ async def _mark_finished(self):
await asyncio.sleep(0.05)

self.status = status
log_fn(status_message)
return scan_finish_event

def _start_modules(self):
Expand Down
2 changes: 1 addition & 1 deletion bbot/scanner/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def add(self, targets):
events.add(event)

# sort by host size to ensure consistency
events = sorted(events, key=lambda e: (0 if not e.host else host_size_key(e.host)))
events = sorted(events, key=lambda e: ((0, 0) if not e.host else host_size_key(e.host)))
for event in events:
self.events.add(event)
self._add(event.host, data=event)
Expand Down
13 changes: 12 additions & 1 deletion bbot/test/test_step_1/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


@pytest.mark.asyncio
async def test_target(bbot_scanner):
async def test_target_basic(bbot_scanner):
from radixtarget import RadixTarget
from ipaddress import ip_address, ip_network
from bbot.scanner.target import BBOTTarget, ScanSeeds
Expand Down Expand Up @@ -245,6 +245,17 @@ async def test_target(bbot_scanner):
assert len(events) == 3
assert {e.type for e in events} == {"SCAN", "USERNAME"}

# users + orgs + domains
scan = bbot_scanner("USER:evilcorp", "ORG:evilcorp", "evilcorp.com")
await scan.helpers.dns._mock_dns(
{
"evilcorp.com": {"A": ["1.2.3.4"]},
},
)
events = [e async for e in scan.async_start()]
assert len(events) == 5
assert {e.type for e in events} == {"SCAN", "USERNAME", "ORG_STUB", "DNS_NAME"}

# verify hash values
bbottarget = BBOTTarget(
"1.2.3.0/24",
Expand Down

0 comments on commit 9b755e4

Please sign in to comment.