Skip to content
Subdomain takeover Write-up Beginner

Subdomain Takeover Basics

The article explains that a subdomain can be taken over when its DNS CNAME record still points to a third-party cloud service that the company no longer uses, allowing anyone who registers that service name to control the subdomain. It describes a methodology for finding such subdomains at scale using Google dorks, subdomain enumeration tools, and takeover scanners.

Aishwarya Kendle Follow

Published on medium.com

In the midst of the lockdown, I and my friend Prateek Thakare decided to improve our bug bounty skills and this time we focused on a particular bug, reading a lot about it, referring POCs and then automating the vulnerability. We decided to start from Subdomain Takeoverand 0xpatrick’s blogs is what we started reading.

Aishwarya Kendle, on medium.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

This write-up is about subdomain takeover, and specifically about the part most write-ups skip: how to find vulnerable subdomains at scale. The author and a friend spent the lockdown period studying this one bug class, reading proofs of concept and then automating the search. The article describes their methodology and the tools they used, from gathering candidate domains to confirming a takeover.

The article opens with the basics. A subdomain takeover is the process of registering a non-existing domain name to gain control over another domain. The mechanism is a dangling CNAME record:

  1. Subdomains map themselves to a specific IP, or to third party services such as Azure, AWS, Heroku, Github, Fastly or Shopify, to serve content. These subdomains use a CNAME record pointing to another domain, for example xyz.company.com CNAME xyz.cloudservice.com.
  2. For whatever reason, the company stops using the service and cancels its subscription with the third party cloud provider to save money.
  3. The company forgets to update or remove the CNAME record in the DNS zone file.
  4. Because the CNAME record is still in the company.com DNS zone, anyone who registers xyz.cloudservice.com has full control over xyz.company.com for as long as the DNS record is present.
A CNAME record From the original on medium.com

The image shows a CNAME record.

Setup

The work was done by two researchers, Aishwarya Kendle and Prateek Thakare. The tooling is all public and mostly small command line utilities:

  • Google search with dorks, to find companies with a responsible disclosure or bug bounty programme.
  • A browser bookmarklet to extract URLs from the search results page.
  • tomnomnom's unfurl, to pull domains out of those URLs.
  • A shell script, enumSubdomains.sh, wrapping Sublist3r and assetfinder for subdomain enumeration.
  • subjack, a subdomain takeover scanner written in Go, and SubOver, a hostile subdomain takeover tool originally written in Python, as references for how the checking works.
  • A second shell script, subdomainTakeover.sh, combining enumeration with subjack.
  • The can-i-take-over-xyz repository, for the steps to build a proof of concept once a vulnerable subdomain is identified.
  • A DigitalOcean VPS, chosen for good speed and bandwidth during the scans.

No specific versions are given for any of the tools.

Finding it

The starting observation is that different subdomain enumeration tools give different outputs: one tool may include a subdomain that another misses. Rather than trusting a single enumerator, the researchers combined the output of several to get the best coverage. The second observation is that takeover scanners all work the same way: they check for a fingerprint, an error message returned by the cloud service for pages that are expired and therefore vulnerable to takeover. A scanner can only report what its fingerprint list knows about, so the list can be extended when a new type of takeover is found.

Exploitation

Step 1: Gathering domains with a disclosure programme

The first step was to find companies that run a responsible disclosure or bug bounty programme, using Google dorks:

Text
inurl:  /bug bountyinurl: / securityinurl: security.txtintext: responsible disclosureinurl:/security ext:txt "contact"

Once the search results were loaded, the researchers used a bookmarklet described in a separate blog post to extract the URLs from the page. The bookmarklet is a JavaScript function that scrapes the URLs present in the Google search result.

Extracting URLs from Google’s search page From the original on medium.com

The image shows extracting URLs from Google's search page.

The extracted URLs were stored in a file called urls.txt. To reduce them to domains, they used tomnomnom's unfurl:

Bash
cat alive.txt | unfurl domains >> subs.txt

This extracts the domains and stores them in a file called subs.txt. Note that the command reads from alive.txt, not from urls.txt; the article does not explain the relationship between the two files.

Step 2: Enumerating subdomains

With the domain list ready, the next step was subdomain enumeration. Because no single tool is complete, the researchers wrote a script that runs several enumerators and merges their output:

Bash
./enumSubdomains.sh subs.txt

The script enumerates subdomains using Sublist3r and assetfinder. The article notes that any other subdomain enumerator can be added and its output combined.

Step 3: Checking for takeover

