Home Guides Security ChecksDNS Hijacking and Cache Poisoning: How Attacks Work and How to Defend Against Them
Security Checks15 minUpdated 2026-03-01

DNS Hijacking and Cache Poisoning: How Attacks Work and How to Defend Against Them

When an attacker compromises DNS, they don't need to touch your web server, your application code, or your database. They just need to change where your domain resolves — and suddenly every user who tries to reach your site is directed to infrastructure the attacker controls. This guide explains how DNS hijacking and cache poisoning work and how to defend against them.

DNS Architecture and the Compromise Chain

The DNS system is the "Nervous System" of the internet, but it was designed in an era of implicit trust. To understand how exploits work, you must first understand the "Chain of Command" for a domain. It starts with the Registry (the central database for .com, .org, etc.), which trusts the Registrar (where you bought your domain). The Registrar points to your Authoritative Nameservers, which finalmente give the "Answer" (IP address) to the Recursive Resolvers used by ISPs and users.

Each step in this chain is a potential point of failure. If an attacker can inject malicious data at any point, they can effectively "Ghost" your website. They don't need to hack your WordPress or your AWS server; they just need to change the pointer on the map. This makes DNS attacks exceptionally dangerous because they are often invisible to the server administrator. Your server logs will simply show a sudden drop in traffic, while your users are unknowingly submitting their credit card info to a perfect clone of your site hosted elsewhere.

Code
; THE DNS ATTACK POINTS:
1. REGISTRY LAYER -> The ultimate authority. Very rare, but catastrophic if breached.
2. REGISTRAR LAYER -> Account theft via phishing or support fraud. Most common path.
3. NAMESERVER LAYER -> Compromising the DNS hosting provider's management API.
4. RESOLVER LAYER -> "Poisoning" the ISP's cache without touching your records.
5. USER LAYER -> Manipulating the /etc/hosts file on a local computer.

The severity of an attack depends on where it happens. A "Local" attack on a user's computer only affects that user. However, an attack at the Registrar or Nameserver level affects every user on Earth. This "Global Impact" is why DNS hijacking is favored by state actors and high-level cybercriminals. In a few clicks, they can redirect the traffic of a major bank or a government agency to a server that performs a "Man-in-the-Middle" (MITM) attack to capture passwords in real-time.

As a webmaster, your goal is to "Harden" every link in this chain. You cannot control your ISP's recursive resolver, but you can use DNSSEC to ensure the resolver can verify your records. You cannot control the Registry, but you can use a Registry Lock to ensure your registrar can't be tricked. By building a layered defense, you transform your DNS from a legacy vulnerability into a robust, cryptographically verified gateway for your brand.

DNS Cache Poisoning: Forging the Recursive Answer

