Attacks
Understanding SSRF: A hands-on demonstration
Security analyst
Updated
May 6, 2020
7 min
Many web applications request outside services for data, configurations, updates, among others. This is beneficial for the developers and maintainers because it keeps separation of duties in their infrastructure, one for managing the view and another for the data. When it is done right, these applications are easier to maintain and to add features to, but there are some intrinsic risks in getting information through the internet using web services.
Server Side Request Forgery (SSRF) occurs when an attacker can create requests from the vulnerable server to the internet/intranet. Typically, the vulnerable server has a functionality that reads data from a URL, publishes data to a URL, or imports data from a URL. An attacker could abuse this functionality to read or update internal resources, or bypass access controls like firewalls that prevent the attackers from accessing them directly.
In a normal use case, the vulnerable application works like this:

Normal use case.
The user requests information from an external server through the Web Server. For example,
GET /?url=http://external.server/data HTTP/1.1
The server makes the request to the external server
If the request is to an intranet server, then it passes through the company firewall
The external server responds with the data requested, and the user receives it
When an attacker finds this, and he wants to bypass the firewall in order to get internal resources, then the process of the attack is the following:

ssrf attack.
The attacker makes the same request but modifies the payload for a request to another internal server, for example,
GET /?url=http://admin.server/users HTTP/1.1
The server makes the request to the modified server
The request passes through the company firewall bypassing its measures
The admin server responds with the data requested by the attacker
SSRF lab
To set up our lab, we are going to use Hashicorp’s
Vagrant; the source files are below. Create a folder with the name ssrf
and save the Vagrantfile
there.
setting up the lab.
Vagrantfile.
Then run the environment using:
vagrant up.
This will create a Linux
machine with LAMP
installed and configured. At this point, everything we need has been completed and is ready for us to launch an attack.
Now we can set up our attacking machine. Here we are using Kali Linux with Vagrant
too, but you can use whatever OS
you prefer.
These are the tools that we are going to use:
If you are using Kali
, then everything has already been installed by default.
We are ready to go.
Enumerating our server
First, we need to check the server ports. We can use nmap
or ncat
to do it.
port scanning.
nmap output.
nc.
Our server runs Apache
on port 80
and MySQL
on port 3306
, but we do not have access to it.
Then using Dirbuster
, we can search for directories on the web server.
dirbuster.
As we can see, there is an admin site to which we do not have access, and a normal site to search for products.
SSRF attacks
Given that we have access to the search products site, then we can make a request and intercept it:
products request.
There we can see that it makes a request with a URL to retrieve the data. So, what happens when we modify the URL? Let’s change it to https://owasp.org/
:
simple SSRF.
Then it will load the OWASP
web page on our site:

ssrf vulnerable.
Now we have several options to work with.
Reflected XSS
Let’s create an
SVG
image in our kali machine with anXSS
payload and then serve it on a localPython
server:
local xss.
payload.svg content.
Then simply put your URL into the request and watch the result:
SSRF to XSS payload.

SSRF to XSS result.
Bypassing controls
As we saw earlier, we could not access the admin section of the server; this can be bypassed with this vulnerability:
SSRF to admin payload.

SSRF to admin result.
If the server had some local HTTP servers like a mongodb
database, we could bypass the access controls with this vulnerability.
Information disclosure
We can use
file://
to get internal files:
file usage.
We can also use the dict://
URL schema to connect to a server and send data:
dict usage.
This is useful when we find another vulnerable server or service, because we can send data to it and maybe even execute commands.
Port enumeration
.port enum
Cloud goodies
If the target uses
Amazon EC2
orGoogle Cloud
, then you can request metadata from them:
cloud SSRF.
Because the server uses cURL
, there are some URL schemas that this library does not support, like ssh22
, expect
, among others. For more information and payloads, you can go here or check this paper from OWASP.
Solution
The first level of protection against this attack is to implement input validation. It could be in the form of validating the domain name of the target host using a whitelist. With this, if the attacker tries to access more resources, it will be impossible for him.
Besides, if it is possible, avoid querying URLs using user input. Even if they are hidden fields, an attacker can modify them and exploit a SSRF vulnerability. It is better to request resources directly on the web server whenever it is possible.
Another way to do this is to prevent the web application to access only the resources that it will need by segregating the network. This will prevent access to other resources in the network, but it does not work against local access.
If you want more information about protections against SSRF, you can check OWASP or our Criteria.
Get started with Fluid Attacks' application security solution right now
Related posts