Prevent subdomain takeovers with Azure DNS alias records and Azure App Service's custom domain verification (2024)

  • Article

This article describes the common security threat of subdomain takeover and the steps you can take to mitigate against it.

What is a subdomain takeover?

Subdomain takeovers are a common, high-severity threat for organizations that regularly create, and delete many resources. A subdomain takeover can occur when you have a DNS record that points to a deprovisioned Azure resource. Such DNS records are also known as "dangling DNS" entries. CNAME records are especially vulnerable to this threat. Subdomain takeovers enable malicious actors to redirect traffic intended for an organization's domain to a site performing malicious activity.

A common scenario for a subdomain takeover:

  1. CREATION:

    1. You provision an Azure resource with a fully qualified domain name (FQDN) of app-contogreat-dev-001.azurewebsites.net.

    2. You assign a CNAME record in your DNS zone with the subdomain greatapp.contoso.com that routes traffic to your Azure resource.

  2. DEPROVISIONING:

    1. The Azure resource is deprovisioned or deleted after it is no longer needed.

      At this point, the CNAME record greatapp.contoso.com should be removed from your DNS zone. If the CNAME record isn't removed, it's advertised as an active domain but doesn't route traffic to an active Azure resource. You now have a "dangling" DNS record.

    2. The dangling subdomain, greatapp.contoso.com, is now vulnerable and can be taken over by being assigned to another Azure subscription's resource.

  3. TAKEOVER:

    1. Using commonly available methods and tools, a threat actor discovers the dangling subdomain.

    2. The threat actor provisions an Azure resource with the same FQDN of the resource you previously controlled. In this example, app-contogreat-dev-001.azurewebsites.net.

    3. Traffic being sent to the subdomain greatapp.contoso.com is now routed to the malicious actor's resource where they control the content.

Prevent subdomain takeovers with Azure DNS alias records and Azure App Service's custom domain verification (1)

The risks of subdomain takeover

When a DNS record points to a resource that isn't available, the record itself should be removed from your DNS zone. If it isn't deleted, it's a "dangling DNS" record and creates the possibility for subdomain takeover.

Dangling DNS entries make it possible for threat actors to take control of the associated DNS name to host a malicious website or service. Malicious pages and services on an organization's subdomain might result in:

  • Loss of control over the content of the subdomain - Negative press about your organization's inability to secure its content, brand damage, and loss of trust.

  • Cookie harvesting from unsuspecting visitors - It's common for web apps to expose session cookies to subdomains (*.contoso.com). Any subdomain can access them. Threat actors can use subdomain takeover to build an authentic looking page, trick unsuspecting users to visit it, and harvest their cookies (even secure cookies). A common misconception is that using SSL certificates protects your site, and your users' cookies, from a takeover. However, a threat actor can use the hijacked subdomain to apply for and receive a valid SSL certificate. Valid SSL certificates grant them access to secure cookies and can further increase the perceived legitimacy of the malicious site.

  • Phishing campaigns - Malicious actors often exploit authentic-looking subdomains in phishing campaigns. The risk extends to both malicious websites and MX records, which could enable threat actors to receive emails directed to legitimate subdomains associated with trusted brands.

  • Further risks - Malicious sites might be used to escalate into other classic attacks such as XSS, CSRF, CORS bypass, and more.

Identify dangling DNS entries

To identify DNS entries within your organization that might be dangling, use Microsoft's GitHub-hosted PowerShell tools "Get-DanglingDnsRecords".

This tool helps Azure customers list all domains with a CNAME associated to an existing Azure resource that was created on their subscriptions or tenants.

If your CNAMEs are in other DNS services and point to Azure resources, provide the CNAMEs in an input file to the tool.

The tool supports the Azure resources listed in the following table. The tool extracts, or takes as inputs, all the tenant's CNAMEs.

