Skip to content
Subdomain takeover Write-up Intermediate

How I found my first Subdomain Takeover vulnerability

A subdomain pointed via a CNAME record to a third-party hosting service that no longer claimed it, so the researcher could register a new site there and serve their own content on the company's subdomain. Because the main host's CORS policy trusted any subdomain, the taken-over subdomain could then be used to make cross-site requests and read responses on behalf of logged-in users.

Monish Basaniwal Follow

Published on monish-basaniwal.medium.com

Bounty$375 View original

Finding your very first vulnerability as a newbie security researcher can be really intimidating and can easily burn you out especially when you don’t know where to start from. Read on to know how I managed to find a Subdomain Takeover vulnerability and how I was able to leverage that into a CSRF attack with the…

Monish, on monish-basaniwal.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. 6 min read.

Context

This is an account of a first subdomain takeover, found on a private programme on Intigriti, and then extended into a CSRF scenario. The report is titled Subdomain Takeover + CSRF, with the scope listed as Other/ Subdomain Takeover, the payout as €375, the resolution date as 06/07/2021 and the severity as High.

The affected asset was a subdomain written in the report as explore.*****.com. The subdomain had a CNAME record pointing at a Netlify DNS server, and the third party service behind it no longer had a site attached to that name. That is the condition a subdomain takeover needs: a DNS record that still delegates a name to a provider where nobody has claimed the name.

From the original on monish-basaniwal.medium.com

Setup

The only precondition the report stresses is scope. Subdomain takeovers are normally only treated as valid reports when the programme allows a wildcard domain name, for example a scope entry containing .example.com. The author notes that a few programmes may still accept a submission without it, so it is worth trying anyway.

The tools used were:

  1. Subfinder to enumerate subdomains of the target. The report also mentions Virustotal and Spyse as online alternatives.
  2. Medic or HTTPStatus to check which subdomains return a 404 response.
  3. The Can I Take Over XYZ repository by Ed from Live Overflow, which lists third party services together with their error messages and whether they are vulnerable: https://github.com/EdOverflow/can-i-take-over-xyz

No versions are given for any of these tools.

Finding it

The recon started with enumerating every subdomain of the master domain under scope. The Subfinder scan returned 175 enumerated subdomains.

The next step was to scan those subdomains for a 404 response, on the reasoning that a 404 marks a subdomain that is potentially exploitable. That filter returned 12 subdomains out of the 175.

Each of the 12 was then visited by hand to inspect the error message returned by the attached service, because the 404 page is what identifies the provider and whether the name can be claimed. The Can I Take Over XYZ list is used at this point to match the error message against a known service.

Before consulting the list, the report says, you first need to verify that the subdomain has a CNAME record pointing to a dead third party service page. In this case explore.*****.com was pointing to a Netlify DNS server.

From the original on monish-basaniwal.medium.com

Exploitation

Step 1: Claim the name at the provider

Netlify had fixed subdomain takeovers some time before, according to the report: it now verifies ownership of the website, and Netlify site names automatically get a random number appended to make them unique. In this case there were no unique numbers, so the author was able to create a new Netlify site and attach explore.*****.com to it. Content was then served on that subdomain.

From the original on monish-basaniwal.medium.com

Step 2: Keep the proof of concept contained

The report gives three rules for the proof of concept:

  1. Never serve the PoC on the index of the subdomain. Hide it behind an unguessable file name; in this case the author used oc-2bdg3erf2i6td.html.
  2. No login page. Never recreate the company's login page as a PoC.
  3. No funny business. Keep the PoC message minimal, with no memes or GIFs.

Step 3: Turn the takeover into a CSRF

Reporting the takeover on its own, the report argues, risks being marked as Low severity because there is no loss of confidentiality. The next step is therefore to think like an attacker and work out how the taken-over subdomain can be used against accounts.

