The first machine captured on OffSec Proving Grounds
So I paid for OffSec…
Today I started doing OffSec machines on Proving Grounds. The first machine that I solved was called “Exfiltrated”. Basically, this machine is about exploiting ExifTool vulnerability that can cause a privilege escalation.
An all seeing eye
Like a member of the Illuminati, I started a scan with nmap. The output is quite interesting because it parsed the robots.txt file and allowed me to see some disallowed entries:
1 | |
Ok. To be honest, I have never interacted with this CMS (Subron CMS), and I have no idea what’s happening here, but I’m quite sure that /panel/ and /backup/ will be interesting. When I tried to enter the website with Firefox, it tried to redirect me to [http://exfiltrated.offsec/](http://exfiltrated.offsec/)URL. Ok, now I have to add a new entry in the/etc/hosts` file, and you have no idea how often I forget IP addresses!!!
After I made a connection, I quickly saw the sign in and sign up sections. Of course I tried to create an account, and actually I managed to create SEVERAL accounts. Now you’re going to ask why I made several accounts. Well… none of them actually worked. I had to go to /panel/. It was a sign-in page for the admin of the website. Kind of like the WordPress login page on /wp-login.php. I have this magical methodology: If a website has a CMS on it, don’t try directory brute force. I just went with credential guessing, and you’ll NEVER guess what the username and password were. It goes like this: admin:admin. I’m dead serious. I was the admin, but I saw no flag. Alright, maybe the flag can be taken from the shell. So I started looking for exploits. I know the version from the whatweb command:
1 | |
Now I can just search the exploit with searchsploit. This is what I have found:
1 | |
The most interesting has to be the third one. There is no need for XSS during most CTFs (about 99.99% of them), and in this scenario there is no need for CSRF so it has to be the Arbitrary File Upload exploit. I took it and ran it. It has to have several parameters in order to work:
1 | |
Alright. I have a webshell, which doesn’t work. I don’t know why, but when I try to run a command, I just get the HTML of the webpage as the output. There is no command output injected in the code. This means I have to get a reverse shell.
The shell that walks backwards
Alright. I went here and searched for Perl reverse shell. This is the exact payload that I used against this machine:
1 | |
At the same time, I was listening on the 4444/tcp port locally in order to get the shell. REMEMBER! Always obtain a prompt after getting a reverse shell. This can be simply done by using Python and then exporting the $TERM variable in a shell:
1 | |
After I run that little command I went from LITERAL NOTHINGNESS to this:
1 | |
Personally, I think this is much better than having no prompt. How are you even working like that?
Alright, I have obtained the shell, but I have a problem. I’m www-data instead of root and this makes me mad. I decided to upload [linpeas.sh](http://linpeas.sh) the script from my local machine to the target. After that I ran the script and discovered an interesting script called [image-exif.sh](http://image-exif.sh). It was located in the /opt/ directory. This is the content of that file:
1 | |
As the description of this machine said, I have to exploit this. I searched for ExifTool exploits and found one here. After that I ran the script:
1 | |
So now I have a new image.jpg file that I can upload from admin panel. But before I do that, I have to listen on port 5678/tcp in order to receive a connection. This is a second reverse shell, man, what the hell.
When I uploaded this image ncat which was listening on port 5678/tcp actually received a connection. I ran the whoami command to make sure I was the root user and not some weird user created for a web server. I WAS ROOT! I found a proof.txt file, which obviously was a flag.
Then I went to the /home/coaran/ directory and found the local.txt file, which was the user flag. So I submitted both flags and finally solved the challenge.
What went wrong and why?
During the challenge I faced several problems. I always hated Exploit-DB problems because they never ran correctly and always had errors. I think people who upload on that platform don’t actually know how to write clean code that works. Oh, also, most of the code that you see there is Python2 which died before Cleopatra was even born. My frustration during these CTFs is that I always face exploits that were written by stupid people! Imagine not being able to correctly handle errors in your code. Why are you doing that to me? Can’t you write try/except blocks? It’s two lines of code. Mostly they don’t even add a manual on how to use the exploit!
I have to be honest, those two exploits had explanations (some), but what about the other million times?
CVE analysis
I would like to analyze CVEs that I used during this challenge. Here, I see the explanation of the vulnerability.
1 | |
Alright, the problem has to be with the .htaccess file that allows PHP to execute .pht or .phar files. The first file extension is a PHP script that contains HTML code. The second one is a PHP archive. I checked the /panel/uploads/ directory for this CMS, and it is the place where the admin user uploads files. I now understand why I failed at first. I’m not quite sure, but this has to be the explanation: I tried uploading files as a regular user (not from the admin panel login). When a normal user uploads a file, it doesn’t go to the /panel/uploads/ directory. It goes to somewhere else that is not vulnerable.
The exploit shows JSON data that’s being sent to the server.
1 | |
Alright. "<?php system($_GET['cmd']); ?>\n\r\n" This is malicious PHP code that’s being uploaded to the server. It means I can use ?cmd= parameter from the web to run commands on the target machine.
The second CVE that I used was CVE-2021-22204. When ExifTool was being run during image upload, it was possible to inject PERL code inside:
1 | |
This was the description of this CVE. Here, you can see the full exploit. On line 847 there is an interesting part:
1 | |
This is the command that’s being injected into ExifTool through the image that we upload. After payload configuration, this script runs several system commands that finally create a malicious image.jpg file. When I uploaded the image as administrator, it went to ExifTool and when it started processing the image, PERL code was injected. bcode variable is interesting. I think injection happens because of many A characters that it has inside. From line 526 to line 779 there are only A characters that have to be a padding for the injection.