Information Gathering
Rustscan
Only HTTP and SSH were open → Typical HTB Linux machine
Nmap
I ran nmap default script scan on it but nothing useful was found.
nmap -sVC -p 22,80 -v 10.10.10.84
Enumeration
HTTP - TCP 80
Accessing the target through browser, I see this webpage is hosting service that let’s you test local .php scripts:
It seemed that in.php, info.php, listfiles.php, and phpinfo.php scripts are provided as an example to be tested.
I typed in random file with .php extension to see what will happen and discovered that this service running on port 80 is opening file from /usr/local/www/apache24/data/browse.php.
Also I can tell that files that are in /usr/local/www/apache24/data are being opened.
So at this point, I had two plans:
-
Path Traversal Vulnerability?
-
Directory Bruteforce?
Directory Bruteforce
I first tried on directory Brute-forcing using Feroxbuster but nothing interesting was discovered:
sudo feroxbuster -u http://10.10.10.84 -n -x php -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt
info.php was one of the example scripts and it showed bunch of information including hostname and Kernel version.
Path Traversal (Success!)
I checked for path traversal vulnerability and luckily it was vulnerable to it:
http://10.10.10.84/browse.php?file=../../../../../../../etc/passwd
I passed the request to Burp Suite to play around with it more:
Following this article, I tried elevating path traversal vulnerability to RCE but it was successful.
Some of my attempts:
I was stuck at this point, so I went back through my notes again and I discovered I haven’t checked on example scripts yet.
listfiles.php
Opening listfiles.php, it revealed that there is a file named pwdbackup.txt:
pwdbackup.txt
Accessing pwdbackup.txt on browser, it showed me long encoded password hash:
Shell as charix
Cracking Hash
It says the password is encoded at least 13 times but it seemed to be encoded using base64 multiple times which could be easily cracked.
I created base64 decoder using python that it decodes until readable content is obtained:
Now I have cracked password: Charix!2#4%6&8(0
Remembering from /etc/passwd file earlier, user charix must be the valid user for this password.
SSH
As expected, using the cracked password for user charix and I was able to sign in:
ssh charix@10.10.10.84
Privesc: charix to root
secret.zip
On /home/charix, I found secret.zip
I tried unzipping it but it was asking for a password:
I decided to move the zip to local kali machine to crack it.
Using python http server and wget I was able to move it locally:
Using zip2john, I turned the zip file into john crackable format:
sudo zip2john secret.zip > zip.hashes
I tried cracking it using John, but somehow john wasn’t detecting any hashes which up until this point I still don’t understand why.
Since I failed on cracking, I tried password that I found for user charix and it worked!
However, unzipped file was not readable and it seemed that I have to take more steps to use this file.
VNC as root
Checking on what ports are open internally, I found VNC was open internally on port 5801 and 5901:
netstat -an -p tcp
On process, I was able to grep vnc running currently:
ps -aux | grep vnc
Looking at the process once more, it showed that vnc was being ran as root any it authenticates itself by grabbing password file from /root/.vnc/passwd:
Port Forwarding with Chisel (Failed)
Since chisel is my favorite port forwarding tool, I decided to go for chisel.
I first uploaded chisel to the target using Python HTTP server and wget:
Now on local Kali machine, I set up chisel server to listen on port 9000:
Back on target system, I tunneled port 5901 to Kali machine’s port 9000:
I forgot about this system being FreeBSD, so chisel won’t work here since it is coded for Linux AMD.
Tunneling with SSH (Success!)
Since Chisel failed, I moved on to SSH tunneling
ssh -L 5902:localhost:5901 -N -f -l charix 10.10.10.84
-L 5902:localhost:5901
: Specifies that the local port 5902 on my machine should be forwarded to port 5901 on the remote server.-N
: Instructsssh
not to execute any commands on the remote server after establishing the connection. This is useful when you only need to set up port forwarding without running any remote commands.-f
: Requestsssh
to go into the background just before it executes the command provided. This allows you to continue using the terminal for other tasks without keeping thessh
connection open in the foreground.-l charix
: Specifies the username (charix
) to use when logging in to the remote server. This is followed by the IP address of the remote server (10.10.10.84
).
I confirmed tunneling through nmap as such:
nmap -p 5902 -sVC localhost
Now using vncviewer and cracked zip file, I can VNC open the target machine as root:
vncviewer -passwd secret localhost:5902
Beyond Root
SSH Persistence
First go to /root/.ssh and generate SSH Private & Public Keys:
ssh-keygen -f mykey
Copy public key(mykey.pub) to authorized_keys using cat mykey.pub > authorized_keys
and now you will see these three files in .ssh directory:
I needed to copy private key(mykey) to my local Kali machine but Copy Paste wasn’t working on VNC environment so I set up a Python HTTP Server and download private key to my local machine:
Back in your target system, change permission for .ssh directory and authorized_keys file: chmod 700 .ssh
& chmod 600 .ssh/authorized_keys
Now I can SSH in as root: