-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from blacklanternsecurity/dev
Push new tests to main
- Loading branch information
Showing
9 changed files
with
380 additions
and
261 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 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
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
from baddns.modules.nsec import BadDNS_nsec | ||
from .helpers import mock_signature_load | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_nsec_match(fs, mock_dispatch_whois, configure_mock_resolver): | ||
mock_data = { | ||
"bad.dns": {"NSEC": ["asdf.bad.dns"]}, | ||
"asdf.bad.dns": {"NSEC": ["zzzz.bad.dns"]}, | ||
"zzzz.bad.dns": {"NSEC": ["xyz.bad.dns"]}, | ||
} | ||
mock_resolver = configure_mock_resolver(mock_data) | ||
target = "bad.dns" | ||
mock_signature_load(fs, "nucleitemplates_azure-takeover-detection.yml") | ||
|
||
baddns_nsec = BadDNS_nsec(target, signatures_dir="/tmp/signatures", dns_client=mock_resolver) | ||
|
||
findings = None | ||
if await baddns_nsec.dispatch(): | ||
findings = baddns_nsec.analyze() | ||
|
||
assert findings | ||
expected = { | ||
"target": "bad.dns", | ||
"description": "DNSSEC NSEC Zone Walking Enabled for domain: [bad.dns]", | ||
"confidence": "CONFIRMED", | ||
"signature": "N/A", | ||
"indicator": "NSEC Records", | ||
"trigger": "bad.dns", | ||
"module": "NSEC", | ||
"found_domains": ["bad.dns", "asdf.bad.dns", "zzzz.bad.dns", "xyz.bad.dns"], | ||
} | ||
assert any(expected == finding.to_dict() for finding in findings) |
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,29 @@ | ||
import pytest | ||
from baddns.modules.txt import BadDNS_txt | ||
from .helpers import mock_signature_load | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_txt_match(fs, mock_dispatch_whois, configure_mock_resolver): | ||
mock_data = {"bad.dns": {"TXT": ["baddns.azurewebsites.net"]}, "_NXDOMAIN": ["baddns.azurewebsites.net"]} | ||
mock_resolver = configure_mock_resolver(mock_data) | ||
target = "bad.dns" | ||
mock_signature_load(fs, "nucleitemplates_azure-takeover-detection.yml") | ||
|
||
baddns_txt = BadDNS_txt(target, signatures_dir="/tmp/signatures", dns_client=mock_resolver) | ||
|
||
findings = None | ||
if await baddns_txt.dispatch(): | ||
findings = baddns_txt.analyze() | ||
|
||
assert findings | ||
expected = { | ||
"target": "bad.dns", | ||
"description": "Vulnerable Host in TXT Record. Original Event: [Dangling CNAME, probable subdomain takeover (NXDOMAIN technique)]", | ||
"confidence": "PROBABLE", | ||
"signature": "Microsoft Azure Takeover Detection", | ||
"indicator": "azurewebsites.net", | ||
"trigger": "bad.dns", | ||
"module": "TXT", | ||
} | ||
assert any(expected == finding.to_dict() for finding in findings) |
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,51 @@ | ||
import pytest | ||
import dns | ||
|
||
|
||
from baddns.modules.zonetransfer import BadDNS_zonetransfer | ||
from .helpers import mock_signature_load | ||
|
||
|
||
def from_xfr(*args, **kwargs): | ||
zone_text = """ | ||
@ 600 IN SOA ns.bad.dns. admin.bad.dns. ( | ||
1 ; Serial | ||
3600 ; Refresh | ||
900 ; Retry | ||
604800 ; Expire | ||
86400 ) ; Minimum TTL | ||
@ 600 IN NS ns.bad.dns. | ||
@ 600 IN A 127.0.0.1 | ||
asdf 600 IN A 127.0.0.1 | ||
zzzz 600 IN AAAA dead::beef | ||
""" | ||
zone = dns.zone.from_text(zone_text, origin="blacklanternsecurity.fakedomain.") | ||
return zone | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_zonetransfer_discovery(fs, configure_mock_resolver, monkeypatch): | ||
mock_signature_load(fs, "nucleitemplates_azure-takeover-detection.yml") | ||
mock_data = {"bad.dns": {"NS": ["ns1.bad.dns."]}, "ns1.bad.dns": {"A": ["127.0.0.1"]}} | ||
mock_resolver = configure_mock_resolver(mock_data) | ||
target = "bad.dns" | ||
baddns_zonetransfer = BadDNS_zonetransfer(target, signatures_dir="/tmp/signatures", dns_client=mock_resolver) | ||
|
||
monkeypatch.setattr("dns.zone.from_xfr", from_xfr) | ||
|
||
findings = None | ||
if await baddns_zonetransfer.dispatch(): | ||
findings = baddns_zonetransfer.analyze() | ||
|
||
assert findings | ||
expected = { | ||
"target": "bad.dns", | ||
"description": "Successful Zone Transfer", | ||
"confidence": "CONFIRMED", | ||
"signature": "N/A", | ||
"indicator": "Successful XFR Request", | ||
"trigger": "ns1.bad.dns", | ||
"module": "zonetransfer", | ||
"found_domains": ["bad.dns", "asdf.bad.dns", "zzzz.bad.dns"], | ||
} | ||
assert any(expected == finding.to_dict() for finding in findings) |