Wargame: Bandit
Level: 12
Category: Linux Fundamentals
Description
data.txt is a hexdump of a file that has been compressed multiple times. The goal is to reverse each layer of compression until the final plaintext file containing the password is reached.
Overview
xxd -rreverses a hexdump back to binary.- The
filecommand identifies the compression type of the binary at each stage. - Each step decompresses with the appropriate tool:
gzip,bzip2, ortar. - The process repeats until a plain ASCII file remains.
Background: Compression Formats
gzipfiles begin with magic bytes\x1f\x8b; extension.gz.bzip2files begin withBZh; extension.bz2.- POSIX
tararchives begin withustar; extension.tar. - Each format has a corresponding
-dor-xflag to decompress/extract.
Solution
Step 1: Reverse the Hexdump
mkdir /tmp/work && cd /tmp/work
cp ~/data.txt .
xxd -r data.txt > data.bin
Step 2: Iteratively Decompress
- Check type with
file data.bin, rename accordingly, then decompress. - Repeat until
filereportsASCII text.
file data.bin
# e.g. "gzip compressed data" -> mv data.bin data.gz && gzip -d data.gz
# e.g. "bzip2 compressed data" -> mv data.bin data.bz2 && bzip2 -d data.bz2
# e.g. "POSIX tar archive" -> tar -xf data.tar
- After 9 rounds of decompression, a plain text file remains.
Step 3: Read the Password
cat data10.txt
Password
wbWdlBxEir4CaE8LaPhauuOo6pwRmrDw