Subdomain takeover: how to find and remove forgotten DNS records
A subdomain takeover becomes possible when your DNS zone still contains a record pointing to an external service you have already cancelled. Typical examples are an old campaign page, a blog, a customer support portal or a test environment. If the provider of that service does not properly verify domain ownership, a stranger can create an account, attach your subdomain to it and show their own content under your brand.
The fix is not an expensive tool but good housekeeping: a complete inventory of DNS records, an owner for every subdomain, the right order of steps when you set up or cancel a service, and domain verification with your providers. This article gives you a practical procedure, typical mistakes and a checklist for your company website.
What a dangling DNS record is and why it is a business risk
MDN describes a subdomain takeover as a situation where a subdomain has a CNAME record in DNS but no host is providing content for it, for example because the service was removed. An attacker then creates their own service with your name at the same provider and starts serving their content on your subdomain (MDN). Microsoft calls such a record a „dangling DNS“ entry and notes that CNAME records are especially vulnerable to this threat (Microsoft Learn).
The consequences are not only technical. According to Microsoft’s documentation, an attacker controlling the subdomain can obtain a valid SSL certificate for it, harvest cookies shared across subdomains or run a phishing campaign that looks trustworthy because it runs on your domain. If an MX record is left dangling, they may receive emails intended for that subdomain (Microsoft Learn).
The OWASP testing guide adds that the risk is not limited to CNAME records but also covers A, MX, NS and TXT records. In its view, an NS delegation takeover has the highest impact, because the attacker may gain control over the whole delegated zone (OWASP WSTG).
Practical example: a campaign page that outlived the campaign
Illustrative example: a marketing agency built a page at promo.company.com for a client using an external landing page tool. It added a CNAME record pointing to the provider. When the campaign ended, the company cancelled the subscription, but nobody removed the DNS record, because only the agency knew it existed.
The subdomain now points to a provider where there is no longer any page. If that provider does not require domain verification, all it takes is for someone to open an account and enter promo.company.com as their custom domain. Visitors, old links in emails and search results then lead to content you do not control.
OWASP describes two similar scenarios: a company moves its code away from GitHub but keeps the subdomain in DNS, and someone claims it through GitHub Pages. Or a CNAME points to another company domain whose registration expires, and the new owner of that domain gains control of your subdomain (OWASP WSTG).
Where forgotten records most often appear
During the inventory, look beyond the website itself at every service that has ever used your domain. The following table summarises typical situations based on the sources cited.
| Record | Typical situation | What to check |
|---|---|---|
| CNAME | Landing page, blog, help desk or test environment at an external provider | Does the target service exist and does it belong to your company? |
| A | IP address of a server or cloud service you have already cancelled | Who owns the IP address today and what runs on it? |
| MX | Mail for a subdomain at a service you no longer use | Is anyone receiving emails for this subdomain? |
| NS | Subdomain delegated to name servers of another, possibly expired domain | Is the name server domain still registered to you? |
| Wildcard *. | An asterisk record that catches any subdomain name | Is it really needed, or can it be replaced with specific records? |
Procedure: DNS inventory and safe service decommissioning
1. Get a complete export of the DNS zone
Start with a zone export from your DNS provider, not a list of subdomains someone remembers. With a zone file, you do not have to guess subdomains. For this kind of test, OWASP notes that the methodology is the same, only DNS enumeration becomes unnecessary (OWASP WSTG). Include every company domain, including old brands and domains from finished projects.
2. Assign a service and an owner to every record
MDN recommends keeping an inventory of all your organisation’s domains and their hosting providers and updating it whenever things change. Microsoft recommends a catalogue of endpoints with application owners. In practice, a table with these columns is enough: record, target, service, internal owner, contract or account, and date of last check.
3. Check that the target exists and belongs to you
Microsoft frames the check as two questions: does the service the record points to exist, and do you own it? OWASP advises paying attention when dig queries return NXDOMAIN, SERVFAIL or REFUSED, and watching for provider error pages, such as a 404 instead of your content, when you visit the subdomain. Investigate such a record the same day.
dig CNAME promo.company.com
dig NS company.com +short
4. When cancelling a service, remove the DNS record first
According to MDN, prevention is mainly a matter of the order of operations. When decommissioning a service, start by removing the DNS record and only then cancel the account or hosting. Microsoft recommends adding „remove DNS entry“ to the required checks when decommissioning any service.
5. When setting up, service and verification first, DNS last
For a new service, MDN recommends the opposite order: claim the service and the name at the provider first and create the DNS record last. If the provider offers domain verification, complete it right at the start.
6. Check regularly, not just once
OWASP recommends continuous monitoring and periodic checks. For a smaller company, a sensible minimum is a check whenever you change suppliers, when a campaign ends and at a fixed interval, for example once a quarter. With many subdomains, it pays to automate the check and send the results to the responsible person.
Domain verification with providers and wildcard records
Some providers let you verify a domain with a TXT record. GitHub states that verifying a domain for an account or organisation stops other users from publishing their own GitHub Pages site on it, including its immediate subdomains. The TXT record must stay in DNS after verification. GitHub also strongly recommends against wildcard records such as *.example.com: even with a verified domain, an attacker could still take over, for example, b.a.example.com (GitHub Docs).
The asuid TXT record in Azure App Service works in a similar way: when it exists, no other Azure subscription can validate the domain or take it over (Microsoft Learn). When choosing new services, ask the provider how it verifies that the person adding a domain is its real owner. MDN recommends making this question part of your vendor selection process.
Trade-offs and common mistakes
The main trade-off is between speed and certainty. Removing a record that something still uses can cause an outage, such as broken sign-in or undelivered emails. That is why each record needs an owner who can confirm whether the service is still running. On the other hand, keeping a record „just in case“ for a long time leaves the risk open.
- Relying on the SSL certificate. Microsoft explicitly warns that an attacker can obtain a valid certificate for a taken-over subdomain.
- Cancelling the service before removing the DNS record.
- Wildcard records for the whole domain without a clear reason.
- Subdomains created by an agency or external supplier without an entry in the company inventory.
- Checking only CNAME records and forgetting A, MX and NS.
- Deleting the verification TXT record after successful domain verification.
What to do if someone has already taken over a subdomain
MDN recommends removing the subdomain’s DNS record as the first step, in other words „cutting the power at the breaker“. If the service passes through several layers, such as a CDN and hosting, examine each layer to find where the attacker claimed the subdomain.
Microsoft further recommends investigating whether a compromise occurred, reviewing application code that references the subdomain, and finding out why nobody removed the record when the service was decommissioned. If an application sent sensitive data or credentials, such as OAuth tokens, to the subdomain, they may have been exposed to a third party. Follow your incident response plan.
Checklist for your company domain
- We have a current DNS zone export for all company domains.
- Every record has an assigned service and an internal owner.
- For every CNAME, A, MX and NS record, we know the target exists and belongs to us.
- Our service decommissioning procedure starts with removing the DNS record.
- For new services, we verify the domain with the provider and keep the verification TXT records.
- We do not use wildcard records without a clear reason.
- We repeat the check after supplier changes, after campaigns and at a fixed interval.
Frequently asked questions
Does this apply to a small company with one website?
Yes, if you have ever used external services on your own subdomain, such as a campaign page, a booking system or a help desk. The number of subdomains is usually small, so the inventory is quick.
Isn’t HTTPS on our website enough?
No. HTTPS protects the connection to a legitimate server, but it does not determine who controls the subdomain. Microsoft states that an attacker can obtain a valid certificate for a taken-over subdomain.
Who should check the DNS records?
Whoever manages DNS should work with the service owners, meaning marketing, IT and suppliers. A technical check without knowing which services are still running often leads either to an outage or to the risk being left in place.
How often should the inventory be repeated?
With every service change and at least at a regular interval you define. We recommend a quarterly check plus an extra check after a campaign ends or a supplier changes.
How we can help
As part of our website development and maintenance services, we review your DNS zone, map records to services and set a safe order of steps for changes. We can also include recurring record checks in process automation so that alerts reach the responsible person. If you want your domain reviewed, contact us via the contact form. You will find more practical guides on our blog.