Bandit 12 → 13
Goal: recover the password from data.txt, a hexdump of a file that was compressed many times over.
Approach
Section titled “Approach”data.txt is a hexdump. Reverse it back to raw bytes, then repeatedly let file name the compression format, rename to match, and decompress, until file finally reports plain text. Work in a temp directory you own.
-
Copy the dump somewhere writable and reverse the hex back to bytes.
bandit12@bandit bandit12@bandit:~$ mktemp -d/tmp/tmp.WwgYxQHtYebandit12@bandit:~$ cd /tmp/tmp.WwgYxQHtYebandit12@bandit:/tmp/tmp.WwgYxQHtYe$ cp ~/data.txt data.txtbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ xxd -r data.txt compressed -
Run the same loop for each layer: detect, rename to the matching extension, decompress.
tararchives extract to a new filename, so follow whatever appears.bandit12@bandit bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ file compressedcompressed: gzip compressed databandit12@bandit:/tmp/tmp.WwgYxQHtYe$ mv compressed compressed.gz && gzip -d compressed.gzbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ file compressedcompressed: bzip2 compressed databandit12@bandit:/tmp/tmp.WwgYxQHtYe$ mv compressed compressed.bz2 && bzip2 -d compressed.bz2bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ file compressedcompressed: POSIX tar archive (GNU)bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ mv compressed compressed.tar && tar -xf compressed.tar# ... keep going on the extracted files (tar, then bzip2, then tar, then gzip) ... -
When
filefinally says ASCII text, read it.bandit12@bandit bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ file data8data8: ASCII textbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ cat data8The password you are looking for is: <password>
FO5dwFsc0cbaIiH0h8J2eUks2vdTDwAnWhy it works
Section titled “Why it works”Compression formats are recognised by header magic bytes, not by file extension, which is why file re-detects the type at every stage. The data was packed in alternating layers (gzip, bzip2 and tar in turn), so you peel them in reverse: detect, rename to match, decompress, repeat until plain text falls out.
Full session log
bandit12@bandit:~$ mktemp -d/tmp/tmp.WwgYxQHtYebandit12@bandit:~$ cd /tmp/tmp.WwgYxQHtYebandit12@bandit:/tmp/tmp.WwgYxQHtYe$ cp -d /home/bandit12/data.txt .bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ mv data.txt hexdump_databandit12@bandit:/tmp/tmp.WwgYxQHtYe$ xxd -r hexdump_data compressed_databandit12@bandit:/tmp/tmp.WwgYxQHtYe$ mv compressed_data compressed_data.gzbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ gzip -d compressed_data.gzbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ mv compressed_data compressed_data.bz2bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ bzip2 -d compressed_data.bz2bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ mv compressed_data compressed_data.gzbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ gzip -d compressed_data.gzbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ file compressed_datacompressed_data: POSIX tar archive (GNU)bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ mv compressed_data compressed_data.tarbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ tar -xf compressed_data.tarbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ file data5.bindata5.bin: POSIX tar archive (GNU)bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ tar -xf data5.binbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ file data6.bindata6.bin: bzip2 compressed data, block size = 900kbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ bzip2 -d data6.binbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ file data6.bin.outdata6.bin.out: POSIX tar archive (GNU)bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ tar -xf data6.bin.outbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ file data8.bindata8.bin: gzip compressed data, was "data9.bin"bandit12@bandit:/tmp/tmp.WwgYxQHtYe$ mv data8.bin data8.gzbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ gunzip -d data8.gzbandit12@bandit:/tmp/tmp.WwgYxQHtYe$ cat data8The password you are looking for is: <password>