OverTheWire.org Walkthrough: Bandit

~ Level 8→9 ~

Level Description

The password for the next level is stored in the file data.txt and is the only line of text that occurs only once

The commands listed for this level are: grep, sort, uniq, strings, base64, tr, tar, gzip, bzip2, and xxd.

For the first time in a while, we are also provided with some external reading. The link provided discusses piping, redirection and the concepts of standard in/out/error.


Research Before Solving

With the level description in mind, take a look at the commands given. If something occurs only one time within a group, we could say that the item is unique. With this logic, the uniq command will most likely be used. The piping and redirection reading material is also important so let's take a look at that next.

The webpage provides information for standard in/out/error that we had discussed previously. It discusses using the > symbol to redirect output as we did with the /dev/null directory. Lastly, it details what piping is. Piping is the idea that we can use the output from one command as the input for another command. We do this by placing a pipe symbol | between commands. To create the pipe symbol, at least on American keyboards, hold shift and press the backslash key.

Because we were given the reading material about piping and redirection, we must assume there's a chance we will have to use one or both.


Solution Walkthrough

Log in to the OverTheWire server using bandit8 as the username. Right click and paste the password retrieved from the previous level when prompted. Again, we will start with an ls command to see what is in the home directory. A file called data.txt is present.

Just for fun, let's use the cat command and see the contents of data.txt.

Output of cat command with data.txt file

We then see a very long list of output, all of which resemble passwords. If you attempt to use uniq on the file now, you'll notice the output is the same as if we just read the content with cat. Looking at the help funtion of uniq through the console we find the following:

Output of uniq --help command

The documentation states uniq works between adjacent lines. We must sort the contents of the file so that all matching lines are placed next to eachother. At this point it would appear we need to sort then use a pipe symbol into the uniq command. When attempting the command, sort data.txt | uniq, we are still presented with a long list of potential passwords. This is due to another quirk with uniq mentioned in the documentation. If no options are submitted with the command, the first occurrence out of a group of matching lines will still be printed. Since we only want the line that appears once to be printed, we must append an option of -u to the end.

Our command becomes: sort data.txt | uniq -u and the output appears like this:

Password for level 9

We now have the password to level 9!

UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhR