CCyberwiki

Subdomain takeover

Subdomain takeover
ClassSecurity misconfiguration
Also known asSubdomain hijacking, dangling DNS
MITRE ATT&CKT1584.001 Compromise Infrastructure: Domains
Typical severityHigh
AffectsDNS records that point at hosting services, storage buckets, CDNs and other cloud resources

In a subdomain takeover, someone who does not own example.com gains control of a name under it, such as blog.example.com.1 A DNS record still sends the name to an outside service after the resource it pointed at is gone, and the service lets any customer claim that resource again.2 The attacker who claims it then trades on the trust that visitors place in the victim's domain.3

Description

Sites on hosting platforms are often reached through a CNAME record: the owner's subdomain is an alias for a long name the provider assigns, such as an Azure App Service name ending in azurewebsites.net.4 When the hosted resource is deleted and the record stays, the record is called a dangling DNS record. Of all record types, CNAMEs are the most exposed.4

The window can open at either end of a resource's life. During setup, an attacker can create the virtual host for your name at the provider before you do, so your new DNS record points at their content. During removal, the host is deleted while the DNS entry remains, and an attacker creates a new host for the same name.1 A, MX, NS and TXT records can dangle as well. The worst case is an NS record that delegates to a lapsed domain, because whoever registers that domain answers for the whole DNS zone.2

Mechanism

Amazon S3 bucket names come from one namespace shared by all customers. Suppose a company points subdomain.example.com at the website endpoint of a bucket named subdomain.example, later deletes the bucket and leaves the CNAME in place. Visitors now get an error saying the bucket does not exist. An attacker who sees that error creates a bucket with the same name in their own account, and the company's subdomain serves the attacker's pages.5 By AWS's own account, CloudFront and Elastic Beanstalk can be taken over the same way, and in none of the three services does the attack use a flaw.5

Your DNS zone (CNAME)blog.example.comName at the providerblog-ex.provider.netResource behind itdeleted by youAfter another account creates a resource with the same nameYour DNS zone (CNAME)blog.example.comName at the providerblog-ex.provider.netResource behind itowned by the attacker
Figure 1. A dangling record. The CNAME in the owner's zone still names a resource at the provider; once another account creates a resource under that name, the provider serves that account's content for the owner's subdomain.

GitHub Pages works the same way. A custom domain can be claimed by another GitHub user after the repository is deleted, the billing plan is downgraded or Pages is turned off, while the DNS record still points at GitHub and the domain is not verified.6 A CNAME can also point at a separate domain the victim owned; if that domain expires, whoever registers it controls the subdomain.2

Impact

The attacker publishes any content under the victim's name. Web apps often set session cookies for every subdomain (*.example.com), so a page on the captured name can read them, and the attacker can obtain a valid TLS certificate for it.4 From the captured name, cross-site scripting and getting around a content security policy also become possible.1 Other uses are Phishing, CSRF and CORS bypass; a captured MX record receives the victim's mail, and OAuth credentials that the application still sends to the old name reach the third party.4

Detection

Testing starts with a list of the domain's subdomains, built from the zone file or by enumeration. A query for each record with dig shows which to follow up: NXDOMAIN, SERVFAIL and REFUSED answers. A provider's "not found" page on a name that points at it, such as GitHub's 404 page, is a strong sign the name can be claimed.2

dig CNAME blog.example.com

A record that resolves is not proof of safety. If an attacker has already claimed the resource, the lookup succeeds and returns their server, so each CNAME target has to be compared with the resources that exist in the account.5 Microsoft publishes a PowerShell tool, Get-DanglingDnsRecords, for Azure resources.4 AWS CIRT has seen attackers scanning public DNS for CNAMEs whose targets no longer exist.5

Prevention

Order of changes

Create the hosted resource first and the DNS record last. When removing a site, delete the DNS record first.1 After deleting the CNAME, let its TTL run out before deleting the resource, since resolvers keep serving the old record until then (up to one hour for a TTL of 3600).5 Keep a list of every domain and the provider it points at.1

Domain verification

Several hosting providers tie a custom domain to one account through a TXT record that proves ownership of the domain:

Table 1. Verification records at three providers
ProviderRecord
GitHub PagesTXT at _github-pages-challenge-USERNAME.example.com, added under profile Settings, Pages, Add a domain; it also covers immediate subdomains6
Azure App ServiceTXT at asuid.{subdomain} holding the domain verification ID4
VercelTXT record requested when the domain is in use by another Vercel account7

The GitHub TXT record has to stay in place after verification. Avoid wildcard records such as *.example.com on GitHub Pages: verifying example.com protects a.example.com but not b.a.example.com.6 On AWS, S3 buckets created in an account regional namespace, available since March 2026, cannot be claimed by another account; existing buckets stay in the global namespace.5

After a takeover

Remove the DNS record first. Where a CDN sits in front of the host, check each layer to find where the attacker attached the name.1 Then look for data the application sent to the subdomain, such as OAuth credentials.4

Prompt for a coding agent

List every DNS record for my domain that this project creates or documents: Terraform, Pulumi, CloudFormation, provider config files and README setup steps. For each CNAME, A or ALIAS record, find the resource it points at (S3 bucket, CloudFront distribution, Vercel or Netlify project, GitHub Pages repository, Azure App Service) and say whether that resource is still defined in the project. Flag records whose target is missing, wildcard records, and custom domains with no ownership verification TXT record. Do not delete any live DNS record; list what you would change.

In SecFlash

SecFlash reports a subdomain whose record points at an outside service that answers as if nobody has claimed it as SF-SEC-308, and a record that points at a name that no longer exists as SF-SEC-309, both on the Security page. The list of live subdomains it checks appears as SF-SEC-304 on the same page.

See also

References

  1. a b c d e f MDN contributors (10 September 2025). "Subdomain takeover". MDN Web Docs.
  2. a b c d OWASP. "Test for Subdomain Takeover (WSTG-CONF-10)". OWASP Web Security Testing Guide v4.2.
  3. back "Compromise Infrastructure: Domains, T1584.001". MITRE ATT&CK.
  4. a b c d e f g Microsoft. "Prevent dangling DNS entries and avoid subdomain takeover". Microsoft Learn.
  5. a b c d e f Amazon Web Services (16 June 2026). "Threat tactic spotlight: Subdomain takeover". AWS Security Blog.
  6. a b c "Verifying your custom domain for GitHub Pages". GitHub Docs.
  7. back "Troubleshooting domains". Vercel Docs.