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

Add Baddns Module #1037

Merged
merged 46 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8b112c9
baddns module initial (kindof)
liquidsec Jan 18, 2024
4facff8
typo fix
liquidsec Jan 18, 2024
3cc4b75
Merge branch 'dev' into baddns_module
liquidsec Jan 25, 2024
bd24007
adding MockResolver, baddns tests
liquidsec Jan 26, 2024
f480848
The goodest boy
liquidsec Jan 29, 2024
a9b7255
test adjustments
liquidsec Jan 29, 2024
416e825
Merge branch 'dev' into baddns_module
liquidsec Jan 29, 2024
733e2f8
misc cleanup
liquidsec Jan 29, 2024
610a69e
black
liquidsec Jan 29, 2024
4395377
Merge branch 'dev' into baddns_module
liquidsec Jan 29, 2024
11bf572
black
liquidsec Jan 29, 2024
d4c4cf9
add baddns_zone module
liquidsec Jan 29, 2024
7a340d1
disambiguating test imports
liquidsec Jan 29, 2024
849cb14
fixing import short-circuit
liquidsec Jan 29, 2024
f824ac5
removing deprecated modules
liquidsec Jan 29, 2024
5564276
adjusting baddns meta attributes
liquidsec Jan 29, 2024
05e20ca
you got me Joel
liquidsec Jan 29, 2024
470be4c
baddns meta adjustment
liquidsec Jan 29, 2024
13d9582
typo
liquidsec Jan 29, 2024
6d2584f
Merge branch 'dev' into baddns_module
liquidsec Jan 29, 2024
334d3fa
fixing poetry
liquidsec Jan 29, 2024
8c39aee
forcing version of baddns to fix horrible dependency nightmare
liquidsec Jan 29, 2024
697ef7d
bumping baddns version again
liquidsec Jan 29, 2024
9722389
bumping baddns version to ensure python 3.12 compatability
liquidsec Feb 5, 2024
b3bfd1a
rolling version numbers again for python 3.12 fix
liquidsec Feb 5, 2024
a4004c3
Merge branch 'dev' into baddns_module
liquidsec Feb 6, 2024
caf444f
performance increases using async tasks
liquidsec Feb 6, 2024
22823db
dns mock cleanup
TheTechromancer Jan 30, 2024
5a63b73
fix dnscommonsrv tests
TheTechromancer Jan 31, 2024
ae7e41f
fix tests
TheTechromancer Feb 1, 2024
652b233
fix PTR tests
TheTechromancer Feb 1, 2024
e5d88dc
fix aggregate tests
TheTechromancer Feb 1, 2024
5f8d266
fix speculate tests
TheTechromancer Feb 1, 2024
0bcf77f
normalizing tag names
liquidsec Feb 7, 2024
fa6be6e
baddns version roll
liquidsec Feb 7, 2024
ba9236a
fixing bug with tag name
liquidsec Feb 7, 2024
0097506
black
liquidsec Feb 8, 2024
500930a
Merge branch 'baddns_module' into mock-dns-cleanup
TheTechromancer Feb 8, 2024
036b1d7
Merge pull request #1043 from blacklanternsecurity/mock-dns-cleanup
liquidsec Feb 8, 2024
6108dfe
Merge branch 'dev' into baddns_module
liquidsec Feb 8, 2024
b627499
actually bumping version
liquidsec Feb 8, 2024
0f56b09
\!actually\! bumping version :D
liquidsec Feb 8, 2024
8709d6a
baddns_zone version
liquidsec Feb 8, 2024
25faf8c
Merge branch 'dev' into baddns_module
liquidsec Feb 14, 2024
bc57ab5
Merge branch 'dev' into baddns_module
liquidsec Feb 20, 2024
59a1f68
Merge branch 'dev' into baddns_module
liquidsec Feb 21, 2024
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
1 change: 1 addition & 0 deletions bbot/core/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"active": "Makes active connections to target systems",
"affiliates": "Discovers affiliated hostnames/domains",
"aggressive": "Generates a large amount of network traffic",
"baddns": "Runs all modules from the DNS auditing tool BadDNS",
"cloud-enum": "Enumerates cloud resources",
"deadly": "Highly aggressive",
"email-enum": "Enumerates email addresses",
Expand Down
25 changes: 0 additions & 25 deletions bbot/core/helpers/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,28 +1025,3 @@ def _get_dummy_module(self, name):
dummy_module.suppress_dupes = False
self._dummy_modules[name] = dummy_module
return dummy_module

def mock_dns(self, dns_dict):
if self._orig_resolve_raw is None:
self._orig_resolve_raw = self.resolve_raw

async def mock_resolve_raw(query, **kwargs):
results = []
errors = []
types = self._parse_rdtype(kwargs.get("type", ["A", "AAAA"]))
for t in types:
with suppress(KeyError):
results += self._mock_table[(query, t)]
return results, errors

for (query, rdtype), answers in dns_dict.items():
if isinstance(answers, str):
answers = [answers]
for answer in answers:
rdata = dns.rdata.from_text("IN", rdtype, answer)
try:
self._mock_table[(query, rdtype)].append((rdtype, rdata))
except KeyError:
self._mock_table[(query, rdtype)] = [(rdtype, [rdata])]

