Skip to main content
All articles

Subdomain takeover: the CNAME that outlived the thing it pointed at

A subdomain takeover happens when a DNS record still points at a cloud resource you already deleted, and an attacker recreates that resource to claim your subdomain. Here is the dangling-DNS distinction, a real CVE, a detector you can build against your own zone, and the decommissioning discipline that prevents it.

By Published

9 min read24 views

You spin up a project on a hosting platform, point status.example.com at it with a CNAME, and ship. A year later the project is retired and the platform resource is deleted. The CNAME is not. It now advertises status.example.com to the world as live, but it resolves to a target that no longer belongs to anyone. Someone registers that target on the same platform, and every visitor to status.example.com, with your certificate trust, your cookies scoped to *.example.com, and your brand in the address bar, is now theirs.

Nothing was hacked. A record simply outlived the resource it named, and the platform let the next person claim the vacancy.

The one distinction

A subdomain takeover is not "DNS was misconfigured" in the abstract. It is one specific condition: a dangling DNS record, a live record pointing at a deprovisioned resource, combined with a claimable target, a platform that will let a stranger recreate that exact resource name.

Both halves are required, and separating them tells you where to act:

  • Dangling but not claimable is a bug you fix at leisure. The record points at nothing, visitors get an error, and no attacker can occupy the space. Ugly, not dangerous.
  • Dangling and claimable is a live takeover waiting for whoever notices first. The target is on a platform where account A can release a name and account B can grab it, and your CNAME is the pointer that makes B's content answer to your name.

The dangerous set is the intersection. That is why the fix is a decommissioning process, not a firewall rule: you are racing to delete the record before someone claims the target, and the only durable win is to never leave the record dangling in the first place.

Why it varies: the platform decides who can reclaim a name

Whether a dangling record is claimable is a property of the target platform, and platforms differ. Some reserve a released name for the original owner's account or tenant for a while; some require you to prove domain ownership with a verification token before serving traffic; some hand the name to the next taker immediately. The community catalogue "Can I take over XYZ?" exists precisely because the answer is per-service and changes over time.

Microsoft's own guidance on the Azure model spells out the mechanic: you create a resource with a fully qualified name such as app-name.azurewebsites.net, point a CNAME at it, later delete the resource, and if the CNAME is not removed it becomes a dangling entry that "can be taken over by being assigned to another Azure subscription's resource." The takeover step is nothing more exotic than provisioning a new resource with the same FQDN. The variance across CDNs, storage buckets, static-site hosts, and PaaS platforms is entirely in how hard they make that last step, and you cannot assume any given one makes it hard.

The real CVE

CVE-2023-36474, in the Interactsh server, is a clean, non-hypothetical instance. NVD (CVSS 6.1; the advisory GHSA-m36x-mgfh-8g78 rates it 8.2, CWE-79) describes it exactly: Interactsh server before 1.0.0 created a CNAME entry for the app. subdomain pointing to projectdiscovery.github.io by default, intended for hosting the web client on GitHub Pages. Self-hosted operators who never configured a web client were left with a live CNAME pointing at an unclaimed GitHub Pages target, "making them vulnerable to subdomain takeover." An attacker could claim the GitHub Pages endpoint and "host / run arbitrary client side code (cross-site scripting) in a user's browser." The fix in 1.0.0 was to make the CNAME optional rather than default, so the pointer no longer existed unless the operator meant it to.

Read the shape of that bug and it is the whole class in miniature: a CNAME that points at a third-party target the operator does not actually occupy. It does not matter that the default was well-intentioned. A pointer to a vacancy on a claimable platform is a takeover regardless of how the pointer got there. GitHub Pages, Heroku, S3 buckets and cloud CDNs have been the classic targets since Detectify first documented the technique in 2014, and the list has only grown.

A lab you can build

A Linux VM and Python are enough. No Docker. Critically, this lab does not take over anyone's subdomain; it builds the detector, run against your own zone, which is the artefact you actually want.

python3 -m venv takeoverlab && . takeoverlab/bin/activate
pip install dnspython

The detector reads your CNAME inventory, resolves each target, and flags the two danger signals: a target that no longer resolves at all (NXDOMAIN), and a target on a known claimable platform that is answering with an "unclaimed" fingerprint. A small local fixture lets it run offline so you can see the logic before pointing it at real data.

# takeover_scan.py: a detector for your own zone, not an attack tool
import dns.exception
import dns.resolver

# Minimal fingerprint table. The real one lives in "Can I take over XYZ?".
# Maps a target-host suffix to a string that means "this name is unclaimed".
FINGERPRINTS = {
    "github.io":        "There isn't a GitHub Pages site here",
    "herokuapp.com":    "No such app",
    "s3.amazonaws.com": "NoSuchBucket",
}

def cname_target(subdomain):
    try:
        answers = dns.resolver.resolve(subdomain, "CNAME")
        return str(answers[0].target).rstrip(".")
    except dns.resolver.NXDOMAIN:
        return None
    except dns.resolver.NoAnswer:
        return ""  # resolves, but not a CNAME

