Of course. Here is a comprehensive guide on how to find subdomain takeover vulnerabilities, structured for clarity from concept to execution.
Disclaimer
This information is for educational purposes and for security professionals testing systems they have explicit, written permission to test (e.g., on a bug bounty program or a penetration test engagement). Unauthorized scanning or exploitation of systems is illegal.
1. What is a Subdomain Takeover?
A subdomain takeover is a vulnerability where an attacker gains control over a company's subdomain. This happens when a subdomain's DNS record (usually a CNAME) points to a third-party service (like AWS S3, Heroku, GitHub Pages, etc.), but the resource on that service has been de-provisioned, deleted, or expired.
Since the DNS entry still points to the service, an attacker can go to that third-party service, claim the abandoned resource name (e.g., create a new S3 bucket with the same name), and effectively control the content served on the original subdomain.
Analogy: Imagine a company rents a storefront at 123 Main Street and puts up a big sign pointing to it. Later, they stop paying rent and move out, but they forget to take down the sign. An attacker can now go and rent the same storefront at 123 Main Street and benefit from the old company's sign, which is still directing customers there.
The Sign: The DNS CNAME record (blog.company.com)
The Address: The third-party service alias (company-blog.herokuapp.com)
The Storefront: The resource on the third-party service (the Heroku app)
2. The Step-by-Step Methodology
Finding a subdomain takeover vulnerability involves a systematic process.
Step 1: Subdomain Enumeration
You can't take over a subdomain if you don't know it exists. The first step is to find as many subdomains as possible for your target domain (example.com).
Popular Tools for Subdomain Enumeration:
subfinder: A fast and powerful passive subdomain discovery tool.
bash
subfinder -d example.com -o subdomains.txt
amass: A more in-depth tool that uses both passive techniques (scraping data sources) and active techniques (brute-forcing, DNS zone transfers).
Online Services: crt.sh, VirusTotal, SecurityTrails can also be used to find subdomains.
You should now have a file, subdomains.txt, containing a list of potential subdomains.
Step 2: Identify CNAME Records
The most common vector for takeovers is a CNAME record. You need to resolve all the subdomains you found and check if they point to an external service.
You can use a tool like massdns for resolving a large list of domains quickly, or dig for individual checks.
Example with dig:
bash
dig CNAME blog.example.com
Vulnerable-looking Output:
code
;; ANSWER SECTION:
blog.example.com. 300 IN CNAME example-blog.github.io.
Here, blog.example.com points to a GitHub Pages address. This is a potential candidate. You need to collect all subdomains that have a CNAME record pointing to a third-party service.
Step 3: Probe for "Dangling" Services
Now that you have a list of subdomains pointing to external services, you need to check if those resources are "dangling" (i.e., available for registration). You do this by visiting the subdomain in a browser or using a command-line tool like curl.
You are looking for specific error messages or "fingerprints" that indicate the resource is unclaimed.
Common Fingerprints of Vulnerable Services:
Service Provider
Common Error Message / Fingerprint
AWS S3
NoSuchBucket / "The specified bucket does not exist"
AWS CloudFront
ERROR: The request could not be satisfied
Heroku
There's nothing here, yet. / no-such-app
GitHub Pages
404 - There isn't a GitHub Pages site here.
Shopify
Sorry, this shop is currently unavailable.
Azure
The resource you are looking for has been removed... / 404 Web App not found
Netlify
Not Found
Surge.sh
project not found
Ghost.io
The thing you were looking for is no longer here, or never was.
Example:
If http://blog.example.com shows a GitHub 404 page saying "There isn't a GitHub Pages site here," it's highly likely that the GitHub repository example-blog.github.io is either deleted or was never created, making the subdomain vulnerable.
Step 4: Verification and Proof of Concept (PoC) - The Takeover
This is the most critical and sensitive step. Do not perform this step without permission.
Go to the third-party service (e.g., AWS, GitHub, Heroku).
Try to claim the dangling resource. For example:
For AWS S3, try to create a new S3 bucket with the exact name (example-blog.s3.amazonaws.com).
For GitHub Pages, create a new repository named example-blog.github.io.
If you successfully claim it, you have verified the takeover.
Create a Proof of Concept (PoC): Upload a simple index.html file to the resource you just claimed. The file should contain a non-malicious message.
html
<!DOCTYPE html>
<html>
<head>
<title>Subdomain Takeover PoC</title>
</head>
<body>
<h1>PoC - Subdomain Takeover</h1>
<p>This subdomain has been claimed to demonstrate a vulnerability.</p>
<p>This is for bug bounty/security research purposes only.</p>
<p>Researcher: [Your Name/Handle]</p>
</body>
</html>
Now, when anyone visits http://blog.example.com, they will see your PoC file. This is undeniable proof of the vulnerability.
3. Automating the Process with Tools
Manually checking thousands of subdomains is tedious. Several tools can automate steps 2 and 3.
subzy: A fast and reliable takeover scanner.
bash
# Chain it with a subdomain finder
subfinder -d example.com | subzy
subjack: Another classic and effective tool.
bash
# First, get your subdomains into a file
subfinder -d example.com -o subs.txt
# Then run subjack
subjack -w subs.txt -t 100 -o results.txt -ssl
nuclei: A versatile scanner that uses templates. It has many templates for detecting potential subdomain takeovers.
bash
subfinder -d example.com | nuclei -t "takeovers"
4. How to Prevent Subdomain Takeovers (For Defenders)
Prevention is about good hygiene in your infrastructure and deployment processes.
Audit Your DNS Zone Files: Regularly scan your own DNS records to find CNAMEs pointing to external services.
Integrate DNS Removal into De-provisioning: When you decommission a server, an application, or a resource on a third-party service, make it a mandatory part of your checklist to also delete the corresponding DNS record. This is the single most important step.
Use Takeover Detection Tools: Proactively use the same tools an attacker would (subzy, nuclei) to scan your own domains for dangling DNS records.
Claim Your Namespace: If your company is example, consider registering example on popular services like GitHub, Heroku, etc., even if you don't plan to use them, to prevent others from doing so.