OverTheWire.org Walkthrough: Bandit

~ Level 4→5 ~

Level Description

The password for the next level is stored in the only human-readable file in the inhere directory. Tip: if your terminal is messed up, try the “reset” command.

The commands that may be needed to solve this level are listed as: ls, cd, cat, file, du, find.


Research Before Solving

Iterating through the list of provided commands, we are aware of the purpose of the first three. Let's go to the fourth item; find and plug it into the command line with the help function.

Command line output of file --help

As can be seen in the picture above, the file command is used to determine types of files.


Solution Walkthrough

Start by logging into the OverTheWire server as user bandit4. When prompted, paste the password into the command line and press enter. Once logged in as bandit4, use the ls command to list all files and directories.

Output of LS command showing inhere directory

Use the cd command to move into the inhere directory. Let's list the files inside of this directory now with the ls command.

Output of command ls inhere

We are met with ten files. Note that each file starts with a dash, so we will need to remember to use ./ when using the file command so that we may have access to the files and any associated data.

There are multiple solutions to this level, however, OverTheWire hints towards the easiest in the description. One way to solve is to cat each individual file until we find the output that we desire. This process would look like this:

Output when using cat for each file

With this method we see the output turn into a mess. The output is printed onto the same line as what we are to type into. Eventually we can't see the command we are typing in, potentially causing an error like the No such file or directory issue above. We could, if we wanted to, use the reset command after each cat command to clear the screen and start over. This would of course, increase the time it takes to find our solution.

The solution the creators hint towards involves a human-readable format. If you've not already, use the reset or clear command to start with a fresh shell prompt. It seems rather ineffecient to search each file individually. Let's search online for a way to include any files within a directory.

Wildcards

Wildcards are a staple of programming. They allow us to substitute a special character in for another character. When looking at online resources for linux wildcards, we find that two characters included are the asterisk (*) and the question mark (?). When reading further about these two characters, question marks replace one character while asterisks can replace any number of characters.

The next step will combine the asterisk and the file command. Before inputting the command, let's take a look at the logic behind the command: file ./*. We are using file in this instance because we are looking for a file-type that is human-readable. The ./ is needed because of the filenames starting with a dash. Lastly, the * is used to to include any files inside the directory. If, for example, we wanted to only search for files starting with a g we would put a g before the asterisk like so: file ./g*. It would not matter what else the file contained, as long as it started with a g the file would be included in the output of the command.

Now that we understand the logic of this command, let's run it!

File type of each file from the inhere directory

Each file name is now listed out along with the type of file as the command line documentation had promised. The level details stated it would be the only file that is human-readable, when looking at the output we see that one file-type is not like the others. Typing ASCII into a search-engine reveals that this data-type represents plaintext in computers⚊Jackpot!

The final step of this level is to use cat ./-file07. This will reveal the password to the next level.

Output showing password for level 5

Record the password for your records, koReBOKuIDDepwhWk7jZC0RTdopnAYKh, and exit the session. It's time to move on to the next level!