The mechanism used here is CORS. CORS is the web mechanism that stops unauthorised websites from sending requests on behalf of a victim to a site and reading or changing data. On this programme's host, the CORS header used a subdomain wildcard, *.programhost.com, which means cross-site requests from any of its subdomains were allowed, with full access to its resources.

The attack the report describes: the attacker recreates the company's login page, lures victims in, lets them log in with their credentials, and then makes a request to the login endpoint of the application. Because of the CORS policy, the response is readable, so the attacker could steal the cookies the server sends back, act as the user, read credit card information, and send back malware or a script.

This was verified by sending a request to one of the endpoints of the main host, which returned the header:

HTTP
access-control-allow-origin: https://explore.******.com

That response confirms the main host allowed the request from the taken-over subdomain.

Root cause

Two separate mistakes combine here.

At the DNS and provider level, the subdomain kept a CNAME pointing at Netlify where no site was attached to the name. Netlify's ownership verification and the random suffix on site names are the defences against this; the report states there were no unique numbers on the name, and the site could be created and attached.

At the application level, the CORS policy trusted the whole subdomain namespace through the wildcard *.programhost.com. That makes every subdomain, including one an outsider can claim at a third party provider, an origin the application will answer with its resources. The report does not describe any other control that would have limited this.

Impact

The report lists the impact of the subdomain takeover as:

  1. Representing the company in various wrong ways.
  2. XSS attacks.
  3. Authentication bypass.
  4. Phishing and spear phishing.

Combined with the CORS wildcard, the report describes a path to account takeover: a victim who logs in through the attacker's page could have their cookies and other data read, and the attacker could act as that user. These outcomes depend on the victim being lured to the attacker's page and logging in there, as described in the report.

Fix

The report does not say what the programme changed after the report was resolved. The measures it implies are: remove DNS records that point at third party services no longer in use, and stop trusting an entire subdomain namespace in CORS policy, since any subdomain that can be claimed at a provider becomes a trusted origin.

Variants to test

  1. Other providers on the Can I Take Over XYZ list. Enumerate subdomains, filter for 404 responses, then match the error page against the list. A positive result is a provider error page for an unclaimed name, plus a CNAME pointing at that provider.
  2. CORS wildcards on subdomains. Look for access-control-allow-origin values that reflect any subdomain of the target, or a wildcard over the subdomain namespace. A positive result is a response to a request from a subdomain you control that carries that origin in the header.
  3. Takeover plus credentialed endpoints. Once a subdomain is claimed, request an authenticated endpoint of the main host from it. A positive result is a readable response, which turns the takeover into data theft rather than defacement.
  4. Unclaimed names without a 404. The report's filter relies on 404 responses, so names that answer differently, for example with a provider-specific error page, are worth checking by hand against the same list.

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. 13 min read.

What happened, in plain words

A security researcher found a way to take control of one of a company's subdomains, a name like explore.example.com that belongs to the company but sits under its main domain. The subdomain was pointing at a third-party website hosting service called Netlify, but nobody had claimed that name at Netlify any more. Because of that, the researcher could sign up at Netlify, create a new site, and attach the company's subdomain to it. From then on, anything the researcher put on that site was served at the company's own address.

That alone is a problem, but the researcher went further. So, as the report describes, a page on the taken-over subdomain could ask the main site for data on behalf of a logged-in visitor and read the answer. The researcher showed this by sending a request and getting back a header that confirmed the trust. In the report, this combination was rated High severity and paid €375.

The rest of this article walks through the same steps the researcher took, explaining each idea from scratch.

The report at a glance

The report is titled Subdomain Takeover + CSRF. It was submitted on a private programme on the bug bounty platform Intigriti. The scope was listed as Other/ Subdomain Takeover, the payout was €375, the date resolved was 06/07/2021, and the severity was High.

