About Kioptrix VM Image Challenges:
The Kioptrix VM’s offer simple challenges. The object of the game is to acquire root access via any means possible (except actually hacking the VM server or player). The purpose of these games is to learn the basic tools and techniques in vulnerability assessment and exploitation. There are more ways than one to successfully complete the challenges.
Video Walkthrough
Lab Setup
We will be using Kali Linux as our offensive OS and we will be running both Kali and the Kioptrix VM on VMware.
You can download the Kioptrix 1.1 VM from the following link: https://www.vulnhub.com/entry/kioptrix-level-11-2,23/
Our Kali VM has a local IP address of 192.168.1.106.
The Kioptrix 1.1 VM has a local IP address of 192.168.1.104.
Scanning & Enumeration
Let us get started by performing a Nmap scan on the target, we will be using the following arguments in our scan.
From the results, we can see that the target has various ports open, here are some of the interesting ones we should test:
- SSH – 22
- Apache – 80/443
- MySQL – 3306
On the SSH port, we have OpenSSH 3.9p1 running, which is not vulnerable to any known exploit, so this can be used as an access vector after we have exploited the system, let us move on to the webserver.
For Apache, we have both HTTP and HTTPS ports running, when we try loading up the website with port 443, we get an error informing us that the SSL certificate has expired, so we will have to access the HTTP version.
We are greeted with a simple admin panel, this is very interesting as it is a custom login screen developed in PHP and does not belong to any CMS, our first objective is to try and bypass the login screen with SQL injection.
SQL Injection
You can use the most common SQL injection queries synonymous with bypassing login in screens, after trial and error, we found that this query worked:
admin ' --
After we successfully bypassed the login in screen, we were greeted by an administrative web console, that allows us to ping computers on our local network. We can specify the IP and we get the results presented to us.
Command Injection
From running a few tests with various local IP addresses, it becomes clear that we are able to perform OS command injection, we can check if the commands are being filtered by breaking the initial statement and by using another command, in our case we used:
192.168.1.104; pwd
We specified the IP address and specified another OS command like pwd, which will print the current working directory if the commands are not being filtered. After running the command, it becomes obvious that the commands aren’t being filtered and we can run any system commands.
As you can see from the image above, after running the ping command and displaying the corresponding results, we can see the results from the pwd command, and it tells us that the current working directory is the default Apache directory, which in turn tells us that we are currently running commands as the Apache system user.
Spawning A Reverse Shell
The next step is to get access to the server by using a reverse shell, and since we can run system commands we do not need to use PHP, instead, we can use the bash reverse shell and specify our IP and preferred port (This is also because the target OS does not have netcat installed). We will be using the following command to spawn our reverse shell.
Before we execute the command, we need to set up a listener with Netcat, this can be done by using the following command:
After the reverse shell has been set up and is listening on port 1234, we can now execute the command.
After executing the command, we should receive a shell through the netcat listener we set up, and indeed we do. We are greeted by a bash shell with no job control.
We now have access to the target and we can begin performing some system enumeration, so as to assist with privilege escalation.
Privilege Escalation
We have determined that we are running CentOS version 4.5 running Linux kernel 2.6.9, our next objective is to search for any potential privilege escalation exploits that we can utilize. We will use searchsploit.
After searching with searchsploit we find an interesting exploit that meets our system criteria, the next step is to copy the exploit to our working directory and to upload it to the target for compilation and execution.
To copy the exploit over, we will setup SimpleHTTPServer and we will use wget to copy the exploit over to the target VM. We will use the following commands:
We can now use wget to download the exploit on to our target OS. We will download the file to the /tmp directory as we do not have sufficient permissions as the Apache user.
After we successfully download the file onto the target OS, we can follow the compilation instructions and execute the exploit.
After compiling and executing the exploit, we finally get a shell with root access!