Bandit Level 9 Walkthrough

Bandit Level 9 Walkthrough

Level 8 ➔ Level 9: Finding the Unique Entry

1. My Objective

I am presented with a file named data.txt. This file is full of thousands of lines of text. Almost every line has a duplicate—sometimes dozens of them. My task is to find the one single line of text that appears exactly once in the entire file. That unique line is my password for the next level.

The Obstacle: The uniq command in Linux has a very specific limitation: it only detects duplicate lines if they are adjacent (sitting right next to each other). If duplicates are scattered throughout the file, uniq will miss them.

2. The Feynman Explanation: Sorting the Sock Drawer

How do I find a single unique line in a messy file? I follow the logic of sorting.

The Missing Sock Analogy:

Imagine I have a giant basket of 1,000 mixed socks. Most of them are pairs (two Red, two Blue, two Green). One single Yellow sock is missing its partner.

If I just reach in and grab socks one by one, I’ll never know for sure which one is unique. To find it efficiently, I do this:

  1. The Sort: I dump the basket and line up all the socks by color. Now, every Red sock is sitting right next to its twin.
  2. The Filter: I walk down the line. I see two Reds (Trash), two Blues (Trash), two Greens (Trash). Suddenly, I see one Yellow sock with nothing matching next to it. That is my prize.

In Linux, sort is my "line up" tool, and uniq -u is my "find the one without a twin" tool.

3. Practical Solution

I log in as bandit8. To solve this, I will chain two commands together using a Pipe (|). The pipe takes the output of the first command and hands it to the second.

# I sort the file first, then tell uniq to only show the unique line
bandit8@bandit:~$ sort data.txt | uniq -u

# The terminal prints the unique password:
46sc96saSAb36906sV... (full password appears here)

Why did I use -u?

The -u flag stands for "unique." By default, uniq just removes duplicates. With -u, it goes a step further and only prints the lines that occurred exactly once in the original list.

🚀 My Pro Tips: Working with Uniq

✨ The Counting Trick

If I want to see how many times every line repeats, I use the -c flag:
sort data.txt | uniq -c
This will put a number next to every line (e.g., "10 hello" means "hello" appeared 10 times).

⭐ Why Tab Completion is My Best Friend

I never type "data.txt" manually. I type cat da and hit TAB. If you aren't using Tab completion, you are working too hard! It prevents typos and makes you faster in the terminal.

🔍 Piping multiple commands

I can chain as many commands as I want. If I wanted to find the unique line and then find a specific word in it, I could do:
sort data.txt | uniq -u | grep "pattern"

4. Why this matters

I use this exact workflow when I am analyzing web server logs. If I want to find a single "strange" IP address that only visited my site once among 100,000 normal users, I use sort | uniq -u. It is a fundamental skill for data analysis and security auditing.

I Have the Password!

I've successfully filtered the data. I'll save this password and move on to Level 9 ➔ Level 10, where I'll search for text hidden inside a binary "garbage" file!

Tags: #Linux #Bandit #OverTheWire #SortCommand #UniqCommand #DataFiltering #Piping #CyberSecurity #FeynmanTechnique #CodeWithPritom #ProTips

Comments