Box Stats
Box Info | Details |
---|---|
Box Name : | DogCat |
Difficulty : | Medium |
Play : | DogCat |
Recommended : | Yes ![]() |
Summary
This was an awesome box, with lot of LFI, php analysis etc i’ll not say much, let’s start!
Enumeration/Reconnaissance
Now as always let’s continue with a nmap scan.
1 |
|
Once we visit the website, we can see 2 buttons A dog
& A cat
.
We click a random one and we can see the URL goes like that ?view=dog
, that’s probably LFI. LFI (Local File Inclusion) allow us to read files on the victim machine. The most common way to test that is by using the /etc/passwd
file. Let’s try it.
http://$ip/?view=/etc/passwd
-> This gives an error Sorry, only dogs or cats are allowed.
Let’s try to add dog or cat in the URL.
http://$ip/?view=dog/etc/passwd
-> This gives an error Warning: include(dog/etc/passwd.php)
We can see it adds .php
in all files, we can’t read /etc/passwd
but we can read the index.php
source code! When we have LFI we can’t read php files because they get executed by the webserver. So we will do a trick to bypass that using base64.
Also here we have to apply a directory traversal attack ../
1 |
|
After we decode it we have the source code:
1 |
|
Now we have to do source code analysis. The most important thing in the source code is this variable:
1 |
|
We have a ternary operator
, is an alternative method for using if-else statements. The syntax goes like that:
(Condition) ? (Statement1) : (Statement2);
We have the $_GET
, is a PHP super global variable for collecting form data. For example $_GET['pwn']
in URL will be like that ?pwn=
So it translates to ext
parameter should be equal to the ext
GET parameter, else will it use .php
So we just have to add &ext
to URL to read files.
1 |
|
Shell as www-data
Now we need to turn LFI into RCE. We will do apache log poisoning but to do that we need to be able to read log files. Let’s try to load apache access.log
file. /var/log/apache2/access.log
Perfect, now let’s fire up burp. Capture the request and inject this php code inside user-agent <?php system($_GET['pwn']); ?>
also add to URL the parameter &pwn=whoami
We have RCE!
1 |
|
Now we can simply send our reverse shell (remember to URL encode!)
1 |
|
1 |
|
Let’s search for the flags:
1 |
|
Flag 1: THM{Th1s_1s_N0t_4_Catdog_ab67edfa}
Flag 2: THM{LF1_t0_RC3_aec3fb}
Shell as root
Now privesc to root is simply, let’s just check sudo -l
:
1 |
|
We can run env
as root, easy to exploit.
1 |
|
Flag 3: THM{D1ff3r3nt_3nv1ronments_874112}
Hm.. we miss 1 flag tho. If we check the system root directory, we can see that we’re inside docker container.
1 |
|
We can also check that by the container id in the hostname.
1 |
|
Checking around the system i found under /opt/backups
a backup.sh
file, seems like is running in the background. Let’s add a reverse shell in.
1 |
|
1 |
|
Flag 4: THM{esc4l4tions_on_esc4l4tions_on_esc4l4tions_7a52b17dba6ebb0dc38bc1049bcba02d}
Thank You
Thank you for taking the time to read my writeup. If you don’t understand something from the writeup or want to ask me something feel free to contact me through discord(0xatom#8707) or send me a message through twitter 0xatom
Until next time keep pwning hard!