Defeating RootME
Hello hackers,
Recently I started practicing on Tryhackme and came across this easy yet interesting machine named RootME by ReddyyZ. I strongly recommend the beginners to try this machine out as it would clear the following several concepts of yours one of them being how to bypass file upload functionality and gain a reverse shell on the target system. Not only that, but you'll also have a basic idea about how privilege escalation works. So without taking up any more time of yours, let's jump into the walkthrough.
: TASK 1 :
Deploying the machine😅
While some of you might think what madness this is we already know that!!
My dear friend, you're free to skip this portion then😊😌.
Step 1: Connect to OpenVPN [Check the OpenVPN room so that you have an idea]
Command used: openvpn {your openvpn file}
Step 2: Click on Start Machine or Start Attack Box. [I think you can do this:)]
Step 3: That's all. Congratulations! You successfully completed task 1!
P.S Don't forget to click on Question Done :P
: TASK 2 :
Reconnaissance 🕵
Having deployed our Machine, let's jump right into recon/information gathering.
Q.1 How many ports are open?
Q.2 What version of Apache is running?
Q.3 What service is running on Port 22?
Train yourself in such a way that whenever in your life, you hear a question where it asks information regarding ports, your inner voice should say, NMAP!
Let's shoot down all the three questions given above with a single line of command.
Command used: nmap -sV {ip}
The -sV switch will display the services as well as their versions.
While the question focuses on Gobuster, I really don't know what was wrong with my system Gobuster just didn't work.
A good alternative to it is dirb and is installed by default in your kali machine [if you have one].
So I fired dirb and got these directories.
Now, as you can see we have the uploads and the panel directories present.
Let's visit both of them.
Moreover, another point to note is that the uploads directory will also be helpful to us further.
: TASK 3:
Getting a shell🐚
Let's jump into the task and upload a shell.
You can download a PHP reverse shell from the web. Here's a link for the one which I used.
https://github.com/pentestmonkey/php-reverse-shell
Having downloaded the shell, let's try to upload it.
To begin with, learning Portuguese, the above sentence says PHP is not allowed.
Well in real-life scenarios as well, the file upload functions are strict and you generally cannot upload PHP files to places where you are supposed to upload a resume, photos, etc.
But sometimes what happens is that the upload function blocks a specific extension but similar extensions are still accepted. For example, PHP has various versions such as PHP3, PHP4, PHP5, etc.
As an attacker, you can always keep an eye on such possible misconfigurations.
In this case, we can bypass this upload function by using the php5 extension.
Escalating privileges 🚩
Here comes the final showdown.
Q.1 Find file containing suid bit.
Q.2 Find a form to escalate your privileges.
For finding a file with suid bit, we type find / -user root -perm /4000
The significance of the file containing the SUID bit is that even if we run it, it will execute as the root user
Here, the weird file seems to be /usr/bin/python as per an educated guess from the answer pattern.
Thus we got the answer to Questions 1 & 2.
Now comes the last one.
Well, the hint in question 2 days that visit GTFObins.
We can find SUID here and copy the code.
Thus our command will be
cd /usr/bin
./python -c 'import os; os.execl("/bin/sh", "sh", "-p")'
type whoami to see whether you're root or not
Since we're root now the final question left is
Q.3 root.txt
For finding root.txt, we can simply type
find / root.txt | grep root.txt
That's all... The final command will be cat /root/root.txt
You'll find the final flag there and that's how we defeated RootME.!
Key Takeaways:
- Whenever you come across questions related to ports and services, NMAP can come in handy.
- Make sure to remember some common port numbers and services associated with them.
- Try to look for hidden directories. You might end up getting something juicy.
- Always try to bypass file upload by using alternative or similar extensions.
- Once you upload the shell, try to locate it so that you can access it.
- Try to find files with SUID bits for privilege escalation.
If you like the content then do consider connecting with me and pour your knowledge into my DM!!😇
Instagram: bhavak_29
LinkedIn: https://www.linkedin.com/in/bhavak-kotak-3b6b071b1/
DO NOT FORGET TO CHECK OUT TRYHACKME FOR MORE INTERESTING ROOMS.
Comments
Post a Comment