The affected asset was a subdomain of the programme's main host, written in the report as explore.*****.com. That subdomain had a DNS record of type CNAME pointing at a Netlify DNS server, and the third-party service behind it no longer had a site attached to that name. That is exactly the condition a subdomain takeover needs: a DNS record that still hands a name to a provider where nobody has claimed the name.

From the original on monish-basaniwal.medium.com

The ideas you need first

Before the steps make sense, here are the basic concepts, each with a simple comparison.

  • Domain and subdomain. A domain is the main address of a website, like example.com. A subdomain is a name placed in front of it, like shop.example.com or explore.example.com. Think of the domain as a building and subdomains as different rooms with their own door numbers.
  • DNS. The Domain Name System is the internet's address book. When you type a name into your browser, DNS translates it into the address of a server. A CNAME record is a special entry in that address book that says "this name is an alias for that other name". It is like a mail forwarding note: letters for explore.example.com are forwarded to something.netlify.com.
  • Third-party hosting service. A company that hosts websites for other people, such as Netlify. You create a site there, and it gives you a name and space to serve your pages.
  • Subdomain takeover. This happens when a subdomain still points (via DNS) at a third-party service, but the site at that service has been deleted or never claimed. Anyone who can create a site at that service under the same name can then serve their own content at the company's subdomain. It is like a forwarding note that still sends mail to an empty apartment: whoever moves in gets the mail.
  • HTTP status codes. When your browser asks a web server for a page, the server replies with a number. 404 means "not found". In this context, a 404 on a subdomain is a hint that the page behind it is missing and might be claimable.
  • CORS (Cross-Origin Resource Sharing). A rule that browsers follow to decide whether a web page from one site is allowed to read data from another site. Normally, a page on site-a.com cannot read responses from site-b.com. CORS lets site-b.com say "I trust pages from this other origin, so they may read my data". Think of it as a guest list at a club: only people on the list (trusted origins) get in.
  • CSRF (Cross-Site Request Forgery). An attack where a malicious page makes a victim's browser send a request to another site where the victim is logged in, without the victim intending it. If the target site trusts the malicious page (for example through a loose CORS policy), the attacker can read the response and steal data. It is like someone using your logged-in session at a bank to transfer money without you knowing.
  • Cookie. A small piece of data a website stores in your browser to remember who you are. Session cookies are like a temporary ID card: if someone steals it, they can act as you until it expires.
  • Endpoint. A specific URL on a web application that performs an action or returns data, for example a login endpoint or a profile endpoint. Think of it as a particular counter at a service desk.
  • API. An interface that lets one piece of software talk to another. Web APIs are often accessed through endpoints. It is like a waiter: you tell the waiter what you want, and the waiter brings it from the kitchen.
  • Header. Extra information sent along with an HTTP request or response. The access-control-allow-origin header is part of CORS: it tells the browser which origins are allowed to read the response.
  • Wildcard. A symbol (*) that stands for "anything". In a scope like *.example.com, it means every subdomain of example.com. In a CORS policy, *.programhost.com means every subdomain of programhost.com is trusted.

Setup: what you need and why

The report stresses one precondition: scope. Bug bounty programmes define what you are allowed to test. Subdomain takeovers are normally only treated as valid reports when the programme allows a wildcard domain name, for example a scope entry containing .example.com. The author notes that a few programmes may still accept a submission without it, so it is worth trying anyway.

The tools used were:

  1. Subfinder to enumerate subdomains of the target. The report also mentions Virustotal and Spyse as online alternatives.
  2. Medic or HTTPStatus to check which subdomains return a 404 response.
  3. The Can I Take Over XYZ repository by Ed from Live Overflow, which lists third-party services together with their error messages and whether they are vulnerable: https://github.com/EdOverflow/can-i-take-over-xyz

No versions are given for any of these tools.

Why these tools? Subfinder automates the tedious job of finding subdomains. Medic and HTTPStatus quickly filter the list to those that look broken. The Can I Take Over XYZ list is a reference that matches an error page to a provider and tells you if that provider is known to allow takeovers.

