Search

Type to search posts.

es
HackConRD CTF 2024: Broken Production

HackConRD CTF 2024: Broken Production

Junior Restituyo
0xR3iko

We started by going to the portal to see what we were facing: a login page shows up. We tried some SQLi and took a look at the source code, but nothing was found.

Member Login page of the challenge portal

Moving forward, we created an account to log in to this portal.

Registering a new account on the portal

At first glance we can see that our role is Employee and we are not Admin. This user has limited access, so we went to take a look at the source code we received as a foothold.

Logged in as an Employee with limited access

Files:

Source code files provided with the challenge

Taking a look at the Dockerfile we saw some interesting things, like configuration files and routes, as well as a fake flag followed by the creation of the real flag we’re looking for. Here we can note the creation route /, as well as the fact that the flag has some random numbers in its name.

Dockerfile revealing the flag creation and its randomized name

Moving forward, in the files we found challenge/SessionHandler.php. Here we can see that the session is controlled by a PHPSESSID cookie that equals a JSON {"username": username} encoded in Base64.

SessionHandler.php showing the Base64-encoded PHPSESSID cookie logic

Knowing that we need the admin session, we encode this information into Base64 and get the cookie we needed.

Encoding the admin username as a Base64 cookie value

Setting the forged PHPSESSID cookie in the browser

Once logged in as admin, we can see that we have the option to view the server logs.

Admin panel with the option to view server logs

Going back to the files provided, we take a look at challenge/view/admin.php. Here we can see the utils directory that is received through a GET request, and it appears to be sanitizing ../ in anticipation of an LFI.

admin.php sanitizing ../ in the utils GET parameter

We tried to bypass this sanitization, and we were able to find an LFI using ....//.

LFI achieved by bypassing the filter with ....//

With this LFI and access to the server logs, we can try to sneak in through log poisoning.

Reading the server access log through the LFI

For that we go to Burp Suite and change the User-Agent to <?php system($_GET['cmd']); ?>.

Injecting a PHP payload into the User-Agent header with Burp Suite

Now, using a new query parameter cmd, we can run commands and check the logs for any response.

Executing a command through the poisoned log entry

Command output returned through the log poisoning RCE

After that, we enumerated the root directory and found the flag flag_08d4f2e9753d32.txt.

Enumerating the root directory and locating the flag file

Reading the randomized flag filename

Finally, we got our flag.

Retrieving the flag through the RCE

The flag returned in the response

Thanks for reading.