ServiceTypeFQDNpropertyExample
Azure Front Doormicrosoft.network/frontdoorsproperties.cNameabc.azurefd.net
Azure Blob Storagemicrosoft.storage/storageaccountsproperties.primaryEndpoints.blobabc.blob.core.windows.net
Azure CDNmicrosoft.cdn/profiles/endpointsproperties.hostNameabc.azureedge.net
Public IP addressesmicrosoft.network/publicipaddressesproperties.dnsSettings.fqdnabc.EastUs.cloudapp.azure.com
Azure Traffic Managermicrosoft.network/trafficmanagerprofilesproperties.dnsConfig.fqdnabc.trafficmanager.net
Azure Container Instancemicrosoft.containerinstance/containergroupsproperties.ipAddress.fqdnabc.EastUs.azurecontainer.io
Azure API Managementmicrosoft.apimanagement/serviceproperties.hostnameConfigurations.hostNameabc.azure-api.net
Azure App Servicemicrosoft.web/sitesproperties.defaultHostNameabc.azurewebsites.net
Azure App Service - Slotsmicrosoft.web/sites/slotsproperties.defaultHostNameabc-def.azurewebsites.net

Prerequisites

Run the query as a user who has:

  • at least reader level access to the Azure subscriptions
  • read access to Azure resource graph

If you're a Global Administrator of your organization's tenant, follow the guidance in Elevate access to manage all Azure subscriptions and management groups to gain access to all your organization's subscriptions

Tip

Azure Resource Graph has throttling and paging limits that you should consider if you have a large Azure environment.

Learn more about working with large Azure resource data sets.

The tool uses subscription batching to avoid these limitations.

Run the script

Learn more about the PowerShell script, Get-DanglingDnsRecords.ps1, and download it from GitHub: https://aka.ms/Get-DanglingDnsRecords.

Review your DNS zones and identify CNAME records that are dangling or taken over. If subdomains are found to be dangling or have been taken over, remove the vulnerable subdomains and mitigate the risks with the following steps:

  1. From your DNS zone, remove all CNAME records that point to FQDNs of resources no longer provisioned.

  2. To enable traffic to be routed to resources in your control, provision more resources with the FQDNs specified in the CNAME records of the dangling subdomains.

  3. Review your application code for references to specific subdomains and update any incorrect or outdated subdomain references.

  4. Investigate whether any compromise occurred and take action per your organization's incident response procedures. Tips and best practices for investigating:

    If your application logic results in secrets, such as OAuth credentials, being sent to dangling subdomains or if privacy-sensitive information is transmitted to those subdomains, there is a possibility for this data to be exposed to third parties.

  5. Understand why the CNAME record was not removed from your DNS zone when the resource was deprovisioned and take steps to ensure that DNS records are updated appropriately when Azure resources are deprovisioned in the future.

Prevent dangling DNS entries

Ensuring that your organization has implemented processes to prevent dangling DNS entries and the resulting subdomain takeovers is a crucial part of your security program.

Some Azure services offer features to aid in creating preventative measures and are detailed below. Other methods to prevent this issue must be established through your organization's best practices or standard operating procedures.

Enable Microsoft Defender for App Service

Microsoft Defender for Cloud's integrated cloud workload protection platform (CWPP) offers a range of plans to protect your Azure, hybrid, and multicloud resources and workloads.

The Microsoft Defender for App Service plan includes dangling DNS detection. With this plan enabled, you'll get security alerts if you decommission an App Service website but don't remove its custom domain from your DNS registrar.

Microsoft Defender for Cloud's dangling DNS protection is available whether your domains are managed with Azure DNS or an external domain registrar and applies to App Service on both Windows and Linux.

Learn more about this and other benefits of this Microsoft Defender plans in Introduction to Microsoft Defender for App Service.

Use Azure DNS alias records

Azure DNS's alias records can prevent dangling references by coupling the lifecycle of a DNS record with an Azure resource. For example, consider a DNS record that's qualified as an alias record to point to a public IP address or a Traffic Manager profile. If you delete those underlying resources, the DNS alias record becomes an empty record set. It no longer references the deleted resource. It's important to note that there are limits to what you can protect with alias records. Today, the list is limited to:

  • Azure Front Door
  • Traffic Manager profiles
  • Azure Content Delivery Network (CDN) endpoints
  • Public IPs

Despite the limited service offerings today, we recommend using alias records to defend against subdomain takeover whenever possible.

Learn more about the capabilities of Azure DNS's alias records.

Use Azure App Service's custom domain verification

When creating DNS entries for Azure App Service, create an asuid.{subdomain} TXT record with the Domain Verification ID. When such a TXT record exists, no other Azure Subscription can validate the Custom Domain that is, take it over.

These records don't prevent someone from creating the Azure App Service with the same name that's in your CNAME entry. Without the ability to prove ownership of the domain name, threat actors can't receive traffic or control the content.