Finding it: step by step

The recon started with enumerating every subdomain of the master domain under scope. The Subfinder scan returned 175 enumerated subdomains.

Why enumerate? You cannot test what you do not know exists. Many companies have dozens or hundreds of subdomains, some forgotten.

The next step was to scan those subdomains for a 404 response, on the reasoning that a 404 marks a subdomain that is potentially exploitable. That filter returned 12 subdomains out of the 175.

Why 404? A 404 means the server is reachable but the page is missing. On a subdomain pointing to a third-party service, that often means the site that used to be there is gone, which is the first sign of a takeover opportunity.

Each of the 12 was then visited by hand to inspect the error message returned by the attached service, because the 404 page is what identifies the provider and whether the name can be claimed. The Can I Take Over XYZ list is used at this point to match the error message against a known service.

Why by hand? Automated tools can miss context. The exact wording of an error page often names the provider, and the list tells you if that provider is known to be vulnerable.

Before consulting the list, the report says, you first need to verify that the subdomain has a CNAME record pointing to a dead third-party service page. In this case explore.*****.com was pointing to a Netlify DNS server.

Why check the CNAME? The CNAME is the forwarding note. If it points to a provider and the provider says the name is unclaimed, then you have a takeover candidate. Without the CNAME, a 404 might just be a broken page on the company's own server.

From the original on monish-basaniwal.medium.com

Exploitation

Step 1: Claim the name at the provider

Netlify had fixed subdomain takeovers some time before, according to the report: it now verifies ownership of the website, and Netlify site names automatically get a random number appended to make them unique. In this case there were no unique numbers, so the author was able to create a new Netlify site and attach explore.*****.com to it. Content was then served on that subdomain.

Why does the random number matter? If Netlify appends a random suffix to every site name, then an attacker cannot guess or claim the exact name that the CNAME points to. Here, the name had no such suffix, so it could be claimed.

From the original on monish-basaniwal.medium.com

Step 2: Keep the proof of concept contained

The report gives three rules for the proof of concept (PoC), the demonstration that the vulnerability is real:

  1. Never serve the PoC on the index of the subdomain. Hide it behind an unguessable file name; in this case the author used oc-2bdg3erf2i6td.html.
  2. No login page. Never recreate the company's login page as a PoC.
  3. No funny business. Keep the PoC message minimal, with no memes or GIFs.

Why these rules? Serving at the index (the main page) would be visible to anyone and could be mistaken for defacement. An unguessable file name means only people you share the link with can see it. Recreating a login page crosses into phishing, which is harmful and can get you into trouble. Keeping it minimal shows you are reporting a flaw, not attacking users.

Step 3: Turn the takeover into a CSRF

Reporting the takeover on its own, the report argues, risks being marked as Low severity because there is no loss of confidentiality. The next step is therefore to think like an attacker and work out how the taken-over subdomain can be used against accounts.

Why think like an attacker? Bug bounty programmes often rate severity by impact. A takeover that only lets you show a message is less serious than one that lets you steal data. Showing the path to account takeover raises the severity.

The mechanism used here is CORS. CORS is the web mechanism that stops unauthorised websites from sending requests on behalf of a victim to a site and reading or changing data. On this programme's host, the CORS header used a subdomain wildcard, *.programhost.com, which means cross-site requests from any of its subdomains were allowed, with full access to its resources.

Why is that dangerous? Because the attacker now controls one of those subdomains. The wildcard trusts every subdomain, including the taken-over one. So a page on the taken-over subdomain can read data from the main site as if it were a trusted part of the company.

The attack the report describes: the attacker recreates the company's login page, lures victims in, lets them log in with their credentials, and then makes a request to the login endpoint of the application. Because of the CORS policy, the response is readable, so the attacker could steal the cookies the server sends back, act as the user, read credit card information, and send back malware or a script.

