Friday, June 15, 2018

PwnLab: init


- Layout for this exercise:


- The goal of this exercise is the study of the hacking process for the vulnerable machine PwnLab: init

PwnLab: init can be downloaded from here:,158/

- Once downloaded and extracted with VirtualBox:


- Using netdiscover to find the presence of host that corresponds to the vulnerable machine PwnLab: init

- Scanning with nmap:

- Launching nikto against the host we find two interesting files, the first one config.php may contain a database credentials:

- dirb scans the website:

- Connecting with the browser:

- There is a login page:

- There is also an upload page that can be use once logged in:


3.1 - Local File Inclusion

- At this point, let's try an LFI attack by using curl and php://filter to find out data inside the web pages.

- About PHP filters:

- Following directions in these examples:

'... This forces PHP to base64 encode the file before it is used in the require statement. From this point its a matter of then decoding the base64 string to obtain the source code for the PHP files ..."

- Starting with login page:

- Same thing for upload:

Same thing for index:

- Same thing for config:

- Decoding the outputs with:

- config.php gives us the credentials for a database:

- login.php refers to the previous database and the file config.php:

- upload.php tells us that the uploaded files must be images of extensions .jpg, .jpeg, .gif,.png and MIME content-type:

- index.php reveals the presence of the parameter lang as a cookie with the include function, what could carry crafted content for our purposes:

3.2 - Exploring the database

- Let's exploit the database using credentials revealed at config.php:

- Searching for databases:

- Using Users:

- Showing the tables:

- Selecting from users we discover the existance of the users kent, mike, kane and their passwords encoded with Base64:

- Decoding the passwords:

3.3 - Uploading a PHP script to achieve a shell

- Now let's use the credentials to access the upload page:

- Let's try to upload the php-reverse-shell.php script provided by Kali. 

- Copying it to a working directory:

- Renaming with a .gif extension:

- Opening and adapting the exploit image.gif to our needs.

- On the one hand:

- On the other hand:

- Using kent to login:

- Uploading image.gif:

- Viewing the source we see that the file is stored as a md5 hash:

- Crafting the lang cookie by including the image:

- Opening Burp and intercepting a new upload:

- Now, the PHPSESSID cookie must be erased and replaced with the crafted one carrying the reverse shell script stored at /upload:

- Setting a listening session with netcat:

- The moment we Forward the request a limited shell is successfully achieved:


- First, let's start by importing a better shell:

- Checking /home directory:

- Changing to kane:

- There is a file called msgmike:

- Trying to read its content, we discover that it is an executable file:

- Running ./msgmike it reveals the presence of another msg.txt at mike's home folder, but the cat command fails to find and open it because is called without full path:

- The explanation could be that there is SUID (Set Owner User ID) on the file msgmike for access permission, so owner permissions about the file would be achieved when executing the program:

- A solution is to create a new cat, modifying the environment variable PATH (changing order of execution) for the new cat so that mike can execute /bin/bash

- Following these directions:

- Now, the PATH has changed because it has been exported to .:

- Running ./msgmike we have access to user mike due to the bit SUID:

- There is another executable file msg2root (with SUID for root) at mike's home folder:

- Running ./msg2root and passing the message /bin/sh a root shell is achieved:

- Let's notice that euid=0(root), being euid the Efective User ID.


- Going to the root folder there are two text files: