Table of Contents
- What is SSRF?
- Impact of SSRF Attacks
- Types of SSRF Attacks
- Common SSRF Vulnerabilities and Scenarios
- SSRF Bypass Techniques
- DNS Rebinding
- Detection Methods
- Exploitation Steps
- Mitigation and Prevention
- Real-World Examples
What is SSRF?
Server-Side Request Forgery (SSRF) is a web security vulnerability that allows an attacker to cause the server-side application to make requests to unintended locations.
In a typical SSRF attack, the attacker might cause the server to make a connection to internal-only services within the organization’s infrastructure or to arbitrary external systems, potentially leaking sensitive data.
How SSRF Works
SSRF occurs when an application accepts user-controllable input that specifies a URL or network resource, and then uses this input to make a request on behalf of the server without proper validation.
1 | graph TD |
Impact of SSRF Attacks
| Impact | Description |
|---|---|
| Access Internal Systems | Attackers can reach internal services (like databases, APIs, admin panels) that aren’t normally exposed. |
| Bypass Security Controls | The server makes the request, so firewalls or IP restrictions can be bypassed. |
| Steal Sensitive Data | Attackers can read internal data like credentials, configs, or secrets. |
| Remote Code Execution | In some cases, SSRF can lead to RCE or control over internal servers. |
| Server Abuse | Attackers can send malicious requests to other websites/services using your server’s IP. |
| Cloud Exploits | On cloud platforms, SSRF can expose metadata and give access to cloud resources. |
Types of SSRF Attacks
SSRF Against the Server
In this type of SSRF, the attacker tricks the server into making a request to itself (via localhost or 127.0.0.1).
Why Apps Trust Local Requests
- Access Control is Separate: A different system (like a proxy or firewall) handles access checks. Local requests skip this layer.
- Disaster Recovery Logic: Admin access might be allowed without login if the request is from the local machine.
- Separate Admin Interface: Admin panel might run on a different port that’s not directly accessible from the internet.
Example Scenario
1 | Normal request: |
The server fetches its own /admin page, which is normally protected. Since the request is local, the server allows full admin access.
SSRF Against Back-End Systems
Sometimes the server can access internal systems (with private IPs like 192.168.x.x) that normal users can’t reach. These internal systems are often less secure and may not require authentication.
Example Scenario
1 | Admin interface is hosted at: http://192.168.0.68/admin (internal IP) |
The server makes the request on the attacker’s behalf and returns the admin page.
Common SSRF Vulnerabilities and Scenarios
Basic SSRF
Applications that directly use user input to make HTTP requests without validation.
Vulnerable Code Example:
1 |
|
Blind SSRF
Blind SSRF happens when the server makes the request, but you don’t see the result in the response.
Detection
Use a service like Burp Collaborator or your own HTTP server to see if the server makes a request to you.
Example:
1 | Referer: http://your-collaborator-domain.com |
SSRF with Blacklist-Based Input Filters
Some applications try to block SSRF by blacklisting dangerous inputs like:
- 127.0.0.1
- localhost
- /admin
SSRF with Whitelist-Based Input Filters
Some applications try to prevent SSRF by using a whitelist—only allowing URLs that start with or contain trusted values.
SSRF via Open Redirection
Sometimes, SSRF filters only allow URLs from trusted domains, but if that trusted domain has an open redirection vulnerability, attackers can use it to trick the server into going somewhere else.
SSRF in Different Contexts
SSRRF via Referer Header
Some web applications have internal tools that:
- Log the Referer header for analytics
- Automatically fetch the content of the Referer URL
SSRF via Data Formats
Some structured data formats (like XML, YAML, SVG) allow the inclusion of URLs inside them. When the server parses this data, it might make a request to the URL specified.
Example with XML:
1 |
|
SSRF Bypass Techniques
Bypassing Blacklist Filters
Alternate IP Representations
- Decimal: 2130706433 (for 127.0.0.1)
- Octal: 017700000001 (for 127.0.0.1)
- Shortened: 127.1 (for 127.0.0.1)
Custom Domain That Resolves to Localhost
- Register a domain and make it resolve to 127.0.0.1.
URL Encoding & Case Variations
- Encoding: /admin → %2fadmin
- Case tricks: LoCaLhOsT instead of localhost
Use Redirects
- Host a URL that redirects to the blocked target.
- Try different redirect status codes (e.g., 301, 302, 307)
Bypassing Whitelist Filters
Credentials Injection with @
1
https://trusted.com:fakepass@evil.com
Filter may see: https://trusted.com ✅
But the actual request goes to evil.comFragment Trick with #
1
https://evil.com#trusted.com
Filter sees trusted.com ✅
Actual request goes to evil.comSubdomain Trick
1
https://trusted.com.attacker.com
Filter matches trusted.com ✅
But DNS resolves to your domain (attacker.com)URL Encoding & Double Encoding
- / becomes %2F
- @ becomes %40
- Double encoding tricks: %252F → gets decoded to %2F → then /
Combining Techniques
1
2https://trusted.com#@evil.com
https://trusted.com.%09attacker.com (%09 = tab)
Bypassing SSRF Filters with Open Redirection
If the trusted domain has an open redirection vulnerability:
1 | stockApi=http://weliketoshop.net/product/nextProduct?path=http://192.168.0.68/admin |
Steps:
- Filter allows it (URL starts with weliketoshop.net)
- Server follows the redirect to: http://192.168.0.68/admin
DNS Rebinding
DNS rebinding is a technique that can bypass SSRF protections by changing the DNS resolution of a hostname between validation checks and the actual request.
How DNS Rebinding Works
- Initial Request: The attacker sends a request with a hostname that resolves to a safe IP address
- Validation: The application validates the IP address and allows the request
- DNS Change: The attacker changes the DNS record to point to an internal IP address
- Actual Request: The application makes the request to the internal IP address
1 | sequenceDiagram |
Example Scenario
1 | Attacker sends: |
Detection Methods
Manual Testing
Identify Potential SSRF Points
- Look for parameters that might contain URLs
- Check for functionality that fetches external resources
- Examine headers like Referer
Test with Different Payloads
- Try accessing localhost (127.0.0.1)
- Try accessing private IP ranges (192.168.x.x, 10.x.x.x)
- Use Burp Collaborator or similar for blind SSRF detection
Automated Testing
SSRF Scanners
- Burp Suite Professional
- OWASP ZAP
- Custom scripts
Out-of-Band Detection
- Burp Collaborator
- Custom OAST services
Exploitation Steps
Identify Potential SSRF Vulnerability
- Find functionality that processes URLs
- Look for features that fetch external resources
Confirm Vulnerability
- Try basic payloads to see if you can access different domains
- Use Burp Collaborator to detect blind SSRF
Bypass Filters
- Try the techniques mentioned above
- Test different encoding methods
- Experiment with redirects
Exploit
- Access internal services
- Extract sensitive data
- Attempt to escalate to RCE
Document Findings
- Record the vulnerability
- Provide proof of concept
- Suggest remediation
Mitigation and Prevention
Input Validation
Whitelist Allowed Domains
- Only allow requests to specific, trusted domains
- Implement strict validation
Validate URLs
- Parse and validate the URL structure
- Check against a list of allowed protocols
Avoid User-Supplied URLs
- Use indirect references or IDs instead of full URLs
- Map IDs to pre-approved URLs server-side
Network Controls
Network Segmentation
- Separate web servers from internal networks
- Implement proper firewall rules
Egress Filtering
- Restrict outbound connections from web servers
- Allow only necessary outbound traffic
Disable Unnecessary Protocols
- Disable protocols like file://, gopher://, etc.
Server Configuration
Disable Redirects
- Configure HTTP clients to not follow redirects
- Implement timeout limits
Response Handling
- Don’t return raw responses from external requests
- Filter and sanitize responses
Use Security Libraries
- Libraries with built-in SSRF protection
- Keep libraries updated
Real-World Examples
Example 1: Basic SSRF
1 | # Vulnerable code |
Example 2: Blind SSRF
1 | # Vulnerable code |
Example 3: SSRF with Filter Bypass
1 | # Vulnerable code with filter |
Example 4: SSRF via XML
1 | <!-- Malicious XML payload --> |
Note: This guide is for educational purposes and authorized security testing only. Always obtain proper authorization before testing systems for vulnerabilities.