Turn the hexdump back into binary with xxd -r, then loop: run file, rename the result to the matching extension, decompress with gunzip, bunzip2 or tar xf — until file finally reports ASCII text.
- Platform: OverTheWire Bandit
- Verified against: OverTheWire — official level page
- Category: Linux Fundamentals
- Level: 12 → 13
- Difficulty: Beginner
- Technique: xxd -r, file, gzip/bzip2/tar
Challenge description
This is the first Bandit level that takes more than one or two commands. The trick isn't any single tool, it's the habit of asking file what you're holding after every step instead of guessing.
"Level Goal: The password for the next level is stored in the file data.txt, which is a hexdump of a file that has been repeatedly compressed. For this level it may be useful to create a directory under /tmp in which you can work."
Step 1 — Set up a scratch directory
The home directory isn't writable, so work in a fresh temporary directory. mktemp -d creates one with an unguessable name, so other players on the shared server can't see your files:
ssh bandit12@bandit.labs.overthewire.org -p 2220
cd "$(mktemp -d)"
cp ~/data.txt .
Step 2 — Reverse the hexdump with xxd -r
The file is the output of xxd — offsets on the left, hex bytes in the middle, an ASCII column on the right. xxd -r reads that format and writes the original bytes back out:
xxd -r data.txt > data
file data
data: gzip compressed data, was "data2.bin", ...
The magic bytes at the start of the rebuilt file identify it as gzip — the first of many layers.
Step 3 — Peel each layer based on what file says
The decompressors care about extensions, so rename before each step. The three formats you'll meet and how to open each:
# gzip compressed data
mv data data.gz && gunzip data.gz
# bzip2 compressed data
mv data data.bz2 && bunzip2 data.bz2
# POSIX tar archive
tar xf data # then run file on whatever it extracted
After every command, run file on the newest file and pick the matching line. The layers alternate in no obvious pattern, and tar archives extract to a new filename — so ls often matters as much as file.
Step 4 — Read the final text file
Keep going until file stops reporting an archive or compressed data:
file data8
data8: ASCII text
cat data8
The password is [PASSWORD FOR bandit13]
🔑 password intentionally hidden
The password is deliberately hidden — follow the method, you've earned it. 💪
Key takeaways
The level is deliberately tedious to teach one lasting reflex: never guess a file's type when file can tell you. That same loop — identify, unpack, re-identify — is how you handle most forensics challenges that hand you a mystery blob.
-
xxdmakes hexdumps andxxd -rturns them back into binary -
filereads magic bytes, not extensions — trust it over the filename - gzip, bzip2 and tar each have their own unpack command; renaming to the right extension avoids errors
- Work in
mktemp -don shared machines so your files stay private
Originally published on CTFdojo — join the CTFdojo Discord to discuss writeups and get notified about new ones.
Top comments (0)