This was verified by sending a request to one of the endpoints of the main host, which returned the header:

HTTP
access-control-allow-origin: https://explore.******.com

Line by line:

  • access-control-allow-origin is the CORS response header that tells the browser which origin is allowed to read the response.
  • https://explore.******.com is the origin (the taken-over subdomain) that the main host is allowing. The asterisks hide the real name.

So the main host is saying: "I trust requests from https://explore.******.com and will let them read my responses." Since the attacker controls that subdomain, the attacker can read responses.

That response confirms the main host allowed the request from the taken-over subdomain.

Root cause

Two separate mistakes combine here.

At the DNS and provider level, the subdomain kept a CNAME pointing at Netlify where no site was attached to the name. Netlify's ownership verification and the random suffix on site names are the defences against this; the report states there were no unique numbers on the name, and the site could be created and attached.

At the application level, the CORS policy trusted the whole subdomain namespace through the wildcard *.programhost.com. That makes every subdomain, including one an outsider can claim at a third-party provider, an origin the application will answer with its resources. The report does not describe any other control that would have limited this.

Impact

The report lists the impact of the subdomain takeover as:

  1. Representing the company in various wrong ways.
  2. XSS attacks.
  3. Authentication bypass.
  4. Phishing and spear phishing.

Combined with the CORS wildcard, the report describes a path to account takeover: a victim who logs in through the attacker's page could have their cookies and other data read, and the attacker could act as that user. These outcomes depend on the victim being lured to the attacker's page and logging in there, as described in the report.

Fix

The report does not say what the programme changed after the report was resolved. The measures it implies are: remove DNS records that point at third-party services no longer in use, and stop trusting an entire subdomain namespace in CORS policy, since any subdomain that can be claimed at a provider becomes a trusted origin.

Variants to test

  1. Other providers on the Can I Take Over XYZ list. Enumerate subdomains, filter for 404 responses, then match the error page against the list. A positive result is a provider error page for an unclaimed name, plus a CNAME pointing at that provider.
  2. CORS wildcards on subdomains. Look for access-control-allow-origin values that reflect any subdomain of the target, or a wildcard over the subdomain namespace. A positive result is a response to a request from a subdomain you control that carries that origin in the header.
  3. Takeover plus credentialed endpoints. Once a subdomain is claimed, request an authenticated endpoint of the main host from it. A positive result is a readable response, which turns the takeover into data theft rather than defacement.
  4. Unclaimed names without a 404. The report's filter relies on 404 responses, so names that answer differently, for example with a provider-specific error page, are worth checking by hand against the same list.

Glossary

  • API: An interface that lets one piece of software talk to another, often over the web.
  • CNAME record: A DNS entry that says one name is an alias for another.
  • Cookie: A small piece of data stored in your browser by a website, often used to remember who you are.
  • CORS (Cross-Origin Resource Sharing): A browser mechanism that controls whether a page from one site can read data from another site.
  • CSRF (Cross-Site Request Forgery): An attack that makes a victim's browser send an unintended request to a site where they are logged in.
  • DNS (Domain Name System): The internet's address book, translating names to server addresses.
  • Endpoint: A specific URL on a web application that performs an action or returns data.
  • Header: Extra information sent with an HTTP request or response.
  • HTTP status code: A number a server returns to indicate the result of a request, such as 404 for not found.
  • PoC (Proof of Concept): A demonstration that a vulnerability is real, often a small harmless example.
  • Subdomain: A name placed in front of a domain, like shop.example.com.
  • Subdomain takeover: Taking control of a subdomain by claiming an unclaimed name at a third-party service that the subdomain points to.
  • Wildcard: A symbol (*) that stands for any value, used in scopes and policies.
  • XSS (Cross-Site Scripting): An attack that injects malicious scripts into web pages viewed by others.

More by Monish Basaniwal

View all

2 more disclosed reports, best first.

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.