OverTheWire Bandit Level 2 Writeup — Read a Filename With Spaces
The password file is named spaces in this filename . The shell splits unquoted arguments on whitespace, so the filename has to be quoted or escaped to be treated as one argument. Platform: OverTheWire Bandit Category: Linux Fundamentals Level: 2 → 3 Difficulty: Beginner Technique: Shell quoting and escaping Challenge description Level 2's home directory has one file, but its name contains spaces.…
The OverTheWire Bandit level 2 writeup focuses on accessing a file named "spaces in this filename" located in the home directory. This file's name contains spaces, which poses a challenge for the shell when it comes to interpreting the filename properly.
Upon logging in as bandit2, the recommended first step is to list the files in the home directory using the `ls` command. However, when attempting to directly access "spaces in this filename" without addressing the space issue, the command will split the filename into separate arguments due to the shell's behavior of treating unquoted spaces as argument separators.
To resolve this, two techniques are suggested: quoting the filename using double quotes (`"`) or escaping each space with a backslash (`\`). Both methods ensure the shell treats the entire filename as a single argument. For example, typing `cat "spaces in this filename"` or `cat spaces\ in\ this\ filename` will successfully read the file's contents, thereby revealing the password for the next level (bandit3).
The writeup emphasizes the importance of using proper quoting or escaping techniques when dealing with filenames that may contain special characters, such as spaces. It also highlights the convenience of relying on tab-completion, which automatically escapes special characters for the user, eliminating the need for manual intervention. By following these recommended practices, users can effectively navigate through the OverTheWire Bandit challenges and progress to higher levels.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.