To check for takeover, the researchers used subjack. As described above, the tool checks each subdomain for the fingerprint of an expired page on the cloud service it points to. The scan was run and produced a list of subdomains that are probably vulnerable, together with the cloud service each one uses.

From the original on medium.com

The enumeration and the check were then combined into a single script:

Bash
./subdomainTakeover.sh. subs.txt

Once a vulnerable subdomain was identified, the can-i-take-over-xyz repository was used to view the steps for creating a proof of concept.

Root cause

The design mistake is a dangling DNS record: a CNAME that still points at a third party resource which the organisation no longer owns or has released. The cloud provider is willing to hand that resource name to anyone who asks, so registering it transfers control of the company subdomain. The CNAME record is what keeps the hijack alive: it routes visitors of xyz.company.com to whatever the new owner of xyz.cloudservice.com serves.: the record is what routes visitors of xyz.company.com to whatever the new owner of xyz.cloudservice.com serves. The article does not describe any additional control that was bypassed.

Impact

An attacker who registers the released third party name gains full control over the affected company subdomain for as long as the DNS record remains. The article does not go further into what content could be served or which users could be affected. It does note that the researchers encountered a programme that fixed the takeover immediately after the report and marked the report as an internal known issue, which is why they advise recording the proof of concept before submitting.

Fix

The article does not describe a fix applied by any specific programme. The implied remedy follows from the root cause: remove or update the CNAME record in the DNS zone file when the third party service is no longer used, so that the subdomain no longer points at a resource someone else can claim.

Variants to test

  • Heroku and Azure: both require a credit card to be added before a custom domain name can be attached, so a positive fingerprint still means a payment step before the takeover can be completed.
  • Pantheon: requires buying a 50 dollar basic plan to add a domain name.
  • Fastly: the researchers encountered many Fastly pages and could not succeed in hijacking them. As quoted from d0xing, most are not vulnerable because the root domain has been claimed, but if Fastly is set up with a subdomain only and then released, it is vulnerable to takeover.
  • False positives: subjack sometimes reports a subdomain as vulnerable when it is not, so a hit from subjack may be a false positive..
  • Fingerprint coverage: since scanners only match known fingerprints, a subdomain pointing at a provider missing from the list will be silently skipped. You can add your own fingerprint if you have found a new type of subdomain takeover.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

Two researchers, Aishwarya Kendle and Prateek Thakare, spent the lockdown period learning one specific security bug: subdomain takeover. They read about it, studied existing proofs of concept, and then built a repeatable process to find it on a large scale. This article is their methodology, from collecting candidate companies to confirming a takeover.

Most write-ups on this bug explain what it is but skip the hard part: how do you actually find one? That gap is what this article fills.

Before any of the steps make sense, you need a few ideas explained from zero.

What is a domain and a subdomain? A domain is the name you type into a browser, like company.com. A subdomain is a name placed in front of it, like shop.company.com or blog.company.com. Companies use subdomains to separate parts of their online presence: one for the shop, one for support, one for internal tools.

What is DNS? DNS (Domain Name System) is the internet's address book. Humans remember names; computers need numeric addresses. When you type a name into your browser, a DNS lookup translates it into the address of the server that should answer. The address book is made of records, and each record is a line that says "this name goes to that place".

What is a CNAME record? CNAME stands for Canonical Name. It is a DNS record that says "this name is really just another name, go look that one up instead". It is like a mail forwarding note: post sent to your old address is redirected to your new one. If the new address stops existing, the forwarding note still sends people to a place that is no longer yours.

What is a third party cloud service? Instead of running their own servers, companies rent space from providers such as Azure, AWS, Heroku, Github, Fastly or Shopify. The company points a subdomain at the provider, and the provider serves the content.

What is subdomain takeover? It is the process of registering a non-existing domain name to gain control over another domain. In plain terms: a company points xyz.company.com at xyz.cloudservice.com, which belongs to a cloud provider. Later the company cancels its subscription, so xyz.cloudservice.com becomes free. But the forwarding note (the CNAME) is still in place. Anyone who now registers xyz.cloudservice.com at that provider inherits everything that xyz.company.com sends their way.

Here is the mechanism, step by step, as the article lays it out:

  1. Subdomains map themselves to a specific IP, or to third party services like Azure, AWS, Heroku, Github, Fastly, Shopify, etc. to serve the contents. These subdomains use a CNAME record to another domain, for example xyz.company.com CNAME xyz.cloudservice.com.
  2. For whatever reason, the company decides to stop using this service and, to save some money, cancels the subscription with the third party cloud provider.
  3. But the company forgets to update or simply remove the CNAME record in the DNS zone file.
  4. Since the CNAME record is not deleted from the company.com DNS zone, anyone who registers xyz.cloudservice.com has full control over xyz.company.com until the DNS record is present.
