Skip to content

Commit d849d58

Browse files
authored
Add post for OverTheWire Bandit Level 2 to Level 3
Added a new post detailing the solution for OverTheWire Bandit Level 2 to Level 3, including commands used and explanations about handling filenames with spaces.
1 parent fd71898 commit d849d58

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

_posts/2026-06-26-bandit-2->3.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: "OverTheWire Bandit: Level 2 → Level 3"
3+
date: 2026-06-26 12:00:00 +0500
4+
categories: [CTF, Bandit]
5+
tags: [linux, cat, spaces, filenames, overthewire, beginner]
6+
---
7+
8+
## The Goal
9+
10+
The password is stored in a file called `spaces in this filename` in the home directory.
11+
12+
## What I Did
13+
14+
Logged in as `bandit2` and confirmed the file:
15+
16+
```bash
17+
bandit2@bandit:~$ ls
18+
spaces in this filename
19+
```
20+
21+
Tried reading it directly:
22+
23+
```bash
24+
bandit2@bandit:~$ cat spaces in this filename
25+
```
26+
27+
That failed — the shell treated each word as a separate argument, looking for four different files called `spaces`, `in`, `this`, and `filename`. None of them exist.
28+
29+
Checked the helpful reading material on the level page, which confirmed the fix — wrap the filename in quotes:
30+
31+
```bash
32+
bandit2@bandit:~$ cat "spaces in this filename"
33+
```
34+
35+
That printed the password.
36+
37+
## What Was Actually Happening
38+
39+
The shell splits commands into arguments using spaces as separators. So `cat spaces in this filename` looks like you're passing four separate filenames to `cat`. Wrapping the whole thing in quotes tells the shell to treat everything inside as a single argument.
40+
41+
Single quotes work too:
42+
43+
```bash
44+
cat 'spaces in this filename'
45+
```
46+
47+
So does escaping each space with a backslash:
48+
49+
```bash
50+
cat spaces\ in\ this\ filename
51+
```
52+
53+
All three are valid. Quotes are the most readable.
54+
55+
## What I Learned
56+
57+
**Spaces in filenames cause problems** because the shell uses spaces to separate arguments. This comes up constantly — not just in CTFs but in real scripting work. A script that handles filenames without quoting will break the moment someone names a file with a space in it.
58+
59+
**Quoting is the standard fix.** Double quotes allow variable expansion inside them. Single quotes treat everything literally. For a plain filename with spaces either works the same way.
60+
61+
**Tab completion handles this automatically.** If you type `cat sp` and press Tab, the shell autocompletes to `cat spaces\ in\ this\ filename` with the spaces escaped. Useful to know for later.
62+
63+
## Commands Used
64+
65+
| Command | What it did |
66+
|---|---|
67+
| `ls` | Confirmed the filename with spaces |
68+
| `cat spaces in this filename` | Failed — shell split it into four arguments |
69+
| `cat "spaces in this filename"` | Worked — quotes kept it as one argument |

0 commit comments

Comments
 (0)