Proteus

Back from the second hiatus of the year, and not wanting to do writeups for the Practical Pentest Labs since they’re scored, I decided to give the most recent Vulnhub VM a try. Little did I know, I was going to spend a good 15 hours completely engaged with it.

I load up the VM, and do a quick nmap scan to locate it on the host only network:

Only 2 ports come up on the basic scan, so I figure running a more intense scan may be worth the effort:

The login form is probably the easiest to exhaust basic checks on, so I try that route first………..No dice. Trying some default user credential combinations doesn’t yield a successful login and basic attempts at SQLi login bypass fail as well. So I turn my focus to the upload form. Just to see what the form allows me to upload, I try uploading a picture and get a complaint about the mimetype being invalid, so it’s doing some basic checks at the very least. Modifying a php file with the header of a regular binary such as /bin/ping with hexeditor:

Bypasses the mimetype check which then spits out the contents of the file directly onto the samples page source:

This is nifty because I can now manipulate the page directly, but this ends up being a time consuming:

XSS on a VM like this is generally useless, so I give up on this route and go back to the drawing board on how I’m going to exploit this login form. The strings and objdump output on the “Analysed Samples” page make me wonder if it’s running the actual commands on the uploaded files like “strings filename.bin; objdump filename.bin”. Uploading the ping binary seems to confirm this theory, so I compile a basic C program to use in place of ping:

C

1

2

3

4

5

#include <stdio.h>

intmain(void){

printf("blah");

return0;

}

Shell

1

gcc cfile.c -o exploit.bin

I confirm that the exploit.bin file can still be uploaded without issue:

Cool, looks good. Now to open up Burp and start appending stuff to the end of the filename to see if we can get RCE:

Burp repeater shows that we have RCE! I check out the directory, cat the index.php to find nothing useful, and then try to “cat /etc/passwd” only to find that the command failed. I try running “cat .htaccess” and this fails as well. It must not like “.” and “/” characters. This means I have to start encoding my commands. I try doing a basic echo command with a base64 encoded string, but that seems to fail:

Hex encoding the command options seems to work better, however:

Trying this method to output /etc/passwd also works perfectly:

Awesome! I’ve got reliable RCE! Now to turn this into a shell. I start by checking to make sure python is installed on the target system and confirm that it is. Next thing is to create an msfvenom payload to start a meterpreter shell up:

Voila! We have a working shell! Looking around the web directory, I found the config.php file and it had MySQL creds in it:

PHP

1

2

3

4

5

/* MySQL */

constMYSQL_USERNAME='root';

constMYSQL_PASSWORD='viWJ.cgdf&3a]d3xh;C/c]&c?';

constMYSQL_HOST='127.0.0.1';

constMYSQL_DATABASE='proteus_db';

Logging into MySQL provided me with the password hash for the malwareadm account as well, but I didn’t spend too much time trying to crack it. Attempting to log into the root account with the MySQL password also failed. Moving on from there I go down to the “/home/malwareadm/sites/proteus_site” directory and find a root owned setuid binary file called admin_login_logger:

Attempting to run this file without any arguments provides a usage excerpt. Inserting a word into it produces valid output:

I then try to access that file without success:

At this point, I’m thankful I chose to use a meterpreter shell because it’s a breeze to download/upload files. This is definitely a file I want to look at locally. After downloading the file, I create a valid path for the log to be written and I check to see what it writes:

Ok, it’s writing whatever is added as the argument. I begin to wonder if I can crash it so I whip out pattern_create.rb and set the output to 500. I then take that created pattern and use it as the argument for the binary:

Houston, we’ve got a crash! What’s even more interesting is that instead of writing to “/var/log/proteus/log” it wrote to a file named after the place in the pattern that broke it:

Nifty! Now I need to find out what the position of that pattern was so I can replicate the crash in a more controlled way. I can’t use pattern_offset.rb, though because I’m not working in GDB and it expects a hex value. To get over this hump, I wrote a very basic string position script in python:

Python

1

2

3

4

5

#!/usr/bin/python

string="Insert pattern_create.rb output here"

result=string.index("Insert written file pattern here")

print(result)

Running this script tells me that the crash happens at 456 bytes. The next step will be to make a payload that we can control. I wrote another python script to handle this part:

Python

1

2

3

4

5

6

#!/usr/bin/python

buff="\x41"*456

tarpath="test"

print(buff+tarpath)

Taking this script, running it, and using the output as the argument for admin_login_logger makes it crash again, but this time writes it to “test” in the current working dir. The content of the file is the entirety of the payload we gave it:

Changing the word “test” with the word “/var/log/proteus/test” has the same effect and writes the output to whatever is specified after position 456. Keeping in mind that this file is run as root via setuid on the target machine, this should mean that we can overwrite files owned by root. Which takes me to the next discovery in that this binary doesn’t overwrite files, it just appends to them.

I first try to target root’s known_hosts file, but this fails because I can’t separate the buffer text from the end of public key. I figure the next easiest route at this point will be to just add myself as a root user in /etc/passwd. After toying with this for a while and having issues with “su” because “/bin/bashAAAAAAAAAAAA…” isn’t a valid shell, I finally landed on something that worked:

Python

1

2

3

4

5

6

7

#!/usr/bin/python

passwd="'z00n:<openssl passwd -1 password here>:0:0::/root/'"

buff="\x41"*(456-len(passwd)+2)#+2 because '' don't count

tarpath="/etc/passwd"

print(passwd+buff+tarpath)

Running the result of that command as the admin_login_logger argument gives us:

The crash and write to /etc/passwd! Trying to log in gives us:

Root! And finally, after navigating to the /root/ dir, copying the flag to “/home/malwareadm/sites/proteus_site/web/public”, and pulling it up from the browser, I am rewarded with:

Ha! I feel like a real HACKERMAN after that VM. Good job @viljoenivan on the awesome VM! Seriously the most entertaining thing I’ve done in ages!