A CNAME record From the original on medium.com

The image shows a CNAME record.

How to find subdomain takeover?

The researchers followed a set of steps to perform this scan on a large scale. Each step is explained below, with the reason behind it.

I. Gathering RDP domains

What is a responsible disclosure or bug bounty programme? Many companies invite security researchers to report bugs to them. A responsible disclosure programme gives a contact route for doing that. A bug bounty programme goes further and pays for valid reports.

What is a Google dork? A dork is a search query that uses Google's advanced operators (words like inurl: and intext:) to find pages with particular characteristics, instead of searching for ordinary keywords. It is like asking a librarian for every book whose title contains a certain word, rather than for books about a topic.

The researchers used Google Dorks to search for companies that have a responsible disclosure program or bug bounty program:

Text
inurl:  /bug bountyinurl: / securityinurl: security.txtintext: responsible disclosureinurl:/security ext:txt "contact"

Line by line, in plain words:

  • inurl: /bug bounty asks Google for pages whose address contains the text /bug bounty.
  • inurl: / security asks for pages whose address contains / security.
  • inurl: security.txt asks for pages whose address contains security.txt, a well-known file where companies publish how to contact them about security issues.
  • intext: responsible disclosure asks for pages whose visible text contains the phrase "responsible disclosure".
  • inurl:/security ext:txt "contact" asks for text files (.txt) whose address contains /security and whose content includes the word "contact".

All of these are pasted into Google as one query. The point is to surface the security contact pages of many companies at once, so you have a list of organisations that have agreed in advance to receive reports.

Once the search results are loaded, the researchers referred a separate blog to extract the URLs from the page. That blog contains an Extraction Bookmarklet Code, which is nothing but a JavaScript function that scrapes the URLs present in the Google search result.

What is a bookmarklet? A bookmarklet is a small piece of JavaScript saved as a browser bookmark. When you click it while viewing a page, it runs the code against that page. It is like a button on your browser toolbar that does a small job for you. Here the job is: read the search results page and pull out every link.

Extracting URLs from Google’s search page From the original on medium.com

The image shows extracting URLs from Google's search page.

After extracting the URLs, they stored them in a file called urls.txt. The next problem is that a URL is a full web address, including paths and page names, while what you need for DNS work is just the domain part. To extract the domain, they used tomnomnom's unfurl tool:

Bash
cat alive.txt | unfurl domains >> subs.txt

Line by line:

  • cat alive.txt prints the contents of a file called alive.txt to the screen. The | symbol (a pipe) takes that printed output and feeds it as input to the next command instead of showing it.
  • unfurl domains is the tool that reads web addresses and keeps only the domain part of each one.
  • >> subs.txt appends the result to a file called subs.txt, creating it if it does not exist.

This will extract the domains and store them in a file called subs.txt. The command reads from alive.txt rather than urls.txt; the article does not explain how those two files relate.

II. Enumerating Subdomains

What is subdomain enumeration? It is the process of discovering which subdomains exist under a domain. A company may have mail.company.com, dev.company.com, vpn.company.com and dozens more, and many of them are not linked from the main website. Finding them is the whole game, because a takeover can only happen on a subdomain that exists and points somewhere.

During the learning period the researchers tried different subdomain enumeration tools and found out that different tools give varied outputs. Some tools might include a subdomain which the other one may not. So to get the best result, they decided to gather the output of different tools.

They wrote a script for this:

Bash
./enumSubdomains.sh subs.txt

Line by line:

  • ./ means "run the file in the current folder".
  • enumSubdomains.sh is the name of their script.
  • subs.txt is the input file, the list of domains gathered in the previous step.

They used the above script to enumerate subdomains using Sublist3r and assetfinder. You can add any other subdomain enumerator tool and combine its output.

III. Checking for takeover

What is a fingerprint? When a subdomain points at a cloud service that no longer has a matching account, the service often answers with a particular error page, for example a message saying the application is not found. That error message is the fingerprint. It is like a shop with a sign saying "this unit is vacant": the sign tells you nobody is using it, and the same sign appears on every vacant unit of that chain.

To check for takeover, there are many different tools available and all of them work similarly: the tool checks for a fingerprint, an error message provided by the cloud service for pages that are expired and are vulnerable to takeover. You can add your fingerprint if you have found a new type of subdomain takeover. That last point matters: a scanner can only recognise the providers whose fingerprints it already knows, so a new kind of takeover needs a new fingerprint added to the list.

