CIDADAXSEC
← All topics
Expert

Server-side request forgery (SSRF)

SSRF makes the server issue requests to internal destinations that are not directly reachable from the internet.

Material

Server-side request forgery occurs when the server is made to issue a request to an attacker-chosen address. Because the request originates inside the network, destinations such as localhost, internal services, or cloud metadata endpoints become reachable and often answer without extra authentication.

How it works

The usual pattern is a webhook, URL preview, or remote import feature that takes a parameter from the client and calls it with a server-side HTTP client. The app never shows the response body, but the attacker can still tell a successful request from a failed one by the difference in behavior.

http
POST /webhook HTTP/1.1
Host: lab.cidadaxsec.local
Content-Type: application/json
Cookie: session=3f9a1c7e
Accept: */*

{"callbackUrl":"http://169.254.169.254/latest/meta-data/"}
bash
curl -sS -X POST "https://lab.cidadaxsec.local/webhook" \
  -b "session=3f9a1c7e" \
  -H "Content-Type: application/json" \
  -d '{"callbackUrl":"http://127.0.0.1:8080/admin"}'

# deteksi buta: pakai perbedaan status dan waktu
curl -sS -o /dev/null -w "%{http_code} %{time_total}\n" \
  -X POST "https://lab.cidadaxsec.local/webhook" \
  -H "Content-Type: application/json" \
  -d '{"callbackUrl":"http://127.0.0.1:9/closed"}'

Attack vectors

  • Internal reconnaissance: the attacker scans localhost ports and internal networks using timing and status differences.
  • Cloud metadata access: 169.254.169.254 often returns instance credentials with no token required.
  • Blacklist filters: internal addresses in decimal, octal, or hex notation slip past plain string matching.
  • Bypass through an open redirect: the attacker points at a redirect endpoint that then targets an internal service.
  • Shellshock: a CGI endpoint forwarding controllable headers into bash makes the server execute commands.

Blacklist filters can almost always be walked around because an address has many textual forms. DNS that the attacker also controls makes it worse, since a domain name can point at any address at any time.

Preventing

  • Use a destination allowlist: only the hosts and ports the feature genuinely needs, not a list of forbidden addresses.
  • Resolve DNS before connecting, then validate the resolved IP against the allowlist to stop DNS rebinding.
  • Block loopback, link-local, and internal network ranges from inside the application HTTP client.
  • Disable redirects when fetching URLs and cap response time and download size.
  • Return response details only when the feature needs them, and never render metadata pages or internal content.
python
import ipaddress
import socket

ALLOWED_HOSTS = {"hooks.example.com"}

def is_public(ip: str) -> bool:
    addr = ipaddress.ip_address(ip)
    blocked = (addr.is_loopback, addr.is_link_local, addr.is_private)
    return not any(blocked)

def fetch_allowed(url: str) -> bytes:
    host = url.split("/")[2].split(":")[0]
    if host not in ALLOWED_HOSTS:
        raise ValueError("host not allowed")
    ips = [i[4][0] for i in socket.getaddrinfo(host, None)]
    if not all(is_public(ip) for ip in ips):
        raise ValueError("non-public address")
    return http_get_without_redirects(url)

Labs

  • Basic SSRF against the local server
  • Basic SSRF against another back-end system
  • Blind SSRF with out-of-band detection
  • SSRF with blacklist-based input filter
  • SSRF with filter bypass via open redirection vulnerability
  • Blind SSRF with Shellshock exploitation
  • SSRF with whitelist-based input filter
Whether the SSRF echoes the response body or only triggers the request decides your testing strategy. A blind one can always be detected through timing, status differences, or DNS, but never through the response body.

Labs in this topic

Labs run on a domain separate from this site, so a payload cannot reach your account session.

Labs for this category land in Phase 2. The material is readable now.

Challenges in this category

Challenges from the PortSwigger Web Security Academy. The original labs run on PortSwigger domains, so the link opens there.