PicoCTF 2018: Grep 2 Solution

Located in the miscellaneous section, 125 points

Silver
3 min readOct 14, 2018
Image showing what PicoCTF problem we will be solving

Problem:

This one is a little bit harder. Can you find the flag in /problems/grep-2_2_413a577106278d0711d28a98f4f6ac28/files on the shell server? Remember, grep is your friend.

Hint:

grep tutorial

Solution:

First of all, we need to start by gathering and opening up all the resources that we will be using. Open up PowerShell on a separate window and login if not done so already. Copy the link that the problem is asking you to go to, and cd into it in PowerShell. After that, you can use the ls command to see what is inside this directory it wanted us to go to. We can see 10 directories that have names ranging from files 0 to 9. Our goal is to find the flag somewhere in this directory, but it would take far too long to manually look at each file and all the information stored in each file.

Image showing what you should see in your PowerShell

This is when we use grep to help us out. Grep can be seen as like a tool that is similar to a search bar. You can use it to find specific keywords inside of text files, instead of trying to find it manually. It is a very simple and easy tool to use, as long as you know what you are doing.

When using egrep or just grep, you just need to follow this layout, egrep [command line options] <pattern> [path]. Command line options are not always needed, but they are extremely helpful. Pattern is the text that you are looking for. Path is the text file(s) you are searching in to find the text you are looking for.

For this problem, we are looking for a flag, which usually follows the format of picoCTF{}. Knowing that, we just need to use egrep to look at all the files and see if it finds any text with the words picoCTF. We will also be using the command line option of -i, so that our word search is not case sensitive. There are a total of 10 directories, each containing 30 text files. Instead of checking and typing out each text file one by one, we can just use the star(*) symbol for our path. It will check every text file in that directory for the words you are looking for.

Image showing the use of egrep on files0

Cd into the first directory called files0, then use this grep command to search for the flag in each text file, egrep -i ‘picoctf’ *. In files0, nothing will pop up, meaning that the flag is not in any of those text files in that directory. Cd out of that directory, and do the same thing for the rest of the directories until you find the flag.

Image showing what pops up when using our grep command in the directory called files3

When we got to the directory called files3 and used our grep command, PowerShell displayed this to us, file20:picoCTF{grep_r_and_you_will_find_8eb84049}. That means that in the text file called file20, it found some text that contained the keywords we were searching for, so it displayed it back to us.

All you have to do it copy and paste the flag into the answer box and submit it. Congratulations, you just solved PicoCTF 2018: Grep 2!

___________________________________________________________________

Thanks for taking your time to read my blog :)

If you have more time, check out my other blogs in the links down below.

--

--