Subdomain Takeover is a vulnerability that occurs when a dangling DNS record (typically a CNAME, but can also be an A or NS record) points to an external service (like GitHub Pages, Heroku, Amazon S3, Microsoft Azure, Zendesk, etc.) that has been deprovisioned or expired. An attacker can then claim that service, thereby taking control of the subdomain.
This can lead to:
- Phishing/Malware Distribution: Hosting malicious content on a trusted subdomain.
- Session Hijacking/Cookie Theft: Bypassing Same-Origin Policy if the main domain issues lax cookies.
- Brand Reputation Damage: Defacing the subdomain with undesirable content.
- Bypassing Security Controls: E.g., Content Security Policy (CSP), Web Application Firewalls (WAFs) that whitelist the main domain.
Here's a step-by-step guide on how to find Subdomain Takeover vulnerabilities:
Phase 1: Subdomain Enumeration (Finding Potential Targets)
The first step is to gather as many subdomains as possible for your target domain. The more comprehensive your list, the higher your chances of finding a vulnerable one.
-
Passive Enumeration (OSINT):
- Search Engines: Use Google Dorks like
site:*.example.com or site:example.com -www to find indexed subdomains.
- Certificate Transparency Logs (CTLs): Websites like
crt.sh, censys.io, securitytrails.com list domains for which SSL certificates have been issued. This is an excellent source.
- DNS Databases/Archives:
DNSDumpster.com
VirusTotal.com (search for domain:example.com)
Shodan.io (can search for hostname:.example.com)
Anubis-DB.com
Riddler.io
- Wayback Machine (
archive.org): Look for old versions of the website that might reference subdomains no longer in use.
- GitHub/Code Repositories: Search for the domain name in public code repositories; developers sometimes hardcode subdomains.
- Tools:
Sublist3r: Python script to enumerate subdomains using various search engines.
Amass: A powerful tool for comprehensive asset discovery and enumeration.
subfinder: A fast and simple passive subdomain enumeration tool.
-
Active Enumeration:
- Brute-Forcing: Use tools like
ffuf, gobuster, or massdns with large subdomain wordlists (e.g., SecLists/Discovery/DNS/subdomains-top1million-110000.txt) to guess subdomains.
- Zone Transfers (Rarely successful, but worth a try): Attempt a DNS zone transfer for the target domain (
dig axfr @ns1.example.com example.com).
- Reverse DNS Lookups: Look up IP ranges owned by the target and try reverse DNS lookups.
Output: A massive list of potential subdomains (e.g., test.example.com, blog.example.com, staging.example.com, dev.example.com, old-app.example.com, etc.).
Phase 2: Identifying Potential Vulnerable Subdomains
Once you have a list of subdomains, you need to check which ones might be pointing to a deprovisioned external service.
-
Resolve DNS Records: For each subdomain, resolve its DNS records, specifically looking for CNAME, A, or NS records pointing to external services.
dig <subdomain.example.com>
nslookup <subdomain.example.com>
host <subdomain.example.com>
- Look for
CNAME records pointing to domains like example.github.io, s3-website-us-east-1.amazonaws.com, myapp.herokuapp.com, azurewebsites.net, etc.
- Look for
A records pointing to IPs that don't belong to the organization, or seem to be generic cloud IPs.
-
Check HTTP Responses for Specific Error Messages: If a subdomain resolves to an external service, visit it in your browser or use curl. Look for specific error messages that indicate the service is not configured or has been deprovisioned by the original owner.
Common "Dangling" Error Messages for various services:
- Heroku:
No such app, There's nothing here.
- GitHub Pages:
There isn't a GitHub Pages site here., 404 Site not found
- Amazon S3:
NoSuchBucket, The specified bucket does not exist.
- Microsoft Azure (Blob Storage/App Service):
No such host is known., Page not found., The specified resource was not found., Service not found
- Shopify:
Sorry, this shop is unavailable.
- Netlify:
Not Found - Request ID, Page Not Found
- Wix:
This site was not found.
- CloudFront:
Bad Request (sometimes, if the origin is removed)
- Zendesk:
Oops, we couldn't find your help center!
- Desk.com:
Sorry, that page doesn't exist.
- Tumblr:
There's nothing here.
- Unbounce:
Page not found., The requested page could not be found.
Phase 3: Confirming the Takeover (Ethically!)
IMPORTANT: Before attempting to claim any service, understand the ethical implications. Only perform this step if you have explicit permission (e.g., through a bug bounty program or a penetration testing contract). If you are testing your own assets, proceed with caution. Do not host malicious content.
-
Identify the Service: From Phase 2, you should know which external service the dangling DNS record points to (e.g., GitHub Pages, Heroku, S3).
-
Register an Account: Create a new account on that specific service (if you don't already have one).
-
Create a Resource:
- GitHub Pages: Create a new repository (e.g.,
yourusername/yourusername.github.io or orgname/repo). In the repository settings, go to "Pages" and add the vulnerable subdomain (vulnerable.example.com) as a custom domain.
- Heroku: Create a new app. Go to "Settings" -> "Domains" and add the vulnerable subdomain.
- Amazon S3: Create a new S3 bucket with the exact name of the vulnerable subdomain (
vulnerable.example.com). Configure it for static website hosting.
- Azure: Create a new Azure App Service or Storage Account. Attempt to bind the custom domain.
-
Claim the Subdomain: Follow the service's instructions for adding a custom domain. If the takeover is successful, the service will accept the domain, and your newly created resource will be accessible via vulnerable.example.com.
-
Proof of Concept (POC):
-
Immediately Relinquish Control: After getting your proof, remove your claim on the domain from the service you used. Delete the resource (app, bucket, repository) you created. This is crucial for ethical hacking to minimize your impact.
Phase 4: Reporting and Remediation
-
Responsible Disclosure: If you found a vulnerability on a system you don't own, report it immediately to the domain owner or through their designated bug bounty program.
- Clearly explain the vulnerability.
- Provide steps to reproduce (without actually performing the takeover, or by showing your POC screenshots).
- Explain the potential impact.
-
Remediation:
- Delete the dangling DNS record: This is the primary fix. Remove the CNAME, A, or NS record that points to the deprovisioned service.
- Reclaim the service: If the service was accidentally deprovisioned, the legitimate owner can re-create their resource on the external service and claim the subdomain again.
- Regular DNS Audits: Implement a process to regularly review and clean up DNS records, especially for decommissioned services or applications.
By following these steps, you can effectively identify and, if ethically permitted, confirm Subdomain Takeover vulnerabilities. Always prioritize ethical hacking and responsible disclosure.