Continuing from b-Identify SSRF
, let’s move on to exploitation part.
Accessing Restricted Endpoint
Let’s use ffuf
to directory bruteforce for more open pages.
Server at dataserver.htb Port 80
is used to filter out HTTP 403 responses below:
LFI
We can use such command below to read /etc/passwd
file:
dateserver=file///etc/passwd&date=2024-01-01
Gopher Protocol
Let’s say we found a login form as admin.php
:
dateserver=http://dateserver.htb/admin.php&date=2024-01-01
We need to send a POST request with the credentials, but we cannot do so with the http://
URL scheme.
We can use gopher
URL scheme to send arbitrary bytes to a TCP socket.
Let’s say we want to try common password such as admin
, we can send the following POST request:
We are going to URL encode all special characters and construct a valid gopher URL (spaces (%20
) and newlines (%0D%0A
) must be URL-encoded).
When converted to gopher URL scheme, above POST request will look like below:
gopher://dateserver.htb:80/_POST%20/admin.php%20HTTP%2F1.1%0D%0AHost:%20dateserver.htb%0D%0AContent-Length:%2013%0D%0AContent-Type:%20application/x-www-form-urlencoded%0D%0A%0D%0Aadminpw%3Dadmin
Now let’s inject above’s gopher command to our original POST request.
Since we are sending our URL within the HTTP POST parameter dateserver
, which itself is URL-encoded, we need to URL-encode the entire URL again to ensure the correct format of the URL after the web server accepts it.
Upon sending the above traffic, we can try whether the password worked out or not.
Imagine we identified SSRF vulnerability and TCP port 25 is open locally, we can do so many thing using this.
Gopherus
Constructing gopher URLs can be tricky so we can use tool such as Gopherus to generate gopher URLs for us.
The following services are supported:
- MySQL
- PostgreSQL
- FastCGI
- Redis
- SMTP
- Zabbix
- pymemcache
- rbmemcache
- phpmemcache
- dmpmemcache
We need Python2 for running this tool.
Let’s try generating a valid SMTP URL by supplying the corresponding argument.
Tool asks us for input details about the email we intend to send. Afterward, we are given a valid gopher URL that we can use in our SSRF exploitation: