THM Linux Privilege Escalation Capstone Write-up
Nov 18, 2024
Hello all! Wanted to create a quick writeup on how to complete THM's Junior Penteseter Privilege escalation module. More specifically, how-to complete the capstone challenge.
Getting Started
We are given a user and login info for the user Leonard.
Username: leonard
Password: Penny123
Once the machine starts, we can freely ssh into his account with
input his password, and you have a basic account.
Once inside…
With the base account, we are only allowed to run all commands at a user level. We know this because when we run:
We are met with
So, that rules out a bunch of methods. However, there is something to note about the system we are operating on.
If we cat /etc/passwd
, we see that there is a user named 'missy'. This will be important later.
So what can we do to raise our privileges? Since Leonard can't run sudo, we should try and see if missy can. However, we aren't given missy's password— so we are gonna have to get creative and somehow access the /etc/shadow
file.
Lateral movement
So to access missy's account, we need to somehow read /etc/shadow. This is called a horizontal escalation of privileges. So let's see if there are any existing binaries on the system that will allow us to read sensitive files on the system:
Low and behold, our lovely friend base64 is executable at the root level.
If we do a quick search on gtfobins:
(base64) File read:
It reads data from files, it may be used to do privileged reads or disclose files outside a restricted file system.
So back to our system:
and like that, we got the password hash of missy.
Hash Cracker 2000
So now that we have missy's hash, we can use john
to crack the hash. I personally default to using rockyou.txt for the most part, but in a real-world scenario, it is probably best to crack the hash via a rainbow table. But since we are just working with a lab, rockyou.txt will be sufficient in cracking the password.
So on our primary machine copy and paste the hash to any file and run:
and we see here, missy's password is "password1", neat.
Queue the Hollywood line: "I'm in":
We got missy's password? Great, but that's not good enough. You see, missy is still just a regular user. She isn't root— but she is a step forward towards root. The next section will explain how to obtain root from her login, but first let's collect the user flag from /home/missy/Documents/flag1.txt
Grand Finale! Ultra Power Move (Over 9k): getting root'd:
First, login as missy:
Oh good heavens… before we confirmed that we horizontally escalated— can missy run any sudo commands?
OH LORD, MISSY CAN RUN find
AS ROOT. This is the moment we have been waiting for— this is how we obtain root baby.
How? Well… let's ask our friend gtfobins:
(find) Shell:
It can be used to break out from restricted environments by spawning an interactive system shell.
SOOOOOOOOO… we can get a shell as root REALLY easily, all we have to do is:
aaaaaaaaaannnnndddddd like that the system is totally owned. Time to collect our flag and dip :)
Conclusions:
So, to root this particular machine: you have to start from a user with no privileges, to a user with some, and finally strive to the ultimate goal of root. This lab helps users practice the following concepts:
Horizontal Privilege Escalation.
SUID binary abuse for read/write capabilities.
Hashcracking passwords
True veritcal privilege escalation via exploiting misconfigured
sudo
settings.
With that, I hope this write-up serves you well! Happy hacking!