Introduction

(this write-up has been sent to google for evaluation and it’s copyrighted, so if you want to send your own solution..it’s over yesterday.. you have to be registered in the scoreboard for your write-up to be considered)

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 a “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:

<script>alert(test)</script>

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 were to try directory traversal and it turns out that the host is vulnerable. The following traversals were tried but also with no luck

../.././../etc/passwd

../../../../etc/shadow

../../../../etc/resolv.conf

../../../etc/hosts

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’re 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 tying /dev/fd/8 gives us

Coupled with directory traversal

/dev/fd/../environ

And the flag has been captured

About the Author

Mastermind Study Notes is a group of talented authors and writers who are experienced and well-versed across different fields. The group is led by, Motasem Hamdan, who is a Cybersecurity content creator and YouTuber.

View Articles