Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Web attacks

Lab · Medium · 1.5 hoursFree account

Subdomain Takeover

Enumerate dangling DNS, claim GitHub Pages and S3 buckets, exploit cookie scope.

  • subdomain-takeover
  • dangling-dns
  • github-pages
  • s3
  • dns
On this page 7 sections
  1. ·Topics Covered
  2. ·What is Subdomain Takeover?
  3. ·Build the target
  4. ·Enumeration
  5. ·Identifying Dangling Records
  6. Locked: Fingerprinting Vulnerable Services
  7. Locked: Exploitation Impact

Before you start

A company creates a CNAME that points a subdomain at a cloud service, then removes the service without removing the DNS record. An attacker registers the same cloud name and now serves content from the company's own subdomain. Cookie theft, CSP bypass and brand damage are all possible consequences, and public disclosures involving Microsoft and Starbucks subdomains followed this pattern. In this lab, you find, claim and exploit one such dangling record end to end.

Lab Objectives

  • Understand what makes a subdomain vulnerable to takeover
  • Enumerate subdomains at scale using automated tools
  • Identify dangling CNAME records pointing to unclaimed resources
  • Claim a vulnerable subdomain via a cloud service
  • Exploit a taken-over subdomain for cookie theft and CSP bypass
  • Automate subdomain takeover monitoring in a CI pipeline

Topics Covered

  • CNAME chain resolution and dangling records
  • Fingerprinting takeover-vulnerable services from HTTP responses
  • GitHub Pages subdomain takeover methodology
  • AWS S3 bucket subdomain takeover
  • Heroku/Fastly/Ghost takeovers
  • Cookie scope implications — stealing session cookies via subdomain takeover

What is Subdomain Takeover?

A company may create a DNS CNAME that points blog.company.com to company.github.io. If it later removes the GitHub Pages site without removing the DNS record, an attacker can register company.github.io and serve arbitrary content from blog.company.com. The impact includes cookie theft, phishing, CSP bypass and credential harvesting.

Build the target

KaliRange hosts no targets, no domains and no lab files. You run this lab on your own machine, against a domain that you own. The names target.com, blog.target.com and attacker.com in the commands are placeholders. Replace them with your own names.

Your lab needs these parts:

  • A domain that you own, with a DNS zone that you control. Use a cheap domain or a free subdomain of one that you own.
  • At least one subdomain, for example blog, with a CNAME record that points to a cloud service (GitHub Pages, an S3 website endpoint, Heroku or similar).
  • A cloud resource behind that CNAME that you created yourself and then deleted, so that the record dangles and the service shows its "not found" page (see the fingerprint table).
  • A second account or resource name that you control, to claim the dangling name.
  • A cookie set on the parent domain (Domain=target.com), and a CSP that allows *.target.com, to show the impact section.
  • A web server of your own to receive the cookie request, and a few other subdomains so that the enumeration tools have something to list.

No public training application fits this lab, so you build it from your own domain and your own cloud accounts. Follow the terms of each cloud service. Remove the DNS records and the cloud resources when you finish. Write down the DNS records before you start, so that you can restore them.

Authorised targets only. Run every command in this lab only against a domain that you own or have written permission to test. Claiming a dangling name of someone else is unauthorised access.

Enumeration

# Mass subdomain discovery
subfinder -d target.com -o subs.txt
amass enum -passive -d target.com | tee -a subs.txt
sort -u subs.txt > all_subs.txt

# DNS resolution and CNAME extraction
cat all_subs.txt | dnsx -cname -o cnames.txt

Identifying Dangling Records

# Manual check
dig CNAME blog.target.com
# If CNAME points to unclaimed resource: VULNERABLE

# Automated scanning
subjack -w all_subs.txt -t 100 -timeout 30 -o results.txt -ssl

# Nuclei takeover templates
nuclei -l all_subs.txt -t takeovers/

Sign in to continue

2 more sections are for signed-in members. It is free: sign in with Google.

Related