KYBC 2021 - Maze 1 Writeup

The site is basically a search box that checks for matching txt files and then redirects to to display the content of the file. flag.txt obviously leads to a fake flag, but the whole thing looks like a potential LFI.

Trying to reach a file with an extension other than .txt results in an error. However, appending an extra f parameters after one with the .txt extension lets me bypass the extension check and access the content of the last file.

The txt files are inside a files/ folder and there seem to be some sort of sanitization mechanism, since ../ get stripped away. However, the filter applies only to that specific pattern, so ....// becomes ../ after sanitation and allows me to look up into the parent folder.

Combining the two bypasses together gets me the etc/passwd file:`

The flag doesn't seem to be there though.

Let's see if it is possible to turn this LFI into an RCE, since trying to guess name and location of the flag doesn't sound like a realistic strategy.

By examining the proc/self/fd folder I discover that proc/self/fd/11 stores the serialized parameters of the search request. Let's see if we can write by making a POST request containing <?php system('id'); ?>

and check the proc file again

Yeah! The code gets executed and the result gets saved into it!!

Let's run ls /

and check the outcome in the proc file. No flag in the root folder, but home/ctf_user1 seems interesting:

there's the flag - let's cat it!

Success! FLAG_c4a66ead822b8d2dd42da826eb180371

Go Top