Learn more about how to map an existing custom DNS name to Azure App Service.

Build and automate processes to mitigate the threat

It's often up to developers and operations teams to run cleanup processes to avoid dangling DNS threats. The practices below will help ensure your organization avoids suffering from this threat.

  • Create procedures for prevention:

    • Educate your application developers to reroute addresses whenever they delete resources.

    • Put "Remove DNS entry" on the list of required checks when decommissioning a service.

    • Put delete locks on any resources that have a custom DNS entry. A delete lock serves as an indicator that the mapping must be removed before the resource is deprovisioned. Measures like this can only work when combined with internal education programs.

  • Create procedures for discovery:

    • Review your DNS records regularly to ensure that your subdomains are all mapped to Azure resources that:

      • Exist - Query your DNS zones for resources pointing to Azure subdomains such as *.azurewebsites.net or *.cloudapp.azure.com (see the Reference list of Azure domains).
      • You own - Confirm that you own all resources that your DNS subdomains are targeting.
    • Maintain a service catalog of your Azure fully qualified domain name (FQDN) endpoints and the application owners. To build your service catalog, run the following Azure Resource Graph query script. This script projects the FQDN endpoint information of the resources you have access to and outputs them in a CSV file. If you have access to all the subscriptions for your tenant, the script considers all those subscriptions as shown in the following sample script. To limit the results to a specific set of subscriptions, edit the script as shown.

  • Create procedures for remediation:

    • When dangling DNS entries are found, your team needs to investigate whether any compromise has occurred.
    • Investigate why the address wasn't rerouted when the resource was decommissioned.
    • Delete the DNS record if it's no longer in use, or point it to the correct Azure resource (FQDN) owned by your organization.

Clean up DNS pointers or Re-claim the DNS

Upon deletion of the classic cloud service resource, the corresponding DNS is reserved as per Azure DNS policies. During the reservation period, re-use of the DNS will be forbidden EXCEPT for subscriptions belonging to the Microsoft Entra tenant of the subscription originally owning the DNS. After the reservation expires, the DNS is free to be claimed by any subscription. By taking DNS reservations, the customer is afforded some time to either 1) clean up any associations/pointers to said DNS or 2) re-claim the DNS in Azure. The recommendation would be to delete unwanted DNS entries at the earliest. The DNS name being reserved can be derived by appending the cloud service name to the DNS zone for that cloud.

  • Public - cloudapp.net
  • Mooncake - chinacloudapp.cn
  • Fairfax - usgovcloudapp.net
  • BlackForest - azurecloudapp.de

For example, a hosted service in Public named "test" would have DNS "test.cloudapp.net"

Example:Subscription 'A' and subscription 'B' are the only subscriptions belonging to Microsoft Entra tenant 'AB'. Subscription 'A' contains a classic cloud service 'test' with DNS name 'test.cloudapp.net'. Upon deletion of the cloud service, a reservation is taken on DNS name 'test.cloudapp.net'. During the reservation period, only subscription 'A' or subscription 'B' will be able to claim the DNS name 'test.cloudapp.net' by creating a classic cloud service named 'test'. No other subscriptions will be allowed to claim it. After the reservation period, any subscription in Azure can now claim 'test.cloudapp.net'.

Next steps

To learn more about related services and Azure features you can use to defend against subdomain takeover, see the following pages.

  • Enable Microsoft Defender for App Service - to receive alerts when dangling DNS entries are detected

  • Prevent dangling DNS records with Azure DNS

  • Use a domain verification ID when adding custom domains in Azure App Service

  • Quickstart: Run your first Resource Graph query using Azure PowerShell

Prevent subdomain takeovers with Azure DNS alias records and Azure App Service's custom domain verification (2024)

FAQs

What is subdomain takeover? ›

A subdomain takeover occurs when an attacker gains control over a subdomain of a target domain. Typically, this happens when the subdomain has a canonical name (CNAME) in the Domain Name System (DNS), but no host is providing content for it.

What are the risks of subdomain takeover? ›

The risks of subdomain takeover

Malicious pages and services on an organization's subdomain might result in: Loss of control over the content of the subdomain - Negative press about your organization's inability to secure its content, brand damage, and loss of trust.

What two DNS record types are used to verify a custom domain name in Azure Active Directory? ›

