CertaDNS
Skip to lesson

Subdomain Takeover · lesson 2 of 2

Finding them before someone else does

After this lesson you can

Triage a list of CNAME targets for takeover risk and state the retirement rule that prevents recurrence.

Assumes you have read Dangling records.

Finding dangling records is a triage exercise: enumerate what your zone points at, work out which targets are unclaimed, and judge which of those can actually be taken. The last step is the one that needs judgement, because most unresolved targets are harmless.

Step 1 — list what you point at

You need the zone contents. From your DNS provider’s export, or a zone transfer if you are permitted one:

# every CNAME target in an exported zone file
awk '$4=="CNAME" {print $1, $5}' example.com.zone | sort -u

# every delegated subdomain
awk '$4=="NS" && $1!="example.com." {print $1, $5}' example.com.zone | sort -u

If you cannot get the zone, you are reduced to guessing names, and that is a much weaker position. Being able to enumerate your own zone is itself worth having.

Step 2 — check each target

for host in $(cut -d' ' -f2 targets.txt); do
  printf '%-50s ' "$host"
  dig +short "$host" | head -1 | grep -q . && echo RESOLVES || echo 'NXDOMAIN  <-- investigate'
done

NXDOMAIN on a CNAME target is the strongest single signal. It means the platform has released the name, and on many platforms releasing means available.

Step 3 — decide whether it is takeable

This is where judgement comes in, and where automated tooling produces its false positives.

ObservationReading
CNAME target NXDOMAIN, on a platform with open self-service signupLikely takeable. Highest priority.
CNAME target resolves, and the service returns a "no such site" pageOften takeable — the platform holds the name but the resource is unclaimed. Read the platform’s own documentation on how it allocates names.
CNAME target resolves and serves your contentFine. In use.
A record pointing at an address not assigned to youInvestigate. Exploitability depends on whether an attacker can obtain that specific address, which for a cloud pool is possible but not on demand.
NS delegation to nameservers that do not answer for the zoneSevere. Treat as urgent.

Do not test by claiming

The definitive test is to register the resource on the platform and see whether you get it. On your own domain that is a legitimate and sensible thing to do. Do not do it for a domain you do not own — claiming someone else’s dangling hostname is an unauthorised act regardless of intent, and demonstrating a takeover by performing one is not a demonstration anybody thanks you for.

Fixing

Delete the record. That is the whole remediation, and it is instant and complete.

The hesitation is always the same — someone might still need it — and it is answerable with evidence: check query volume if your DNS provider reports it, lower the TTL and watch, announce the removal, then delete. A record pointing at infrastructure you do not control is not serving anyone except whoever controls it.

The rule that stops them accumulating

Retire the DNS record before you cancel the service

Cancelling first creates the window. Removing the record first closes it, at the cost of a brief outage on a service you were cancelling anyway. This single ordering rule prevents almost every case.

  • Record the owner of every record that points at third-party infrastructure — a comment in the zone, a field in your DNS management, an inventory. When a service is cancelled there is then someone to ask.
  • Put DNS cleanup in the offboarding checklist for vendors, not only for people.
  • Re-run the enumeration periodically. Quarterly is enough. It is a short script and the findings do not accumulate quietly if something is looking.
  • Watch certificate transparency for your own domain. A certificate issued for a hostname you did not expect is a strong signal that somebody else controls it. The monitoring module returns to this.
Knowledge check

An audit finds three records: (1) a CNAME to a SaaS hostname returning NXDOMAIN, (2) an A record to a cloud IP not in your account, (3) an NS delegation for eu.example.com to nameservers that return REFUSED. Which do you deal with first?

Last reviewed