A subdomain takeover occurs when an attacker gains control over a subdomain of a target domain. Typically, this happens when the victim’s external DNS server subdomain record is configured to point to a non-existing or non-active resource/external service/endpoint.
If the subdomain takeover is successful, a wide variety of attacks are possible (serving malicious content, phishing, stealing user session cookies, credentials, etc.). This vulnerability could be exploited for a wide variety of DNS resource records including: A, CNAME, MX, NS, TXT etc. In terms of the attack severity, an NS subdomain takeover (although less likely) has the highest impact, because a successful attack could result in full control over the whole DNS zone and the victim’s domain.
Practice
Enumerate
Before attempting a domain or subdomain takeover, it's crucial to enumerate all subdomains associated with the target domain. Refer to the below section for comprehensive techniques and tools.
Scanning for Subdomain Takeover
After enumerating subdomains, we can use these tools to perform a Subdomain Takeover scan and detect any subdomains that might be vulnerable.
(Golang) is a subdomain takeover vulnerability checker which works based on matching response fingerprints from .
We can use this tools and scan for each subdomain discovered.
# Scan a list of subdomains
subzy run --targets domains.txt
# Scan for a single subdomain
subzy run --target test.example.com
# One-liner: find subdmains + scan for domain takeover
echo 'example.com'|(subfinder -all||assetfinder -subs-only)|uniq -u > domains.txt;subzy r --targets domains.txt | sed 's/\x1b\[[0-9;]*m//g' |grep -iE -A 2 "\[ VULNERABLE"
We may use for checking HTTP response status for each subdomain discovered.
# -title: Display page title
# -wc: Display response body word count
# -sc: Display response status-code
# -cl: Display response content-length
# -ct: Display response content-type
# -location: Display response redirect location
# -web-server: Display server name
# -asn: Display host ASN information
# -o: Output
cat domains.txt | httpx -title -wc -sc -cl -ct -location -web-server -asn -o alive-subdomains.txt
# Resume Scan (-resume)
# You can resume the scan using `resume.cfg`.
cat domains.txt | httpx -title -wc -sc -cl -ct -location -web-server -asn -o alive-subdomains.txt -resume resume.cfg
The, we can then check for error codes 404 and check on if the provider allows us to register subdomains.
# Scan a list of subdomains
python3 takeover.py -l domains.txt
# From list
python3 subdover.py -l domains.txt
# Single domain (will scan for subdomains using findomain)
python3 subdover.py -d example.com
SubOver -l domains.txt
MX domains that will expire soon
Unregistered MX domains
Domains that points to not currently in use by mailgun.
First, check DNS records for identifying what’s on the destination of the subdomain.
dig sub.example.com ANY
dig sub.example.com CNAME
If the HEADER status is NXDOMAIN error in the result, subdomain takeover might be possible.
Also we can try to access them with web browser or command-line:
If a certain subdomain can be accessible but the error page of the specific provider (e.g. GitHub, Google Cloud, Wix, etc.) appeared, it means that the subdomain of the settings in the service provider was removed but the DNS record (e.g. A, CNAME) remains yet.
In short, attackers can spoof as a legitimate site by claiming this subdomain in the provider.
Here’s an abstract example:
Login the target provider.
Create a malicious website.
Add the target subdomain (e.g. app.example.com) as custom domain in the setting page.
If users visit app.example.com, they have now visited a malicious website created by an attacker.
It’s more dangerous If NS record is vulnerable because if the nameserver is taken over, an attacker can take full control of victim’s domains.
To gather NS records for the target domain, use dig command.
dig example.com +short NS
# Result examples
ns-100.abcde.org
ns-120.abcde.co.uk
Next, check if the gathered domains can be purchased with domain name registrar like GoDaddy, NameCheap.
For example, search [abcde.org](http://abcde.org) in the domain search page of NameCheap. If this domain can be purchased, attackers can buy this domain then take control the name resolution of a victim by creating the custom nameserver which pointed to this domain.
When DNS wildcard is used in a domain, any requested subdomain of that domain that doesn't have a different address explicitly will be resolved to the same information. This could be an A ip address, a CNAME...
For example, if *.testing.com is wildcarded to 1.1.1.1. Then, not-existent.testing.com will be pointing to 1.1.1.1.
However, if instead of pointing to an IP address, the sysadmin points it to a third party service via CNAME, like a Github subdomain for example (sohomdatta1.github.io). An attacker could create his own third party page (in Gihub in this case) and say that something.testing.com is pointing there. Because, the CNAME wildcard will agree the attacker will be able to generate arbitrary subdomains for the domain of the victim pointing to his pages.
Resources
(python) is a subdomain takeover vulnerability checker.
(python) is a subdomain takeover vulnerability scanner, which has more than 88+ fingerprints of potentially vulnerable services.
(Golang) can be used to detect potential subdomain takeovers by checking a list of subdomains.
focuses DNS MX records and detects misconfigured MX records. It currently support three technique. These are,
You can find an example of this vulnerability in the CTF write-up: