Course contentsShow
← Security
Lesson 890 of 3,05218. Web Security - CSRF and Request ForgeryFree lesson

DNS Rebinding Attacks

Exploiting time-of-check-time-of-use vulnerabilities with DNS TTL manipulation to bypass SSRF protections.

DNS Rebinding Attacks

What you'll learn: How attackers exploit DNS time-to-live (TTL) manipulation to bypass SSRF protections by making a domain resolve to different IP addresses at different times.


The Time-of-Check-Time-of-Use Problem

DNS rebinding exploits a classic security vulnerability pattern: time-of-check-time-of-use (TOCTOU). Here's how it works in the context of SSRF protections:

Many applications try to prevent SSRF by validating URLs before fetching them. They resolve a domain name to check if it points to a dangerous internal IP address (like 127.0.0.1 or 192.168.1.1). If the check passes, they proceed with the request.

The attack exploits the gap between these two moments.

How DNS Rebinding Works

  1. Attacker controls a domain (e.g., evil.attacker.com) and its DNS server
  2. Initial DNS lookup: The application checks the domain and it resolves to a safe, external IP (like 1.2.3.4)
  3. Validation passes: The app thinks it's safe to fetch from this domain
  4. DNS TTL expires: The attacker sets an extremely short TTL (time-to-live), often 0 or 1 second
  5. Second DNS lookup: When the app actually makes the HTTP request, it queries DNS again
  6. Rebinding occurs: The attacker's DNS server now returns a malicious internal IP (127.0.0.1, cloud metadata endpoint, etc.)
  7. Attack succeeds: The app fetches the internal resource, bypassing SSRF protections

The Analogy

Imagine showing your ID at a club entrance (validation check), then walking through a magical door that teleports you to a different person's body before you reach the bar (the actual request). The bouncer checked you, but someone else got served.

Defense Considerations

  • Re-validate DNS resolution immediately before each request
  • Pin IP addresses after initial resolution
  • Implement request-time checks, not just pre-validation
  • Use allowlists instead of denylists for domains

Key Takeaway: DNS rebinding bypasses SSRF protections by exploiting the time gap between URL validation and actual request execution, using short DNS TTLs to change where a domain points between these two moments.