Skip to content

Commit

Permalink
target tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 30, 2024
1 parent 9004e0b commit 892f490
Show file tree
Hide file tree
Showing 14 changed files with 337 additions and 3,578 deletions.
25 changes: 23 additions & 2 deletions bbot/core/event/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,21 @@ def host_original(self):
return self.host
return self._host_original

@property
def host_filterable(self):
"""
A string version of the event that's used for regex-based blacklisting.
For example, the user can specify "REGEX:.*.evilcorp.com" in their blacklist, and this regex
will be applied against this property.
"""
parsed_url = getattr(self, "parsed_url", None)
if parsed_url is not None:
return parsed_url.geturl()
if self.host is not None:
return str(self.host)
return ""

@property
def port(self):
self.host
Expand Down Expand Up @@ -1110,8 +1125,7 @@ def __init__(self, *args, **kwargs):
class IP_RANGE(DnsEvent):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
net = ipaddress.ip_network(self.data, strict=False)
self.add_tag(f"ipv{net.version}")
self.add_tag(f"ipv{self.host.version}")

def sanitize_data(self, data):
return str(ipaddress.ip_network(str(data), strict=False))
Expand Down Expand Up @@ -1667,6 +1681,13 @@ def make_event(
if event_type == "USERNAME" and validators.soft_validate(data, "email"):
event_type = "EMAIL_ADDRESS"
tags.add("affiliate")
# Convert single-host IP_RANGE to IP_ADDRESS
if event_type == "IP_RANGE":
with suppress(Exception):
net = ipaddress.ip_network(data, strict=False)
if net.prefixlen == net.max_prefixlen:
event_type = "IP_ADDRESS"
data = net.network_address

event_class = globals().get(event_type, DefaultEvent)

Expand Down
9 changes: 8 additions & 1 deletion bbot/core/helpers/bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ def _fnv1a_hash(self, data):
hash = (hash * 0x01000193) % 2**32 # 16777619
return hash

def __del__(self):
def close(self):
"""Explicitly close the memory-mapped file."""
self.mmap_file.close()

def __del__(self):
try:
self.close()
except Exception:
pass

def __contains__(self, item):
return self.check(item)
4 changes: 2 additions & 2 deletions bbot/core/helpers/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import multiprocessing as mp
from functools import partial
from radixtarget import RadixTarget
from concurrent.futures import ProcessPoolExecutor

from . import misc
Expand All @@ -12,7 +13,6 @@
from .regex import RegexHelper
from .wordcloud import WordCloud
from .interactsh import Interactsh
from ...scanner.target import Target
from .depsinstaller import DepsInstaller
from .async_helpers import get_event_loop

Expand Down Expand Up @@ -156,7 +156,7 @@ def clean_old_scans(self):
self.clean_old(self.scans_dir, keep=self.keep_old_scans, filter=_filter)

def make_target(self, *events, **kwargs):
return Target(*events, **kwargs)
return RadixTarget(*events, **kwargs)

@property
def config(self):
Expand Down
2 changes: 1 addition & 1 deletion bbot/core/helpers/web/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, parent_helper):
self.ssl_verify = self.config.get("ssl_verify", False)
engine_debug = self.config.get("engine", {}).get("debug", False)
super().__init__(
server_kwargs={"config": self.config, "target": self.parent_helper.preset.target.radix_only},
server_kwargs={"config": self.config, "target": self.parent_helper.preset.target.minimal},
debug=engine_debug,
)

Expand Down
1 change: 0 additions & 1 deletion bbot/scanner/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ async def init_events(self, events=None):
event.parent = self.scan.root_event
if event.module is None:
event.module = self.scan._make_dummy_module(name="TARGET", _type="TARGET")
event.add_tag("target")
if event != self.scan.root_event:
event.discovery_context = f"Scan {self.scan.name} seeded with " + "{event.type}: {event.data}"
self.verbose(f"Target: {event}")
Expand Down
6 changes: 6 additions & 0 deletions bbot/scanner/preset/preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ def target(self):
raise ValueError("Cannot access target before preset is baked (use ._seeds instead)")
return self._target

@property
def seeds(self):
if self._seeds is None:
raise ValueError("Cannot access target before preset is baked (use ._seeds instead)")
return self.target.seeds

@property
def whitelist(self):
if self._target is None:
Expand Down
8 changes: 6 additions & 2 deletions bbot/scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ async def _prep(self):
f.write(self.preset.to_yaml())

# log scan overview
start_msg = f"Scan with {len(self.preset.scan_modules):,} modules seeded with {len(self.target):,} targets"
start_msg = f"Scan with {len(self.preset.scan_modules):,} modules seeded with {len(self.seeds):,} targets"
details = []
if self.whitelist != self.target:
details.append(f"{len(self.whitelist):,} in whitelist")
Expand Down Expand Up @@ -359,7 +359,7 @@ async def async_start(self):

# distribute seed events
self.init_events_task = asyncio.create_task(
self.ingress_module.init_events(self.target.events), name=f"{self.name}.ingress_module.init_events()"
self.ingress_module.init_events(self.target.seeds.events), name=f"{self.name}.ingress_module.init_events()"
)

# main scan loop
Expand Down Expand Up @@ -893,6 +893,10 @@ def config(self):
def target(self):
return self.preset.target

@property
def seeds(self):
return self.preset.seeds

@property
def whitelist(self):
return self.preset.whitelist
Expand Down
Loading

0 comments on commit 892f490

Please sign in to comment.