Skip to content

DNS Finder

The functions of dns_finder.core, taken from their docstrings.

dns_finder.core

invalidate_monitored_cache(**kwargs)

Forget the cached monitored domains and keywords (also used as a signal receiver).

get_monitored()

Monitored corporate domains and keywords, cached for MONITORED_CACHE_TTL seconds.

Returns:

Type Description

((id, domain_name), ...) and ((id, name), ...) (Tuple of tuples).

start_scheduler()

Schedule the jobs: dnstwist every 2 hours, CertStream every hour, the dangling-subdomain recheck every 6 hours.

in_dns_monitored(domain)

Check if domain is a subdomain of one domain of the DnsMonitored list.

Parameters:

Name Type Description Default
domain

Domain to search (Str).

required

is_legitimate_domain(domain)

Check if domain or its parent domain is in the Legitimate Domains list.

Parameters:

Name Type Description Default
domain

Domain to check (Str).

required

clean_wildcard_domain(domain)

Remove leading *. from domain names.

extract_certificate_metadata(message)

Issuer and SAN of a CertStream certificate_update message. Every field is read defensively: a different payload omits data, never raises.

Parameters:

Name Type Description Default
message

CertStream event (Dict).

required

load_dangling_fingerprints()

Load (and cache) the dangling-DNS provider fingerprint list.

match_fingerprint(cname_target)

Find the fingerprint entry whose cname_pattern is contained in cname_target.

Parameters:

Name Type Description Default
cname_target

Terminal CNAME hostname (Str) or None.

required

resolve_cname_chain(subdomain, max_hops=5)

Follow the CNAME chain for a subdomain up to max_hops, returning the terminal target hostname, or None if there is no CNAME record.

Parameters:

Name Type Description Default
subdomain

Subdomain to resolve (Str).

required
max_hops

Maximum CNAME hops to follow (Int).

5

check_dangling_status(dns_twisted)

Resolve a DnsTwisted row's CNAME chain, match it against known takeover-able provider fingerprints, and confirm via DNS/HTTP. Updates the DnsTwisted row's technical probe fields in place.

Parameters:

Name Type Description Default
dns_twisted

DnsTwisted Object.

required

Returns:

Type Description

The raw probe verdict: 'ok', 'dangling_suspected', or 'dangling_confirmed' (Str).

evaluate_dangling_subdomain(dns_twisted, source)

Run check_dangling_status and create or update the subdomain_takeover Alert of the domain.

Notifies on the first verdict ('pending' to 'suspected') and when the status becomes 'confirmed', not again for a flapping subdomain.

Parameters:

Name Type Description Default
dns_twisted

DnsTwisted Object.

required
source

'certstream' or 'periodic_recheck' (Str).

required

track_dangling_subdomain(domain)

Catalog a subdomain of a monitored root domain for dangling-DNS tracking (a DnsTwisted row and its Alert).

Nothing is probed here: the CertStream callback has no queue, so blocking it would drop certificates. The recheck job verifies the 'pending' rows. The suffix check is strict (not a substring) because this writes rows.

Parameters:

Name Type Description Default
domain

Domain from a CertStream event (Str).

required

recheck_dangling_subdomains()

Re-check every subdomain_takeover Alert that hasn't been triaged as resolved/false_positive, to catch takeovers that appear long after the subdomain was first discovered.

check_threats_with_suspicious()

Ask Suspicious, the phishing analysis platform, whether the recent threats were already judged in a reported phishing.

certificate_domains(message)

Domains a certificate is about: its CN, or its SAN list when it has none (multi-tenant certificates list hundreds of unrelated SANs). Lowercased, without the leading *..

Parameters:

Name Type Description Default
message

CertStream event (Dict).

required

certstream_paused()

The pause of the connector, looked up at most every 5 seconds: the stream is one message after another.

print_callback(message, context)

Runs CertStream scan.

Parameters:

Name Type Description Default
message

event from CertStream.

required
context

parameter from CertStream.

required

scan_certificate_domain(message, domain, keywords)

Check one domain of a certificate against the monitored keywords and alert on a match.

Parameters:

Name Type Description Default
message

event from CertStream (Dict).

required
domain

Domain to check (Str).

required
keywords

Monitored keywords, as (id, name) tuples (see get_monitored).

required

main_certificate_transparency()

Launch CertStream scan using internal certstream-server-go.

main_dns_twist()

Launch dnstwist algorithm.

check_dnstwist(dns_monitored)

Runs dnstwist.

Parameters:

Name Type Description Default
dns_monitored

DnsMonitored Object.

required

Returns:

Type Description

send_dns_finder_notifications(alert)

Notify a DNS Threats alert on Slack, Citadel, TheHive and e-mail: the first three follow the Notifications tab, the e-mail goes to the subscribers who ticked it. A subdomain_takeover alert uses the 'dns_finder_dangling' notification.

Parameters:

Name Type Description Default
alert

Alert Object.

required

send_dns_finder_notifications_group(dns_monitored, alerts_number, alerts)

Sends grouped notifications to Slack, Citadel, TheHive or Email based on dns_finder_group. If the application is TheHive, individual notifications are sent for each alert.

Parameters:

Name Type Description Default
dns_monitored

The DNS Threats Monitored (the domain or keyword the alerts are about).

required
alerts_number

The total number of alerts in the group.

required
alerts

The list of individual alerts to be processed and sent to TheHive.

required