DNS Cache Poisoning (also known as DNS Spoofing) is a technical exploit that targets the Recursive Resolver. Unlike hijacking, where the attacker changes your official records, poisoning works by tricking a resolver (like your ISP's DNS or a public resolver like 8.8.8.8) into believing a lie. The attacker sends a fake response to a resolver's query before the real nameserver has a chance to respond. If the fake response arrives first and contains the correct "Transaction ID," the resolver will cache the malicious IP and serve it to thousands of users.

In the early days of the web, this was easy because transaction IDs were predictable. However, after the famous "Kaminsky Attack" in 2008, developers implemented Source Port Randomization. This made it exponentially harder for an attacker to guess the correct combination of port and ID to "win" a race. Today, a successful blind poisoning attack requires trillions of guesses, making it computationally expensive for most attackers—unless they are "On-Path" (meaning they can see the traffic) or the resolver has a weak random number generator.

  • Race Conditions: The attacker must "outrun" the legitimate nameserver. If the real answer arrives first, the poison fails.
  • TTL Duration: Once poisoned, the "Lie" remains in the resolver's cache for the duration of the record's TTL (Time to Live).
  • Global vs. Local: Poisoning a single ISP only affects that ISP's customers. This is why attackers often target large public resolvers to maximize their reach.

Modern poisoning defenses focus on increasing "Entropy" (randomness). The more random the query ID, the source port, and even the "Capitalization" of the domain name (0x20 encoding), the harder it is for an attacker to forge a matching response. But even with these math-based defenses, the underlying protocol is still just an unauthenticated exchange of UDP packets. It’s like a conversation where anyone can yell "YES, THAT'S ME!" from across the room.

The only definitive solution to cache poisoning is DNSSEC. By adding a digital signature to every record, DNSSEC allows the resolver to say "I don't care who arrived first; I only care whose signature is valid." If an attacker sends a forged response, it won't have the correct cryptographic signature, and the resolver will automatically discard it. Without DNSSEC, you are relying on probability; with it, you are relying on physics and advanced math.

Registrar and Nameserver Hijacking: Source-Level Compromise

While cache poisoning is a technical exploit, Registrar Hijacking is primarily a "Social" or "Account" exploit. This is the most common high-impact DNS attack. Instead of tricking a resolver, the attacker gains direct access to your domain management account (e.g., your GoDaddy or Namecheap account). Once inside, they simply update your Nameservers to point to their own infrastructure. In seconds, they have full control over every record: A, MX, TXT, and CNAME.

Nameserver hijacking is especially dangerous because it allows the attacker to pass Domain Validation (DV) challenges. Most SSL certificates are issued based on whether you can modify the DNS. If the attacker controls your nameservers, they can request a valid, trusted SSL certificate from a CA, pass the DNS check, and present a site with a "Green Lock" to your users. This is a total compromise of your brand's security posture.

MethodEntry PointDifficultyImpact
PhishingAdmin's Email / Domain AccountLowTotal - Global Takeover
Credential StuffingReused Passwords from LeaksLowTotal - Global Takeover
Social EngineeringCalling Registrar SupportMediumTotal - Global Takeover
API CompromiseLeaked Cloud CredentialsMediumRestricted to One Provider

As indicated in the table, the "Difficulty" of these attacks is alarmingly low. An attacker doesn't need to be a "Master Hacker" to phish a tired IT administrator or find a reused password in a public data breach. To defend against this, you must treat your registrar account like your most sensitive bank account. Hardware MFA (Multi-Factor Authentication), such as a YubiKey, is the only way to effectively stop these attacks. SMS or App-based codes can still be phished in real-time; hardware keys cannot.

Another critical defense is Registry-Level Locks. For high-value domains, you can pay a fee to have your domain "Locked" at the central database (the Registry). This means that even if an attacker hacks your registrar account, they cannot change the nameservers without a manual out-of-band verification process (usually a phone call or a physical letter). This "Human-in-the-Loop" security is what protects major brands like Google, Apple, and large financial institutions from sudden DNS takeovers.

BGP Hijacking and Subdomain Takeovers: Infrastructure Gaps

Beyond the DNS protocol itself, there are two "Infrastructure Level" attacks that can achieve the same results as a hijacking. The first is BGP Hijacking. BGP (Border Gateway Protocol) is how routers "announce" which IP addresses they own. If an attacker can convince the internet's backbone routers that they own the IP addresses of your nameservers, they can intercept all the DNS traffic intended for you. This is a very high-level attack usually performed by rogue state actors or sophisticated telco-level criminals.

The second, and much more common, gap is the Subdomain Takeover. This is the "Low-Hanging Fruit" of DNS security. Many companies create CNAME records pointing to third-party services like GitHub Pages, S3, or Heroku. If the company later deletes the GitHub project but forgets to delete the DNS record, the CNAME is "Dangling." An attacker can then register their own project on that same service using the same name, and suddenly they are hosting content on yoursubdomain.com.

  • Forgotten Infrastructure: Marketing "campaign" sites, old dev environments, and temporary blog platforms are prime targets.
  • Trusted Source: Users trust the subdomain because it's under your "Apex" domain, making it an ideal place for phishing or malware delivery.
  • Implicit Authority: Because the attacker "controls" the subdomain, they can sometimes leverage it to perform cross-domain cookie attacks on your main site.

Defending against subdomain takeovers requires a "DNS Sanitization" process. You should regularly audit every record in your zone. If you see a CNAME pointing to a service you no longer use, delete it immediately. There is no benefit to keeping "Stale" records, and the risk they pose is significant. We recommend using a DNS Monitoring Tool that alerts you whenever a record resolves to a 404 or a "Project Not Found" page at a major hosting provider.

BGP hijacking is harder to defend against as an individual company, but you can choose infrastructure providers that use "Anycast" DNS and "BGP Route Filtering." These providers (like Cloudflare or AWS Route 53) are large enough to detect and mitigate BGP hijacks in real-time, effectively shielding your domain from routing-level attacks. By choosing robust, global infrastructure partners, you offload the responsibility for Backbone Security to experts who have the scale to handle it.

DNSSEC: Cryptographic Verification of the Resolution Path

DNSSEC (Domain Name System Security Extensions) is the "Encryption" equivalent for DNS. While it doesn't encrypt the content of the query (that’s what DNS-over-HTTPS does), it provides Signature Verification. Without DNSSEC, a resolver has no way to prove that the IP address it received is authentic. It’s like receiving a letter in the mail with no signature and no return address; you just have to hope it’s from the person it claims to be from.

DNSSEC adds a digital signature to every record in your zone using a "Private Key." It then publishes a "Public Key" (DNSKEY) and a "Signature" (RRSIG). When a browser makes a query, the resolver uses the public key to "Verify" the signature. If the signature matches the data, the resolver knows the answer hasn't been tampered with. It also creates a "Chain of Trust" up to the parent registry (.com or .net), ensuring that no one has "Spoofed" your keys either.

Code
; The DNSSEC Verification Steps:
1. Resolver receives IP address + RRSIG (signature).
2. Resolver fetches DNSKEY (public key).
3. Resolver performs a "Hash" and "Compare" on the two.
4. If they match, the "AD" (Authenticated Data) flag is set.
5. If they FAIL, the resolver returns "SERVFAIL" (Server Failure).

The power of DNSSEC is in the SERVFAIL response. If an attacker tries to poison a resolver's cache for a DNSSEC-protected domain, the signature verification will fail. Instead of showing the user the attacker's fake site, the browser will simply show a "Connection Refused" error. This prevents the user from even seeing the malicious content. It is better for your site to be "Offline" for a few users during an attack than for those users to be "Hijacked" and compromised.

Implementation of DNSSEC has traditionally been difficult, but most modern registrars now offer "One-Click DNSSEC." When you enable it, they handle the key generation, signing, and the "DS Record" submission to the registry for you. However, you must be extremely careful when migrating DNS hosts; if you move your nameservers without updating your DNSSEC keys first, you will break your "Chain of Trust" and your site will vanish for high-security resolvers like Google (8.8.8.8) or Cloudflare (1.1.1.1).

Advanced Registry-Level Locks and Account Hardening

Standard "Domain Locking" is something you see in every registrar dashboard. It's usually a simple toggle that prevents your domain from being transferred to a different registrar. While useful, it is "Low Security." If an attacker hacks your account, they can simply toggle the lock "Off." To reach a professional security posture, you need Registry-Level Lock (ServerLock). This is a premium service where the registrar adds a specific status code (like clientUpdateProhibited) that is enforced by the central database operator.

With a Registry Lock, the registry (VeriSign for .com, for example) will refuse to process any change to your domain—even if your registrar asks them to—until a manual verification occurs. This usually involves a "Code Word" exchanged over the phone between your security officer and the registry's staff. This is the ultimate "Seatbelt" for your domain. It is physically impossible for an automated bot or a phished support agent to bypass a high-quality Registry Lock.

  • Human Verification: Prevents automated API takeovers and phished credentials from being effective.
  • Audit Trail: Every change requires a documented, logged conversation with the registry's security team.
  • Peace of Mind: Even if your entire registrar account is deleted by a malicious actor, your domain remains safe and pointing to your servers.

Beyond registry-level locks, you must also "Harden" your registrar account itself. Use a Dedicated Email Address for your domain account that isn't shared with your marketing or personal accounts. If your "Support" email is hacked, an attacker can use "Reset Password" to take over your domain. By isolating your domain credentials in a separate, high-security vault, you minimize the "Cross-Contamination" risk from other service breaches.

Finally, consider IP Whitelisting for your registrar's management console if they support it. This ensures that even if an attacker has your password and your MFA key, they can only log in from your company's physical office or your secure VPN. This "Geographic Fence" is a powerful deterrent against remote attackers. DNS security is about "Defense in Depth"—stacking these locks and barriers until the effort required to breach your domain is higher than the value of the attack itself.

Observability and Detection: Monitoring your DNS Perimeter

Because DNS is decentralized, you cannot "Watch" every query. You must instead monitor the "Source of Truth" and the "Global Resolvers." DNS Monitoring should be as core to your stack as server monitoring. You should have a script or service that queries your NS and A records from multiple geographic locations every 5-10 minutes. If your site suddenly resolves to an IP address that isn't on your whitelist, you need an instant, high-priority alert (SMS, PagerDuty, etc.).

Another critical monitoring tool is Certificate Transparency (CT) Alerts. Every time a public SSL certificate is issued, it is logged in a public ledger. If an attacker hijacks your DNS and successfully requests an SSL certificate for your domain, you can receive an alert within minutes. This is often the first "Smoke Signal" of a DNS hijack. If you see a certificate issued from a CA you don't use (like "ZeroSSL") for a domain you haven't touched, you know you are under active attack.

Monitoring TypeWhat it DetectsResponse Action
Record AuditChange in A, MX, NS recordsImmediate rollback via Registrar
CT Log MonUnexpected SSL IssuanceRevoke certificate / Fix Hijack
BGP MonitorRoute redirection/hijackingContact Tier 1 Network Provider
WHOIS AuditChange in Registrar/OwnershipContact Registrar Emergency Support

As indicated in the table, different monitoring tools catch different types of attacks. A WHOIS audit might catch a "Slow Transfer" attempt that hasn't changed your resolution yet, giving you days to stop the attack. A record audit catches a real-time hijack. By monitoring all four categories, you create a "360-degree" view of your domain's health. You shouldn't just check "if it works"; you should check "if it works exactly the way I configured it."

One of the most effective tools for this is our DNS Security Check. It performs a deep scan of your DNS chain, looking for broken DNSSEC signatures, dangling CNAMEs, and unauthorized nameservers. It can also be configured to alert you whenever your "Baseline" changes. For professional webmasters, the question is not "if" you will be targeted by a DNS attack, but "when." Having a robust monitoring and response plan ensures that your business stays online and your users stay safe.

Frequently Asked Questions

Q: Can I get hacked even if I use a reputable registrar like GoDaddy?

Yes. Most registrar hijacks are not technical breaches of the registrar themselves; they are breaches of the User's account. If an attacker phishes your password and you aren't using hardware MFA, they can log in effortlessly. Reputable registrars provide the tools (like Registry Lock), but it is your responsibility to enable them.

Q: Will DNSSEC make my website load slower?

The difference is negligible. Resolvers are extremely good at caching DNSSEC signatures. On the very first request, it might add a few milliseconds to the lookup time, but for 99% of your users, they will see no "perceived" difference in speed. The security benefit far outweighs the tiny millisecond cost.

Q: What is the "Registry Lock" vs. the "Registrar Lock"?

A Registrar Lock is the standard lock in your dashboard that prevents transfers. A Registry Lock is an additional, paid service provided by the central database operator (e.g., VeriSign). The Registry Lock is much more secure because it requires manual, human verification from the registry themselves before any record can be changed.

Q: Why does an attacker need an SSL certificate if they hijack my DNS?

Because of HSTS. Most modern browsers (and high-value sites) use HSTS, which forces an HTTPS connection. If an attacker redirects your DNS but can't provide a valid SSL certificate, the browser will block the site and show a massive "Your connection is not private" warning. To perform a secret attack, they must get a trusted certificate.

Q: Can I use DNS monitoring to prevent a hijack?

No. Monitoring only Detects a hijack. It’s like a smoke alarm—it doesn't stop the fire, but it tells you it's happening so you can call the fire department. You use "Locks" and "MFA" to prevent the attack, and you use "Monitoring" to manage your response if those defenses are ever bypassed.

Q: What is a "Dangling CNAME" and why is it dangerous?

A dangling CNAME is a DNS record that points to a third-party service (like myblog.wordpress.com) that you have since stopped using or deleted. It’s dangerous because an attacker can go to WordPress, register that same username, and suddenly they control your subdomain. This is called a "Subdomain Takeover."

Next Steps

Verify your current "DNS Health" by running a comprehensive audit with our DNS Security Check. This tool will simulate multiple attack vectors and provide you with a detailed report on your DNSSEC status, CNAME safety, and nameserver integrity.

Once you have identified any gaps, follow our guides on DNSSEC Implementation and CAA Record Setup to start hardening your perimeter. If you are preparing to move your site to a new provider, be sure to read our DNS Migration Guide to avoid common security pitfalls during the transition.

Browse all Security Guides on DNSnexus for in-depth technical documentation on BGP Route Filtering, CT Log Monitoring, and High-Availability Nameserver architectures.