Step-by-Step Guide to Finding a Subdomain Takeover
A subdomain of the target pointed via a CNAME record to a third-party hosting service that nobody had claimed, so the author was able to register that service name and serve their own content under the victim's subdomain. The text presents this as a general tutorial rather than a detailed account of one specific finding.
Published on medium.com
Subdomain Takeover
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This is a short walkthrough of a subdomain takeover, written from the point of view of someone hunting for one rather than reporting a single fixed bug. The write-up is published on Medium, but the technique is generic: a subdomain of a target organisation points, via a CNAME record, at a third-party service that is no longer claimed by anyone. Whoever claims that service name first controls what the subdomain serves.
The researcher's own example involves two hostnames: dev-app.target.sh, which is the CNAME target on a third-party platform, and sportsbook.target.com, the subdomain that pointed at it. The write-up does not describe the target organisation, the product behind sportsbook.target.com, or what that subdomain was originally used for. It also gives no dates, bounty amounts or severity rating.
Setup
The write-up does not state versions for any of the tools used. The toolchain is:
subfinderandamassfor subdomain enumerationanewfor de-duplicating results into a filednsxfor resolving CNAME recordsnucleiwith thetakeoverstemplate directorydigandtestssl.shfor the bonus techniques- The can-i-take-over-xyz reference list for checking whether a given service is actually takeable
No accounts, credentials or special access are needed. The only precondition is a target domain with subdomains, and the ability to register an account on whichever third-party platform a dangling CNAME points to.
Finding it
The logic is a funnel. Enumerate as many subdomains as possible, keep only those whose DNS points at a known third-party host, scan those for known takeover signatures, then manually verify each candidate before claiming anything. The manual verification step matters because automated hits are noisy: a CNAME to a third-party service is only exploitable if the specific resource behind it is unclaimed.
Exploitation
Step 1: Find subdomains
subfinder -d target.com -silent | anew subs.txtamass enum -passive -d target.com | anew subs.txt
subfinder runs in silent mode against target.com and pipes its output into anew, which appends only lines not already present in subs.txt. amass then runs in passive mode and appends its results to the same file. and appends its results to the same file. The two commands are shown run together on one line in the write-up; in practice they are two separate commands whose output both lands in subs.txt.
Step 2: Find CNAMEs
cat subs.txt | dnsx -cname -resp | grep -iE 'vercel|heroku|github|s3|wordpress'
dnsx is asked to resolve each name and return CNAME records together with their responses. The grep then keeps only lines mentioning one of five third-party platforms: Vercel, Heroku, GitHub, S3 and WordPress. These are third-party services the researcher filtered for, so a subdomain resolving to one of them is a potential takeover candidate. The list is not exhaustive; it is just the set the researcher filtered for.
Step 3: Test for takeover with Nuclei
nuclei -t nuclei-templates/takeovers/ -l subs.txt
This runs every template in the takeovers directory against the subdomain list. The templates match the response fingerprints that third-party services return when a resource does not exist, so a hit means the subdomain is pointing at a service that appears not to have a matching resource behind it.
Step 4: Filter real vulnerabilities
The researcher does not treat a Nuclei hit as a finding. Each candidate is checked by hand:
- Visit the subdomain and look for an error message that indicates the service is unclaimed, such as "No such app" or "There isn't a site here".
- Visit the underlying CNAME target directly, for example
dev-app.target.sh, and confirm that it is dead. - Cross-check the service against can-i-take-over-xyz to avoid false positives.
Step 5: Claim the service
In the researcher's case, the dangling CNAME target was dev-app.target.sh on Vercel. Registering that name on Vercel and serving content there meant that sportsbook.target.com, which still pointed at it, began serving the researcher's content.
Bonus: other methods of takeover
The write-up lists further angles beyond CNAME records pointing at a live third-party platform:
- AWS S3 buckets. A
NoSuchBucketerror usually means the bucket is unclaimed or was deleted. If a subdomain still points at it, creating a bucket with the same name takes control of the subdomain. - GitHub Pages. If a subdomain points at
username.github.ioand the corresponding repository does not exist, creating that repository lets you serve content under the victim's subdomain. - Expired domain takeovers. When a subdomain points at a third-party domain that has expired, registering the expired domain hijacks the associated subdomain.
- DNS zone transfers (AXFR). The command given is:
dig axfr @ns1.target.com target.com
If the nameserver is misconfigured to allow transfers, this returns the full list of subdomains and CNAME records, which feeds straight back into the earlier steps.
- TLS certificate mismatches. Running
testssl.shcan reveal a certificate issued for a service such as*.s3.amazonaws.comwhile the subdomain is something likefiles.target.com. That mismatch is a strong sign of misconfiguration pointing at a third-party service. - Multi-hop takeovers. Follow the redirect chain. If
a.target.com → b.heroku.com → c.s3.amazonaws.comand each hop is unclaimed, the takeover can be chained through all of them.
Root cause
The underlying mistake is a DNS record that outlives the resource it points at. A CNAME from sportsbook.target.com to dev-app.target.sh stays in place after the name is no longer claimed. so the subdomain now delegates its content to a name that anyone can register. Nothing in the target's own infrastructure is compromised; the trust is simply handed to a namespace the target no longer controls.
The record resolves, the third-party service answers with its "not found" page, and the subdomain keeps working at the DNS level while serving nothing legitimate.
Impact
An attacker who claims the dangling resource controls the content served on the victim's subdomain. Because the hostname belongs to the target, content served there appears under the target's domain. The write-up does not go into these consequences beyond stating that the subdomain pointed to the researcher's content.
The impact depends on the subdomain. , and the attack only works while the CNAME remains and the third-party name stays unclaimed.
Fix
Remove the dangling DNS record, or reclaim the third-party resource so the name is no longer available to outsiders.
Variants to test
- Other third-party platforms. The
grepin Step 2 covers Vercel, Heroku, GitHub, S3 and WordPress. Extend the pattern to any service on can-i-take-over-xyz that is marked as vulnerable. A positive result is a subdomain whose CNAME points at that service and whose response matches the service's "unclaimed" fingerprint. - S3 buckets. Look for
NoSuchBucketon a subdomain that still resolves to S3. A positive result is the ability to create a bucket with the same name. - GitHub Pages. Look for a subdomain pointing at
username.github.iowhere the repository does not exist. A positive result is being able to create that repository under that username. - Expired domains. Follow CNAMEs to third-party domains and check their registration status. A positive result is an expiring or expired domain that can be registered.
- Zone transfers. Run the
dig axfrcommand against each authoritative nameserver. A positive result is a full zone listing coming back instead of a refused transfer. - Certificate mismatches. Run
testssl.shagainst candidate subdomains and look for certificates issued for a third-party wildcard rather than the target's own domain. A positive result is a certificate whose subject does not match the hostname being served. - Redirect chains. Follow every hop from the subdomain through third-party services. A positive result is a chain in which an intermediate hop is unclaimed, allowing the takeover to be chained.
What happened, in plain words
A subdomain is a name that sits in front of a main domain, like shop.example.com in front of example.com. Organisations use them for separate services: a shop, a support portal, a sports betting site, an internal tool. Each subdomain is a name that the organisation controls, and visitors trust it because it carries the organisation's domain.
A subdomain takeover happens when one of those names is left pointing at something the organisation no longer owns. The most common way this happens is through a DNS record called a CNAME. Think of a CNAME as a forwarding note: it says "this name is really just another name, go and ask that one instead". If sportsbook.target.com has a CNAME pointing at dev-app.target.sh, then anyone who visits sportsbook.target.com is silently sent to whatever dev-app.target.sh serves.
Now suppose the organisation stops using dev-app.target.sh and deletes it from the third-party platform where it lived, but forgets to remove the CNAME. The forwarding note is still there, pointing at a name that nobody owns. On many platforms, anyone can register that name. If an outsider registers dev-app.target.sh, then sportsbook.target.com starts serving the outsider's content, under the organisation's own trusted domain.
This write-up is a short walkthrough of how to hunt for that situation. It is written from the point of view of someone looking for a takeover rather than reporting one fixed bug. The write-up is published on Medium, but the technique is generic and works against any domain with subdomains. The researcher's own example uses two hostnames: dev-app.target.sh, the CNAME target on a third-party platform, and sportsbook.target.com, the subdomain that pointed at it. The write-up does not describe the target organisation, the product behind sportsbook.target.com, or what that subdomain was originally used for. It gives no dates, bounty amounts or severity rating.
The tools you will see
The write-up does not state versions for any of the tools. Here is what each one does, in plain terms:
subfinderandamassfind subdomains. They gather subdomains from multiple sources.anewis a small helper that adds lines to a file only if they are not already there, so you do not get duplicates.dnsxlooks up DNS records for a list of names. Here it is used to find CNAME records.nucleiis a scanner that runs ready-made checks, called templates, against a list of hosts. Thetakeoverstemplate directory contains checks for the error pages that third-party services return when a resource is missing.digis a command-line DNS lookup tool.testssl.shinspects the TLS certificate a server presents.- The can-i-take-over-xyz list is a community reference of which third-party services can actually be taken over, and how.
No accounts, credentials or special access are needed to start. The only precondition is a target domain with subdomains, and the ability to register an account on whichever third-party platform a dangling CNAME points to.
The overall approach
The logic is a funnel. First, collect as many subdomains as possible. Then keep only the ones whose DNS points at a known third-party host. Then scan those for known takeover signatures. Finally, check each candidate by hand before claiming anything.
The manual check matters because automated hits are noisy. A CNAME pointing at a third-party service is only exploitable if the specific resource behind it is unclaimed. Many CNAMEs point at services that are perfectly alive and owned by the organisation.
Step 1: Find subdomains
subfinder -d target.com -silent | anew subs.txtamass enum -passive -d target.com | anew subs.txt
Line by line:
subfinder -d target.com -silentrunssubfinderagainst the domaintarget.com. The-dflag means "domain". The-silentflag suppresses banners and progress noise so only the found names are printed.- The
|symbol is a pipe. It takes the output of the command on the left and feeds it as input to the command on the right. anew subs.txtreads those names and appends to the filesubs.txtonly the ones that are not already in it. This keeps the list free of duplicates.amass enum -passive -d target.comrunsamassin passive mode against the same domain. Passive mode gathers names from public sources.- Its output is piped into
anew subs.txtagain, so both tools write into the same file.
The two commands are shown run together on one line in the write-up. In practice they are two separate commands whose output both lands in subs.txt.
Why this step: you cannot find a dangling subdomain if you do not know the subdomain exists. The more names you collect, the better the chance that one of them is stale.
Step 2: Find CNAMEs
cat subs.txt | dnsx -cname -resp | grep -iE 'vercel|heroku|github|s3|wordpress'
Line by line:
cat subs.txtprints the contents of the subdomain list.dnsx -cname -respis asked to resolve each name and return CNAME records together with their responses. In other words, for each subdomain it asks DNS "is this name an alias for another name, and if so, what does that other name answer?"grep -iE 'vercel|heroku|github|s3|wordpress'filters the output.grepsearches text for a pattern.-imakes the match case-insensitive, and-Eallows the pattern to use alternation, the|characters inside the quotes, meaning "any of these". So only lines mentioning Vercel, Heroku, GitHub, S3 or WordPress survive.
Why these five: they are third-party platforms the researcher filtered for as potential takeover candidates. A subdomain resolving to one of them is a takeover candidate. The list is not exhaustive; it is just the set the researcher filtered for.
Step 3: Test for takeover with Nuclei
nuclei -t nuclei-templates/takeovers/ -l subs.txt
Line by line:
nucleiis the scanner.-t nuclei-templates/takeovers/tells it to use every template in thetakeoversdirectory. Each template describes the response fingerprint that a particular third-party service returns when a resource does not exist.-l subs.txtgives it the list of subdomains to test, one per line.
Why this step: the templates match the error pages that services return when a resource is missing. A hit means the subdomain is pointing at a service that appears not to have a matching resource behind it. That is a strong hint, not proof.
Step 4: Filter real vulnerabilities
The researcher does not treat a Nuclei hit as a finding. Each candidate is checked by hand:
- Visit the subdomain and look for an error message that indicates the service is unclaimed, such as "No such app" or "There isn't a site here".
- Visit the underlying CNAME target directly, for example
dev-app.target.sh, and confirm that it is dead. - Cross-check the service against can-i-take-over-xyz to avoid false positives.
Why this step: a scanner can be fooled by a page that merely looks like an error page. Visiting the subdomain and the CNAME target yourself confirms that the resource really is unclaimed. The community list helps you avoid false positives.
Step 5: Claim the service
In the researcher's case, the dangling CNAME target was dev-app.target.sh on Vercel. Registering that name on Vercel and serving content there meant that sportsbook.target.com, which still pointed at it, began serving the researcher's content.
Why this step: claiming the name is the proof. Until the subdomain actually serves your content, you have a suspicion, not a finding.
Bonus: other methods of takeover
The write-up lists further angles beyond CNAME records pointing at a live third-party platform.
AWS S3 buckets
S3 is Amazon's file storage service. A bucket is a named container of files. Look for NoSuchBucket errors: these usually indicate an unclaimed or deleted bucket. If the subdomain still points to it, you can create a bucket with the same name and take control.
GitHub Pages
GitHub Pages is a free way to host a website from a GitHub repository. If a subdomain points to username.github.io, but the corresponding GitHub repository does not exist, you can create that repository and serve content under the victim's subdomain.
Expired domain takeovers
When a subdomain points to a third-party domain that has expired, register the expired domain and hijack the associated subdomain.
DNS zone transfers (AXFR)
dig axfr @ns1.target.com target.com
Line by line:
digis the DNS lookup tool.axfris the query type: a full zone transfer, meaning "give me every record in this zone".@ns1.target.comtellsdigwhich nameserver to ask, herens1.target.com.target.comis the zone being requested.
If DNS is misconfigured, you might retrieve a full list of subdomains and CNAME records. That list feeds straight back into the earlier steps.
TLS certificate mismatches
TLS is the encryption behind the padlock in your browser. A certificate is the document a server presents to prove which name it is serving. Run testssl.sh to check if the TLS certificate was issued for a service like *.s3.amazonaws.com while the subdomain is something like files.target.com. That mismatch is a strong sign of misconfiguration pointing at a third-party service.
Multi-hop takeovers
Follow the redirect chain. If a.target.com → b.heroku.com → c.s3.amazonaws.com and each hop is unclaimed, you can chain the takeover through all of them.
Why this happens
The underlying mistake is a DNS record that outlives the resource it points at. A CNAME from sportsbook.target.com to dev-app.target.sh stays in place after the name is no longer claimed. The subdomain now delegates its content to a name that anyone can register. Nothing in the target's own infrastructure is compromised; the trust is simply handed to a namespace the target no longer controls.
The record resolves, the third-party service answers with its "not found" page, and the subdomain keeps working at the DNS level while serving nothing legitimate.
What an attacker could do with it
An attacker who claims the dangling resource controls the content served on the victim's subdomain. Because the hostname belongs to the target, content served there appears under the target's domain. The write-up does not go into these consequences beyond stating that the subdomain pointed to the researcher's content.
The impact depends on the subdomain. , and the attack only works while the CNAME remains and the third-party name stays unclaimed.
How to fix it
Remove the dangling DNS record, or reclaim the third-party resource so the name is no longer available to outsiders.
Variants to test
- Other third-party platforms. The
grepin Step 2 covers Vercel, Heroku, GitHub, S3 and WordPress. Extend the pattern to any service on can-i-take-over-xyz that is marked as vulnerable. A positive result is a subdomain whose CNAME points at that service and whose response matches the service's "unclaimed" fingerprint. - S3 buckets. Look for
NoSuchBucketon a subdomain that still resolves to S3. A positive result is the ability to create a bucket with the same name. - GitHub Pages. Look for a subdomain pointing at
username.github.iowhere the repository does not exist. A positive result is being able to create that repository under that username. - Expired domains. Follow CNAMEs to third-party domains and check their registration status. A positive result is an expiring or expired domain that can be registered.
- Zone transfers. Run the
dig axfrcommand against each authoritative nameserver. A positive result is a full zone listing coming back instead of a refused transfer. - Certificate mismatches. Run
testssl.shagainst candidate subdomains and look for certificates issued for a third-party wildcard rather than the target's own domain. A positive result is a certificate whose subject does not match the hostname being served. - Redirect chains. Follow every hop from the subdomain through third-party services. A positive result is a chain in which an intermediate hop is unclaimed, allowing the takeover to be chained.
Glossary
- Subdomain: a name in front of a main domain, such as
shop.example.comin front ofexample.com. - DNS: the system that turns names like
example.cominto the addresses computers use to reach servers. - CNAME record: a DNS record that says one name is an alias for another name, so lookups are forwarded.
- Subdomain takeover: claiming a third-party resource that a subdomain still points at, so the subdomain serves your content.
- Dangling record: a DNS record that points at a resource that no longer exists or is no longer owned.
- Third-party platform: an outside service, such as Vercel, Heroku, GitHub, S3 or WordPress, that hosts content under names you can register.
subfinder: a tool that collects subdomains from public sources.amass: a tool that collects subdomains; in passive mode it uses only public sources.anew: a helper that appends only new lines to a file, removing duplicates.dnsx: a tool that performs DNS lookups for a list of names.nuclei: a scanner that runs ready-made checks, called templates, against hosts.- Template: a file describing a check, here the error-page fingerprint of a third-party service.
grep: a command that searches text for a pattern.- Pipe (
|): a shell symbol that passes the output of one command as input to the next. - Fingerprint: the distinctive response a service returns, used to recognise it.
- False positive: a scanner hit that turns out not to be a real vulnerability.
- S3: Amazon's file storage service; a bucket is a named container of files.
NoSuchBucket: the error S3 returns when the requested bucket does not exist.- GitHub Pages: a free hosting service that serves a website from a GitHub repository.
- Expired domain: a domain name whose registration has lapsed and can be bought by someone else.
- Zone transfer (AXFR): a DNS query that asks a nameserver for every record in a zone.
- Nameserver: the server that holds the DNS records for a domain.
- TLS: the encryption behind the padlock in a browser.
- Certificate: the document a server presents to prove which name it is serving.
- Wildcard certificate: a certificate valid for every name under a domain, such as
*.s3.amazonaws.com. - Redirect chain: a series of forwards from one address to another.
- Phishing: tricking people into trusting a page because it sits on a familiar domain.