June 28, 2017
Google CTF 2017 Mind Reader Write-up
June 28, 2017
MindReader was supposedly one of the easiest challenges at GoogleCTF and it’s after some guessing. So let’s start! First heading the challenge page we see a box with “read” button.First thing comes to mind is to try to test for “XSS” so a couple of XSS attempts were tested among them the following:
Unluckily the response was not as expected. Command injections techniques were also tried with a couple of “ls”, “cmd”, but also with no luck. Now the next step is to try directory traversal and it turns out that the host is vulnerable. The following traversals were tried but also with no luck.
Then after a couple of fingerprinting, it turns out that the environment is running some docker, so the main page was opened again and “main.py” was typed and the main script has shown up.
The script above uses “flask” framework and uses the function “index()” to run the tasks of reading the values entered in the challenge box. Line 6 tells us that there’s an environment variable which is asserted before running the function and Google presented us a hint that this environment variable is the actual FLAG. And giving the host is vulnerable to directory traversal, so the environment variable must be accessed in that way. Trying every combination using /proc/self/environ but it seems that we do not have access permissions.
A good knowledge of Linux systems comes into play, /proc/self/fd has symlinks to /dev/fd and this means that in Linux there are relations between environment variables and file descriptors to allow us to access environment from file descriptors or from /dev/fd that starts from 0,1,2 and so on.
So trying /dev/fd/0 nothing but trying /dev/fd/8 gives us this.
Coupled with directory traversal
And the flag has been captured!