|
| 1 | +--- |
| 2 | +title: "OverTheWire Bandit: Level 7 to Level 8" |
| 3 | +date: 2026-06-26 19:00:00 +0500 |
| 4 | +categories: [CTF, Bandit] |
| 5 | +tags: [linux, grep, search, overthewire, beginner] |
| 6 | +--- |
| 7 | + |
| 8 | +## The Goal |
| 9 | + |
| 10 | +Find the password stored in `data.txt` next to the word `millionth`. |
| 11 | + |
| 12 | +## What I Did |
| 13 | + |
| 14 | +Listed the directory to confirm the file: |
| 15 | + |
| 16 | +```bash |
| 17 | +bandit7@bandit:~$ ls |
| 18 | +data.txt |
| 19 | +``` |
| 20 | + |
| 21 | +Tried reading it with `cat`: |
| 22 | + |
| 23 | +```bash |
| 24 | +bandit7@bandit:~$ cat data.txt |
| 25 | +``` |
| 26 | + |
| 27 | +A massive wall of text came out — thousands of lines, each containing a word and what looked like a password. Reading through it manually wasn't an option. |
| 28 | + |
| 29 | +I needed to find the specific line containing `millionth`. That's exactly what `grep` is for: |
| 30 | + |
| 31 | +```bash |
| 32 | +bandit7@bandit:~$ grep "millionth" data.txt |
| 33 | +millionth dfwvzFQi4mU0wfNbFOe9RoWskMLg7eEc |
| 34 | +``` |
| 35 | + |
| 36 | +One line. The password is right there next to the word. |
| 37 | + |
| 38 | +## What grep Actually Does |
| 39 | + |
| 40 | +`grep` stands for **Global Regular Expression Print**. It reads through a file line by line, checks each line against a pattern you give it, and prints every line that matches. |
| 41 | + |
| 42 | +The basic syntax is: |
| 43 | + |
| 44 | +```bash |
| 45 | +grep "pattern" filename |
| 46 | +``` |
| 47 | + |
| 48 | +It's case sensitive by default. `grep "Millionth"` would find nothing here because the word is lowercase. To make it case insensitive add `-i`: |
| 49 | + |
| 50 | +```bash |
| 51 | +grep -i "millionth" data.txt |
| 52 | +``` |
| 53 | + |
| 54 | +Other useful flags: |
| 55 | + |
| 56 | +| Flag | What it does | |
| 57 | +|---|---| |
| 58 | +| `-i` | Case insensitive search | |
| 59 | +| `-n` | Show line numbers | |
| 60 | +| `-v` | Invert — show lines that do NOT match | |
| 61 | +| `-r` | Search recursively through directories | |
| 62 | +| `-c` | Count matching lines instead of printing them | |
| 63 | +| `-l` | Print only filenames that contain a match | |
| 64 | + |
| 65 | +## The Other Commands on This Level |
| 66 | + |
| 67 | +This level lists several commands I didn't need here but are worth understanding: |
| 68 | + |
| 69 | +**`sort`** — sorts lines alphabetically or numerically. Almost always paired with `uniq`. |
| 70 | + |
| 71 | +**`uniq`** — removes consecutive duplicate lines. `sort data.txt | uniq` is the standard combination for finding or removing duplicates. |
| 72 | + |
| 73 | +**`strings`** — extracts readable text from binary files. When `cat` gives you garbage characters, `strings` pulls out only the human-readable parts. |
| 74 | + |
| 75 | +**`base64`** — encodes or decodes base64 data. `base64 -d file` decodes it back to the original content. |
| 76 | + |
| 77 | +**`tr`** — translates or replaces characters. `tr 'A-Z' 'a-z'` converts uppercase to lowercase. `tr -d '\n'` removes all newline characters. |
| 78 | + |
| 79 | +**`tar`** — bundles multiple files into one archive. `tar -xf archive.tar` extracts it. |
| 80 | + |
| 81 | +**`gzip` / `bzip2`** — compression tools. `gzip -d file.gz` and `bzip2 -d file.bz2` decompress files. |
| 82 | + |
| 83 | +**`xxd`** — shows a hex dump of a file. Used when you need to inspect raw bytes — common in reverse engineering and forensics. |
| 84 | + |
| 85 | +**`|` (pipe)** — the most important operator in Linux. Takes the output of one command and feeds it as input to the next: |
| 86 | +```bash |
| 87 | +cat data.txt | grep "millionth" |
| 88 | +``` |
| 89 | +This does exactly the same thing as `grep "millionth" data.txt` — two ways to get the same result. Pipes become essential when chaining multiple commands together. |
| 90 | + |
| 91 | +## What I Learned |
| 92 | + |
| 93 | +**`grep` is the go-to tool for searching inside files.** When a file is too large to read manually, grep finds exactly what you need instantly. |
| 94 | + |
| 95 | +**The pipe operator chains tools together.** Linux is built around small tools that each do one thing well. The power comes from combining them. |
| 96 | + |
| 97 | +**Reading a massive file with `cat` first** showed me what the structure looked like — word on the left, password on the right — which confirmed that `grep` was the right approach. |
| 98 | + |
| 99 | +## Commands Used |
| 100 | + |
| 101 | +| Command | What it did | |
| 102 | +|---|---| |
| 103 | +| `ls` | Confirmed `data.txt` exists | |
| 104 | +| `cat data.txt` | Showed the file structure — too large to read manually | |
| 105 | +| `grep "millionth" data.txt` | Found the exact line containing the password | |
0 commit comments