Azure App Services Subdomain Takeover
Introduction
Azure Web Apps enables you to build and host web applications in the programming language of your choice without managing infrastructure. It offers auto-scaling and high availability, supports both Windows and Linux, and enables automated deployments from GitHub, Azure DevOps, or any Git repo.
What are we going to cover?
We will look at how we can
Identify a domain belonging to a target that is vulnerable to a subdomain takeover
Use the information we collect to create an Azure App Service to take over the subdomain
Please note: This chapter requires the existence of CNAMES that do not point to anything (dangling CNAMES). Best to read through this chapter as we will not be able to create CNAMES for everyone trying is exercise outisde a classroom setting. Take a look at the references at the bottom of this page for a real world example.
Steps to Identify a vulnerable subdomain
The following steps can be used to identify a subdomain that is potentially vulnerable to a subdomain takeover
Our target domain is
galaxybutter.co
.While doing reconnaissance, a sub domain was discovered,
users.galaxybutter.co
Browse to this sub domain at
https://users.galaxybutter.co
and notice the errorPerform a DNS A query to identify the IP address of this sub domain using
dig A users.galaxybutter.co
. Notice the NXDOMAIN response. This means that there is no such domain.Perform a DNS CNAME lookup using
dig CNAME users.galaxybutter.co
The CNAME points to an Azure App Service that was probably deprecated/removed
An attacker can now create an Azure App service with the same name and host phishing content, resulting in a sub domain takeover
Steps to create an App Service
We will work in groups for this.
Steps to hijack the sub domain
This is essentially two steps from here
Configure the App Service name to point to the subdomain
Add custom content to the site to show its been taken over
Creat an App Service and point it to the missing CNAME
In the Azure Portal, click on
All Services
and search forApp Services
.Click on
Add
and select the most basic app from the Web window that opens.Click on
Create
.Provide the App name as
XXXXXXXXXX
. ReplaceXXXXXXXXXX
with your team name. The App will be hosted atXXXXXXXXXX.azurewebsites.net
Select Runtime Stack as PHP 7.3. Any stack could be chosen here, but since our objective is to show subdomain takeover, it doesn't really matter for this Proof of Concept.
Under
Sku and size
selectDev/Test > F1
Click
Create
. If you receive an error, check the raw message's bottom most json body.Once the App Service is created, go to its dashboard and under
Overview
click onBrowse
to see the deployment.
Add a custom domain to the App Service
In the dashboard, scroll down to find
Custom domains
Click on
Add hostname
and typeXXXXXXXXXX.galaxybutter.co
. ReplaceXXXXXXXXXX
with your team name.Click on
Validate
Click on
Add hostname
to complete the configurationReload
https://XXXXXXXXXX.galaxybutter.co
and check if the takeover is complete.
Show custom content
A deployment of a web application in the Azure App Service is beyond the scope of this training, however to show a Proof of Concept, we can simply update the index page shown when you browse to
https://XXXXXXXXXX.galaxybutter.co
In the dashboard of the App Service, scroll down and click on
SSH
. Click on Go to launch the SSH shell for the App Service container.Navigate to the
/var/www/html
folder and run the following command to create a simple file containing our textecho Subdomain takeover example. > index.html
Reload the sub domain URL to see your message.
Finding Subdomain takeover at scale using FDNS Dataset (DEMO)
Forward DNS dataset is published as part of Project Sonar. This data is created by extracting domain names from a number of sources and then sending DNS queries for each domain. The data format is a gzip-compressed JSON file. We can parse the dataset to find sub-domains for a given domain.
The project also publishes CNAME records they have enumerated across the Internet. We can use this CNAME dataset to identify potential subdomain takeover issues across the Internet.
https://opendata.rapid7.com/sonar.fdns_v2/
Find Azure Websites using FDNS dataset
Find AWS S3 based applications using FDNS dataset
Additional References
Last updated