
Introduction
This room will cover SQLi (exploiting this vulnerability manually and via SQLMap), cracking users hashed passwords, using SSH tunnels to reveal a hidden service, and using a Metasploit payload to gain root privileges.
Scanning & Enumeration
Target IP: 10.10.244.64
Nmap Scan
As we already know we only have HTTP and ssh.
Enumeration
HTTP Enumeration

The guy with the sniper looks like a hitman, but still no perfect hit. Let us see if the name of the image reveals this info.

Let us use reverse image search option on google.

We notice a login screen. Since we know that the room is going to have SQL injection, we can try to use sqli on the login form, my favourite is
I set this value for both username and password and wait for the results.
In case you are wondering how to learn more about sqli, this is a really great resource - Audi-1 SQL Injection Labs

Vulnerability Analysis
After successful login, we see a search portal. Let us try to insert ' here and see what happens

We see that error message is being displayed. We already used SQL injection to bypass authentication, and the error messages here make it more apparent.
Exploitation
We see the source code of the search form

We find out that the request being made is a POST request, and the id is ‘searchitem’.
Thus we need to use sqlmap for a post request.
If you are wondering, what is sqlmap, it is an automated script that is very helpful during penetration tests, here is a link.
For POST Request, we got the following blog : https://hackertarget.com/sqlmap-post-request-injection/
Copying those steps …
- Set-up burp and intercept the POST request

- Copy this request to a text file, lets call it ‘search.txt’.
- We can turn off burp now. And run sqlmap with
sqlmap -r search.txt -p searchitem
Directly copy-pasting did not work for me. So I went to HTTP History. And then choose ‘copy to file’. Once we do that, ‘sqlmap -r search.txt -p searchitem’ should work.

We see that the parameter is vulnerable.
adding --tables gives us a list of all tables in different databases.

This one looks like has more information
But before that I know that we can also try to spawn a shell using --os-shell
It asks us for programming language info, we can check that

it supports PHP, well looks like we do not have write permissions.
Let us see the contents of the database — db
For ‘post’ we see that there are 5 entries and for users, there is just one.
Hashed Password: ab5db915fc9cea6c78df88106c6500c57f2b52901ca6c0c6218f04122c3efd14
Username: agent47

We use hash-identifier to identify the type of hash. Most likely it is SHA-256
To find the password, we can use hashcat. This website has all the examples for breaking different types of hashes.
We see that SHA-256 uses a hash-code of 1400. Hash-code is used by hashcat to select the hashing algorithm and use a wordlist to crack it.
Easier Option is to just visit this website: https://md5decrypt.net/en/Sha256/#answer
and enter the encrypted password.

Just in case if we still want to use hashcat, here is how to proceed.

Now that we have the password, let us try to ssh on the machine using agent47 as username and videogamer124 as the password.

And we were able to successfully log in.
Privesc

Reading this gives us some information about how SSH port forwarding works.
Let us see which sockets are open on the machine.

Talking about TCP, we know 3306 is MySQL, 22 is ssh and 80 is web. We do not know what exists on 10000.
When we try to connect, it says that connection is refused. Let’s use ssh forwarding.
ssh -L 10000:localhost:10000 [email protected]

Once we have this, let’s check our localhost:10000, and see what exists.

We see a login portal again. Let’s try to use our ssh credentials here, woooooot! It works.

Then we try to search this on Searchsploit

We find one Metasploit module. Let’s try google

Rapid7 is essentially Metasploit results and viewing that page shows how it can be used to exploit the Webmin.

Even exploitDB refers to the Metasploit module here

The best we can do now is look at the code, and try to figure out what this exploit is all about.

This part is mostly about meta-data. We see different descriptions being set, also we notice that it is Remote Command Execution.

We see that it is Privileged. We see the Payload option here. It is using cmd for Unix and Perl.

Next, we see how the checks are being done, 1&2 are used to check if we have the correct authentication, and 3&4 tries to check if ‘/file/show.cgi/bin/{something random}’ returns a status code of 200 or not. A return status code of 200 means that the resource was found on the server. The 200 status here indicates that the version is vulnerable.
Let us see the exploit section. Metasploit gets the username and password and checks if we can successfully authenticate.
Continuing, we see that an encoded payload is stored as ‘command’ which is then used to send a request to
/file/show.cgi/bin/#{something_random}|#{command}|
If you are thinking like I am, I think we can generate a payload, and manually hit the URL and catch the spawned shell using netcat, otherwise, we have Metasploit at our disposal anyways :P
We can either use msfvenom to build our payload or simply pass the command for a reverse shell on to the server. Let’s use the Pentest Monkey reverse shell cheat sheet (link) and we copy the Perl script for the reverse shell.
We need to add our listener IP and port ( here 10.4.9.255 and 4444 respectively ) and use the format with our netcat listening on 4444.
/file/show.cgi/bin/<random>|<cmd>|

We finally get the root shell! Adding the complete URL here just in case someone is trying…
I was curious to know what this show.cgi was, so I tried to look for the file on the server as user ‘agent47’


This suggests that show.cgi can also be used to get all files on the server, and since we are root, we can essentially get everything from the system.
Let us see if we can actually get files on the system.

And we were able to do that.
Parting Thoughts
Sometimes reading source code of msf modules for exploits can help us leverage that information to get shells.
We learned SSH port forwarding and yet another way to Privesc !!
I have skipped the PoC for Metasploit, but I have added the steps in a screenshot above.
Feedbacks are really appreciated. Thank you for reading, and if this helped you in any way, share it with others :)