OverTheWire Bandit Level 12 Writeup — Reverse a Hexdump and Unpack Nested Compression

Misc 2026-12-04 · OverTheWire Bandit · By CTFdojo · ⏱ ...
𝕏 Share
TL;DR

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.

PlatformOverTheWire Bandit
Verified againstOverTheWire — official level page
CategoryLinux Fundamentals
Level12 → 13
DifficultyBeginner
Techniquexxd -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."

Stuck? Try a hint before reading the solution

Hint 1

Turn the hexdump back into binary first, in a writable temp directory.

Hint 2

xxd -r, then loop: file, rename, decompress — until it's ASCII text.

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.

Resources

New to CTFs? Start here: beginner's guide to CTFs — what a CTF is, the categories, the tools and a step-by-step plan.

CTFdojo
CTFdojo
Community of ethical hackers writing beginner-friendly CTF writeups and guides.

Got a question or a different approach?

Discuss this writeup with the community on the CTFdojo Discord.

Join the Discord →