Share some knowledge, skills and others — security research, pentesting notes and more.

View on GitHub
18 January 2020

Server Side Request Forgery

by allencharp

What is SSRF

Why SSRF is dangerous

The key to SSRF is that the request is made by the server, not the client. This means:

Sample Malicious Code

<?php

/**
* Check if the 'url' GET variable is set
* Example - http://localhost/?url=http://testphp.vulnweb.com/images/logo.gif
*/
if (isset($_GET['url'])){
$url = $_GET['url'];

/**
* Send a request vulnerable to SSRF since
* no validation is being done on $url
* before sending the request
*/
$image = fopen($url, 'rb');

/**
* Send the correct response headers
*/
header("Content-Type: image/png");

/**
* Dump the contents of the image
*/
fpassthru($image);}

Here $url is taken directly from user input and passed to fopen(). An attacker only needs to change the parameter, e.g. ?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/, to read the cloud metadata.

Common Bypass Techniques

Filters are often imperfect. Common bypasses include:

Mitigating Server Side Request Forgery

Summary

SSRF is a server-side trust issue: the server blindly follows attacker-controlled URLs. Defense in depth — strict allowlists, scheme restrictions, authentication on internal services, and network segmentation — is required because any single bypass defeats a purely input-based filter.

reference

tags: web-security - ssrf - pentest