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