Hijackings, Subdomains, and Cookies

How dangling DNS records can lead to subdomain takeovers, phishing, and exposed cookies.

Banner

Many companies, brands, and individuals outsource services to other businesses through SaaS (Software as a Service). This saves them work on services they may lack the time or expertise to build themselves: videoconferencing, ticketing, backends, shops, and so on.

Usually, the customer creates an account and changes DNS so that service.domain.com has a CNAME pointing to the SaaS provider.

This is a convenient way to entrust parts of a business to experienced developers, but things don’t always go perfectly.

What’s the problem?

The problem arises when a company stops using a SaaS provider—because of a migration, an abandoned trial, payment problems, or a forgotten renewal—but leaves its CNAME at service.domain.com unchanged. The record should be deleted or updated to point to the replacement service. This is known as dangling DNS, and such a small oversight can have serious consequences.

It might sound rare, but this vulnerability has affected small organizations and major companies alike, including Microsoft, Chevron, the Red Cross, UNESCO, 3M, Arm, Warner Brothers, Honeywell, Toshiba, Xerox, the NHS, Volvo, and others.

Why are these subdomains so easy to hijack?

For a long time, some SaaS providers didn’t check whether the person claiming a subdomain pointing to their service actually owned the domain. Someone who found a dangling DNS record could therefore publish arbitrary content under a company’s subdomain with just a few clicks.

Fortunately, some providers introduced ownership checks, such as requiring a specific DNS TXT record, which an outsider cannot add, or allowing a subdomain to be registered only once to an account.

Other providers still lacked these protections when this article was written. Let’s look at a takeover and the attacks it can enable.

The procedure

Suppose https://b0n3sh.com uses an outsourced meeting booking service at https://vuln.b0n3sh.com.

Original meeting service

The subdomain’s CNAME points to the SaaS provider.

DNS lookup

Now suppose the company abandons this service but doesn’t remove the CNAME. To reproduce that, we delete our SaaS account without changing DNS. Visiting the subdomain now produces an error saying the service isn’t correctly activated.

Unclaimed service error

An attacker who discovers this dangling record can see that the subdomain is no longer registered. If the provider doesn’t verify ownership, the attacker can claim it.

The attacker simply signs up with the provider and selects its custom domain option, entering the abandoned subdomain. Each provider implements this differently, but the result is control over the subdomain’s content.

What now?

The impact depends partly on the provider. Some interfaces are restrictive, while others let you point an A record to your own VPS, giving you much more freedom.

Here, we’re limited to the meeting booking interface. That still leaves room for an attack: visitors recognize b0n3sh.com and may trust its subdomains as belonging to the same organization.

One example is phishing: announce that the service has moved and invite visitors to another website, where they could be asked for sensitive information, using Evilginx for example.

Example redirect message

Looking a little further, I found a somewhat hidden option to embed HTML. To my surprise, it wasn’t parsed properly. With a little creativity, we could hide the meeting interface and create a more direct landing page focused on the message.

Embedded HTML example

Modified landing page

That’s a basic example of phishing through a subdomain takeover.

More attacks

As mentioned, the provider’s features determine what becomes possible. Some let you use a VPS and manage DNS records for the subdomain without controlling the parent domain. That may include adding TXT and MX records and sending email from the compromised subdomain, potentially benefiting from its reputation with spam filters such as Gmail’s.

Cookies scoped to the parent domain may also be sent to the compromised subdomain. The Secure flag doesn’t prevent this when the provider supplies TLS automatically and the subdomain is served over HTTPS.

Another possibility arises when an application on the parent domain trusts its subdomains through its CORS configuration. A compromised subdomain may then be able to make requests that the application allows because it appears on that allowlist.

In other cases, like the service demonstrated here, we can’t run a VPS or our own backend. We only get a limited interface for building HTML or a frontend using the provider’s tools. Then we have to get creative.

Working with what we have

With a restrictive provider, we must work within the available features. As shown above, we could encourage visitors to follow a link to a phishing site.

If the service allows JavaScript and the relevant cookies don’t have the HttpOnly flag, scripts on the compromised subdomain may also read cookies scoped to the parent domain.

Cookie example

Cookie access demonstration

Ultimately, the risk depends on the provider’s checks and on the customer leaving a dangling DNS record behind.

Mitigation

Keep DNS records up to date to avoid this headache.

Here’s a diagram summarizing the process.

Subdomain takeover diagram