Subdomain Takeover

OWASP: WSTG-CONF-10

Theory

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.

Subdomains enumeration

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.

Subzy (Golang) is a subdomain takeover vulnerability checker which works based on matching response fingerprints from can-i-take-over-xyz.

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"

Subdomain Takeover

Identify Misconfigurations for Subdomains

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:

# -L: Follow redirect
# -v: Verbose mode
curl -Lv app.example.com
curl -v cloud.example.com
curl -v mail.example.com

Spoof with the Subdomain

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:

  1. Login the target provider.

  2. Create a malicious website.

  3. Add the target subdomain (e.g. app.example.com) as custom domain in the setting page.

  4. If users visit app.example.com, they have now visited a malicious website created by an attacker.

Resources

Last updated