self.resolve_raw = mock_resolve_raw
2 changes: 2 additions & 0 deletions bbot/core/helpers/names_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"giddy",
"glowering",
"glutinous",
"golden",
"gothic",
"grievous",
"gummy",
Expand Down Expand Up @@ -431,6 +432,7 @@
"gollum",
"grace",
"gregory",
"gus",
"hagrid",
"hannah",
"harold",
Expand Down
86 changes: 86 additions & 0 deletions bbot/modules/baddns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from baddns.base import get_all_modules
from baddns.lib.loader import load_signatures
from .base import BaseModule

import asyncio
import logging
from bbot.core.logger.logger import include_logger

include_logger(logging.getLogger("baddns"))


class baddns(BaseModule):
watched_events = ["DNS_NAME", "DNS_NAME_UNRESOLVED"]
produced_events = ["FINDING", "VULNERABILITY"]
flags = ["active", "safe", "web-basic", "baddns", "cloud-enum", "subdomain-hijack"]
meta = {"description": "Check hosts for domain/subdomain takeovers"}
options = {"custom_nameservers": [], "only_high_confidence": False}
options_desc = {
"custom_nameservers": "Force BadDNS to use a list of custom nameservers",
"only_high_confidence": "Do not emit low-confidence or generic detections",
}
max_event_handlers = 8
deps_pip = ["baddns~=1.1.0"]

def select_modules(self):
selected_modules = []
for m in get_all_modules():
if m.name in ["CNAME", "NS", "MX", "references", "TXT"]:
selected_modules.append(m)
return selected_modules

async def setup(self):
self.custom_nameservers = self.config.get("custom_nameservers", []) or None
if self.custom_nameservers:
self.custom_nameservers = self.helpers.chain_lists(self.custom_nameservers)
self.only_high_confidence = self.config.get("only_high_confidence", False)
self.signatures = load_signatures()
return True

async def handle_event(self, event):

tasks = []
for ModuleClass in self.select_modules():
module_instance = ModuleClass(
event.data,
http_client_class=self.scan.helpers.web.AsyncClient,
dns_client=self.scan.helpers.dns.resolver,
custom_nameservers=self.custom_nameservers,
signatures=self.signatures,
)
tasks.append((module_instance, asyncio.create_task(module_instance.dispatch())))

for module_instance, task in tasks:
if await task:
results = module_instance.analyze()
if results and len(results) > 0:
for r in results:
r_dict = r.to_dict()

if r_dict["confidence"] in ["CONFIRMED", "PROBABLE"]:
data = {
"severity": "MEDIUM",
"description": f"{r_dict['description']}. Confidence: [{r_dict['confidence']}] Signature: [{r_dict['signature']}] Indicator: [{r_dict['indicator']}] Trigger: [{r_dict['trigger']}] baddns Module: [{r_dict['module']}]",
"host": str(event.host),
}
await self.emit_event(
data, "VULNERABILITY", event, tags=[f"baddns-{module_instance.name.lower()}"]
)

elif r_dict["confidence"] in ["UNLIKELY", "POSSIBLE"] and not self.only_high_confidence:
data = {
"description": f"{r_dict['description']} Confidence: [{r_dict['confidence']}] Signature: [{r_dict['signature']}] Indicator: [{r_dict['indicator']}] Trigger: [{r_dict['trigger']}] baddns Module: [{r_dict['module']}]",
"host": str(event.host),
}
await self.emit_event(
data, "FINDING", event, tags=[f"baddns-{module_instance.name.lower()}"]
)
else:
self.warning(f"Got unrecognized confidence level: {r['confidence']}")

found_domains = r_dict.get("found_domains", None)
if found_domains:
for found_domain in found_domains:
await self.emit_event(
found_domain, "DNS_NAME", event, tags=[f"baddns-{module_instance.name.lower()}"]
)
34 changes: 34 additions & 0 deletions bbot/modules/baddns_zone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from baddns.base import get_all_modules
from .baddns import baddns as baddns_module

import logging
from bbot.core.logger.logger import include_logger

include_logger(logging.getLogger("baddns_zone"))


class baddns_zone(baddns_module):
watched_events = ["DNS_NAME"]
produced_events = ["FINDING", "VULNERABILITY"]
flags = ["active", "safe", "subdomain-enum", "baddns", "cloud-enum"]
meta = {"description": "Check hosts for DNS zone transfers and NSEC walks"}
options = {"custom_nameservers": [], "only_high_confidence": False}
options_desc = {
"custom_nameservers": "Force BadDNS to use a list of custom nameservers",
"only_high_confidence": "Do not emit low-confidence or generic detections",
}
max_event_handlers = 8
deps_pip = ["baddns~=1.1.0"]

def select_modules(self):
selected_modules = []
for m in get_all_modules():
if m.name in ["NSEC", "zonetransfer"]:
selected_modules.append(m)
return selected_modules

# minimize nsec records feeding back into themselves
async def filter_event(self, event):
if "baddns-nsec" in event.tags or "baddns-nsec" in event.source.tags:
return False
return True
70 changes: 0 additions & 70 deletions bbot/modules/dnszonetransfer.py

This file was deleted.

46 changes: 0 additions & 46 deletions bbot/modules/nsec.py

This file was deleted.

Loading
Loading