def classify(subdomain):
    try:
        target = cname_target(subdomain)
    except dns.exception.DNSException as exc:
        # Timeout, SERVFAIL, unreachable resolver: report it, keep scanning.
        return f"LOOKUP FAILED: {type(exc).__name__} (rerun; not a takeover signal)"
    if target is None:
        return "DANGLING: name does not resolve"
    if not target:
        return "ok: no CNAME"
    for suffix, marker in FINGERPRINTS.items():
        if target.endswith(suffix):
            # In production, fetch https://<subdomain>/ and test for `marker`
            # in the body. Here we only flag the claimable platform.
            return f"REVIEW: CNAME -> {target} (claimable platform)"
    return f"ok: CNAME -> {target}"

# Your zone inventory. Feed this from your DNS export, not by hand.
INVENTORY = ["status.example.com", "old-project.example.com", "www.example.com"]

for name in INVENTORY:
    print(f"{name:30} {classify(name)}")

The exercise is to point INVENTORY at a real CNAME export from your own DNS zone and read the REVIEW and DANGLING lines. A LOOKUP FAILED line is a resolver timeout or SERVFAIL, not a finding; rerun those names rather than letting one of them stop the scan. The production step the comment marks, fetching the subdomain and testing the response body for the platform's "unclaimed" marker, is what turns a REVIEW into a confirmed finding, and it is a read of your own subdomain, not a claim of anyone's resource. The detector is the deliverable. Building it teaches the bug more durably than any single takeover would, and it is the thing you schedule to run weekly.

Finding it in your estate

  • Diff DNS against live resources. Export every CNAME (and ALIAS, and A record pointing at cloud IP ranges) and check that each target still exists and still belongs to you. Microsoft ships a PowerShell tool, Get-DanglingDnsRecords, for the Azure case; the general form is the loop above.
  • Sort by claimable platform. A CNAME to a third-party host, GitHub Pages, Heroku, S3, a CDN, a PaaS, is higher risk than one pointing inside infrastructure you fully control. Work the third-party pointers first.
  • Hunt the wildcards and the forgotten TXT/MX. A *.example.com CNAME can be claimed once for many names. Dangling MX records let an attacker receive mail for a trusted subdomain. Both are easy to miss because nobody remembers creating them.
  • Look where OAuth and cookies reach. A cookie scoped to *.example.com is readable from any subdomain, so a takeover of one is a session risk for all. Note which subdomains sit inside that scope; they are the ones a takeover hurts most.

Fixing it

  • Remove the DNS record as part of deprovisioning, not after. The record and the resource share a lifecycle. "Delete the DNS entry" belongs on the decommissioning checklist next to "delete the resource," and ideally before it, so the window where the record dangles never opens.
  • Use ownership verification where the platform offers it. Azure App Service's asuid TXT record, and equivalent verification tokens on other platforms, stop a stranger from validating the custom domain even if they recreate the resource name. Turn these on.
  • Bind the record's lifecycle to the resource. Azure alias records, and infrastructure-as-code that creates and destroys the DNS entry alongside the resource, remove the human step that gets forgotten.
  • Reclaim or repoint immediately when you find a dangling record. Either delete it or point it at a resource you control right now. If it may already be taken over, investigate for compromise, because credentials or privacy-sensitive data sent to that subdomain may have reached a third party.

Detection

  • Schedule the inventory diff. The detector above, run weekly against a fresh DNS export, converts takeover from a thing you discover during an incident into a thing you catch as a DANGLING line. Cloud platforms increasingly offer this natively; Microsoft Defender for App Service, for instance, alerts when a site is decommissioned but its custom domain is not removed.
  • Monitor for the answer changing. A subdomain that begins serving content, or a certificate, that your team did not deploy is a takeover in progress. Certificate transparency logs will show a certificate issued for your subdomain by someone who now controls it.
  • Keep an owned inventory. Maintain a catalogue mapping every external FQDN to the resource and the team that owns it, so "does this still belong to us?" has an answer that is not archaeology.

Take this away

A subdomain takeover needs two things at once: a DNS record that still points somewhere, and a somewhere that a stranger can claim. The record is yours to delete and the platform's claimability is not, so the only reliable control is on your side: retire the DNS entry as part of retiring the resource, and audit for the ones you already forgot. Build the detector, run it against your own zone on a schedule, and treat every dangling record as live until you have removed or repointed it. The CNAME that outlived its target is not a loose end. It is an open invitation with your name on it.

Sources

Was this useful?

Share

Tags

  • cloud security
  • detection engineering
  • cve analysis
  • penetration testing

Get the next write-up by email

New technical write-ups by email when we publish. No sales sequence, and every email has an unsubscribe link.

Prefer a feed? RSS. How we handle your address: privacy notice.

Comments

Loading comments…

Leave a comment

Comments are read and approved by hand before they appear, so yours will not show up straight away. Your email address is optional, is never published, and is only used if we need to reply to you directly.

0/5000

Related service

Cloud Penetration Testing (AWS)

Identity, storage and workload misconfiguration testing across your AWS accounts.

If you want to know whether what you have just read applies to your own systems, that is the engagement that answers it.