Server-Side Request Forgery (SSRF)

When a web application fetches additional resources from a remote location based on user-supplied data, such as a URL.

URL schemes used in the exploitation of SSRF vulnerabilities:

  • http://,https://: fetch content via HTTP/S requests

  • file://: reads a file from the local file system

  • gopher://: send arbitrary bytes to the specified address

Identifying SSRF

The web server fetches the availability information from a separate system determined by the URL passed in this POST parameter

Point the web application to itself by providing the URL http://127.0.0.1/index.php

Enumerating the System

Exploiting SSRF

Accessing Restricted Endpoints

Local File Inclusion (LFI)

The gopher Protocol

We can use the gopher URL scheme to send arbitrary bytes to a TCP socket. This protocol enables us to create a POST request by building the HTTP request ourselves. We can use the gopher protocol to interact with many internal services, not just HTTP servers.

Blind SSRF

The response is not directly displayed.

Identifying Blind SSRF

We can confirm the SSRF vulnerability by supplying a URL to a system under our control and setting up a netcat listener

If we attempt to point the web application to itself, we can observe that the response does not contain the HTML response of the coerced request

Exploiting Blind SSRF

Local port scan

Closed ports
Open ports
Existing files
Invalid files

Preventing SSRF

Web application

The remote origin data should be checked against a whitelist to prevent an attacker from coercing the server to make requests against arbitrary origins. The URL scheme and protocol used in the request need to be restricted to prevent attackers from supplying arbitrary protocols. Instead, it should be hardcoded or checked against a whitelist. Input sanitization.

Network layer

Appropriate firewall rules should drop any outgoing requests to potentially interesting target systems. Network segmentation.

Last updated