The article points to two tools, subjack (a subdomain takeover tool written in Go) and SubOver (a hostile subdomain takeover tool originally written in Python), as references for how the checking works.

They used subjack and it gave the result as follows:

From the original on medium.com

It gave them the subdomains which are probably vulnerable and the cloud service that they are using.

Combining the above script with subjack gives:

Bash
./subdomainTakeover.sh. subs.txt

Line by line:

  • ./ runs the file in the current folder.
  • subdomainTakeover.sh. is the name of their combined script, written exactly as it appears in the article, with the trailing dot.
  • subs.txt is the input file, the list of domains.

Once a subdomain has been identified which is vulnerable, the following repository can be used to view the steps for creating a POC.

What is a POC? POC stands for proof of concept. It is a small, safe demonstration that the problem is real, for example a harmless page you control appearing on the company's subdomain. It is like showing a locksmith that your key opens the door, rather than just claiming it does. The can-i-take-over-xyz repository collects, for each cloud provider, the steps needed to build that demonstration.

Some tips that will help you when you encounter a vulnerable subdomain

  1. The subjack tool sometimes gives a false-positive result. A false positive is a warning that turns out to be wrong, like a smoke alarm going off because of toast.
  2. For more information and POC, refer to the 0xpatrick and m7mdharoun blogs.
  3. Make sure you record the POC and then submit the report. The researchers encountered a program who fixed the takeover immediately after reporting and marked their report as an internal known issue.
  4. Heroku and Azure require a Credit Card to be added to add a custom domain name. So a takeover on those providers requires a credit card to be added.
  5. Pantheon requires you to buy a 50 dollar basic plan to add a domain name.
  6. They encountered many Fastly pages and could not succeed in hijacking them. But as mentioned by d0xing, most are not vulnerable because they've claimed their root domain, but if you setup fastly with a subdomain only and release it, it is vulnerable to takeover.
  7. They used a DigitalOcean VPS which gave them good speed and bandwidth. What is a VPS? A virtual private server is a rented computer in a data centre that you control remotely. Running scans from such a machine is faster and more reliable than running them from a home connection.

Glossary

  • Assetfinder: a tool that finds subdomains related to a domain.
  • Azure: a cloud computing service from Microsoft, one of the third party providers a subdomain can point at.
  • AWS: Amazon Web Services, a cloud computing provider.
  • Bookmarklet: a small JavaScript program saved as a browser bookmark and run against the page you are viewing.
  • Bug bounty programme: a scheme where a company pays researchers for valid security reports.
  • CNAME record: a DNS record that says one name is an alias for another name, so lookups are redirected to the second name.
  • DNS: the internet's naming system that translates domain names into the addresses computers use.
  • DNS zone file: the file that holds the DNS records for a domain.
  • Domain: a name such as company.com that identifies a place on the internet.
  • Dork: a Google search query using advanced operators to find pages with specific characteristics.
  • False positive: a warning that turns out to be wrong.
  • Fastly: a content delivery network provider, one of the third party services a subdomain can point at.
  • Fingerprint: the distinctive error message a cloud service returns for an expired page, used by scanners to spot takeovers.
  • Github: a code hosting service, also usable to serve pages, one of the third party services a subdomain can point at.
  • Heroku: a cloud application platform, one of the third party services a subdomain can point at.
  • IP address: the numeric address of a machine on a network.
  • Pantheon: a website management platform, one of the third party services a subdomain can point at.
  • POC (proof of concept): a small, safe demonstration that a vulnerability is real.
  • Responsible disclosure programme: a scheme where a company gives researchers a contact route to report security issues.
  • Shopify: an e-commerce platform, one of the third party services a subdomain can point at.
  • Subdomain: a name placed in front of a domain, such as shop.company.com.
  • Subdomain enumeration: the process of discovering which subdomains exist under a domain.
  • Subdomain takeover: registering a non-existing domain name to gain control over another domain that still points at it.
  • Subjack: a subdomain takeover scanner written in Go.
  • Sublist3r: a tool that enumerates subdomains.
  • SubOver: a hostile subdomain takeover tool originally written in Python.
  • Unfurl: a tool that pulls parts, such as the domain, out of web addresses.
  • URL: a full web address, including the domain and the path to a page.
  • VPS: a virtual private server, a rented machine in a data centre that you control remotely.

Similar reports

View all

Same bug class and techniques, clearest first.

Subdomain takeover

The lesson behind this report.

A company's DNS still points at a cloud service it no longer uses, so anyone can claim it and serve content on the company's domain.