After you add your custom domain name to Microsoft Entra ID, create a DNS TXT , or MX record for your domain. Creating this DNS record for your domain verifies ownership of your domain name. The TXT record must be associated with the subdomain, or hostname of the domain.

What DNS record is required to link a custom domain name to an Azure App Service so that users can access the app service using the custom domain name? ›

You can use either a CNAME record or an A record to map a custom DNS name to App Service. When your function app is hosted in a Consumption plan, only the CNAME option is supported. The app's IP address shown in the Add custom domain dialog.

What is the best tool to check subdomain takeover? ›

There are several tools with dictionaries to check for possible takeovers: https://github.com/EdOverflow/can-i-take-over-xyz. https://github.com/blacklanternsecurity/bbot. https://github.com/punk-security/dnsReaper.

What is second level subdomain takeover? ›

Second - Order Subdomain Takeover

One such scenario can be a website using a javascript code from a third party subdomain which is vulnerable to takeover. This allows for the hacker who now has the control of the domain, to inject malicious javascript code and steal cookies and other personal information.

How do I make my subdomain secure? ›

Wildcard SSL

On the other hand, if you're securing Sub-Domains, you can go the Wildcard route. When you're generating your Wildcard SSL Certificate you simply put an asterisk in front of your domain name, so input *. yourdomain.com on the CSR and you can secure an unlimited number of Sub-Domains.

How many subdomains is too many? ›

A domain can have up to 500 subdomains. You can create multiple levels of subdomains such as store.product.yoursite.com, test.forum.yoursite.com, etc. Each subdomain can be up to 255 characters long, but for multi level subdomains, each level can only be 63 characters long.

What is hostile subdomain takeover? ›

One of the subdomains of the scanned domain is pointing to an external service but the external service account was cancelled or has expired. Because the account is not in use anymore, an attacker can claim this account and takeover your subdomain. The attacker can use this subdomain for phishing or to spread malware.

How do you ensure that Azure can verify the domain name? ›

On the Domains tab, select Verify next to the new domain that you created. The Azure portal generates a value for a TXT record. Add that record to your domain's registrar or DNS hosting provider with the provided value. It might take up to 24-48 hours for a new DNS record to propagate on the Internet.

What is alias record set in Azure DNS? ›

Your alias record set points to an Azure public IP address service instance dynamically. As a result, the alias record set seamlessly updates itself during DNS resolution.

What is DNS record for alias domain? ›

An ALIAS record is a type of DNS record that points your domain name to a hostname instead of an IP address. To add and manage these records through Gandi's interface and API, please note that your domain must be using Gandi's LiveDNS nameservers.

Is it possible to customize DNS name in Azure? ›

You can configure Azure DNS to host a custom domain for your web apps. For example, you can create an Azure web app and have your users access it using either www.contoso.com or contoso.com as a fully qualified domain name (FQDN). To do this, you have to create three records: A root "A" record pointing to contoso.com.

What records are supported by Azure DNS? ›

Record types

Another common type is an 'MX' record, which maps a name to a mail server. Azure Private DNS supports the following common DNS record types: A, AAAA, CNAME, MX, PTR, SOA, SRV, and TXT. The Host field in the SOA record isn't editable.

What is the default DNS domain suffix for Azure app Services? ›

The custom domain suffix defines a root domain used by the App Service Environment. In the public variation of Azure App Service, the default root domain for all web apps is azurewebsites.net. For ILB App Service Environments, the default root domain is appserviceenvironment.net.

What is a subdomain and how does it work? ›

A subdomain is a prefix added to a domain name to separate a section of your website. Site owners primarily use subdomains to manage extensive sections that require their own content hierarchy, such as online stores, blogs, job boards or support platforms. Subdomains function as a separate website from its domain.

What is subdomain forwarding? ›

That's likely the result of web forwarding, also known as domain/subdomain forwarding, URL forwarding, or website redirect. It's a handy tool that directs visitors from one web address to another, streamlining their online experience.

What is an example of using subdomain? ›

Subdomains are also commonly used to separate a section of a website from the main site. For example, blog.hubspot.com and shop.hubspot.com direct to our blog and online store respectively.

Why do owners use subdomains? ›

With subdomains, you can publish alternate website content without confusing your audience or hurting your traffic.

Top Articles
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 6197

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.