The password file is named --spaces in this filename--. Quoting fixes the spaces, but cat still reads the leading -- as an option marker — prefix the name with ./ (or end options with --) so it's treated as a file.
- 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, and its name causes two problems at once: it contains spaces, which the shell uses to separate arguments, and it starts with --, which commands read as the start of an option.
"Level Goal: The password for the next level is stored in a file called --spaces in this filename-- located in the home directory"
Step 1 — List the home directory
Log in as bandit2, then list what's there:
ls
--spaces in this filename--
Step 2 — Quote the filename
Wrap the whole name in quotes so the shell passes it as a single argument instead of splitting it on every space:
cat "--spaces in this filename--"
cat: unrecognized option '--spaces in this filename--'
The spaces are handled now, but cat sees an argument starting with -- and tries to parse it as an option.
Step 3 — Stop it looking like an option
Prefix the name with ./ — "the file in the current directory" — so it no longer starts with a dash:
cat "./--spaces in this filename--"
[PASSWORD FOR bandit3]
The other standard fix is a bare -- before the filename, which tells most commands "no more options after this point": cat -- "--spaces in this filename--". Backslash-escaping the spaces (cat ./--spaces\ in\ this\ filename--) works too, and is what tab-completion produces.
🔑 password intentionally hidden
The password is deliberately hidden — follow the method, you've earned it. 💪
Key takeaways
Whenever a filename might contain spaces (or other shell-special characters), quote it or escape it — and when in doubt, let tab-completion do it for you instead of typing it by hand.
- Unquoted spaces in the shell separate arguments, they don't stay part of one filename
- Double quotes ("...") or single quotes ('...') both keep a filename intact
- Tab-completion after typing a few letters auto-escapes special characters for you
- A name starting with
-or--needs./in front of it (or a--before it) so commands don't treat it as an option — the same trick as Level 1's file named-
Originally published on CTFdojo — join the CTFdojo Discord to discuss writeups and get notified about new ones.
Top comments (0)