Explore HackDev

$ writeup

piwww
Sep 28, 2026

OverTheWire Bandit level 12 --> 13

❓Question

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. Use mkdir with a hard to guess directory name. Or better, use the command “mktemp -d”. Then copy the datafile using cp, and rename it using mv (read the manpages!)

📋 Walkthrough

For this one the file has been compressed multiple time. So we need to decompressed it. The easy way to know what kind of compression been use is by looking at its hexdump header and google the magic number

We need to make a temp directory and copy the data.txt first. Since we cannot write on the current directory

bandit12@bandit:~$ mktemp -d
/tmp/tmp.Pt4PrPkKwz
bandit12@bandit:~$ cp data.txt /tmp/tmp.Pt4PrPkKwz/data.txt
bandit12@bandit:~$ cd /tmp/tmp.Pt4PrPkKwz
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls -la
total 4
drwx------  2 bandit12 bandit12   60 Jul  7 05:58 .
drwxrwx-wt 94 root     root     2380 Jul  7 05:58 ..
-rw-r-----  1 bandit12 bandit12 2639 Jul  7 05:58 data.txt
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ 

Now we look at the header of the data.txt and google it. If u google 1f8b file header. The result would be a gzip compression.

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ cat data.txt | head
00000000: 1f8b 0808 b2f0 3b6a 0203 6461 7461 322e  ......;j..data2.
00000010: 6269 6e00 0142 02bd fd42 5a68 3931 4159  bin..B...BZh91AY
00000020: 2653 59dc 0966 8300 001a ffff dff5 c5fe  &SY..f..........
00000030: b8ef a7be bddb f8a7 febb ffc9 bfbf 9fbf  ................
00000040: b77b bfff fbd9 7ffe 5fef efcf b001 3b19  .{......_.....;.
00000050: 9206 87a9 a068 0340 3400 341a 1a1a 0340  .....h.@4.4....@
00000060: 1a68 068d 1a00 0646 8000 0610 0d00 069a  .h.....F........
00000070: 0640 683c a0d0 3d43 4d3d 4f51 b420 0680  .@h<..=CM=OQ. ..
00000080: d034 0000 0079 41a3 40d1 ea00 0f48 000d  .4...yA.@....H..
00000090: 1a34 d1ea 7a83 d468 f441 a03d 469a 3400  .4..z..h.A.=F.4.

Now we need to revert the hexdump into actual data and decompressed the gzip file

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ xxd -r data.txt revert.gz
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ gzip -d revert.gz
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls -la
total 8
drwx------  2 bandit12 bandit12   80 Jul  7 06:04 .
drwxrwx-wt 90 root     root     2240 Jul  7 06:04 ..
-rw-r-----  1 bandit12 bandit12 2639 Jul  7 05:58 data.txt
-rw-rw-r--  1 bandit12 bandit12  578 Jul  7 06:04 revert

Now if you open the file it still compressed. We can see its file signature by turning it into hexdump and see what kind of compression now. A quick googling for 425a file signature show that its a bz2 compression

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ cat revert | head
▒4��z��h�A�=F�4d����e4��� z�24�����h▒h4▒��Pz����B▒;����h>D�Bl�O����������\]J1#L�E���"?NJh*�w��וR}�]�'�$��▒@�nd�ߧV▒/\��`d�  T�#�3�a�l���j���Z,���Ӌ���4����-�

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ xxd revert | head
00000000: 425a 6839 3141 5926 5359 dc09 6683 0000  BZh91AY&SY..f...
00000010: 1aff ffdf f5c5 feb8 efa7 bebd dbf8 a7fe  ................
00000020: bbff c9bf bf9f bfb7 7bbf fffb d97f fe5f  ........{......_
00000030: efef cfb0 013b 1992 0687 a9a0 6803 4034  .....;......h.@4
00000040: 0034 1a1a 1a03 401a 6806 8d1a 0006 4680  .4....@.h.....F.
00000050: 0006 100d 0006 9a06 4068 3ca0 d03d 434d  ........@h<..=CM
00000060: 3d4f 51b4 2006 80d0 3400 0000 7941 a340  =OQ. ...4...yA.@
00000070: d1ea 000f 4800 0d1a 34d1 ea7a 83d4 68f4  ....H...4..z..h.
00000080: 41a0 3d46 9a34 0064 0000 d0f5 00d0 1901  A.=F.4.d........
00000090: a065 34d0 f283 207a 8d32 0000 0000 341e  .e4... z.2....4.

So we rename the file with .bz2 extension and decompress it with bzip2

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ mv revert revert.bz2
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ bzip2 -d revert.bz2
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls -la
total 8
drwx------  2 bandit12 bandit12   80 Jul  7 06:10 .
drwxrwx-wt 98 root     root     2400 Jul  7 06:10 ..
-rw-r-----  1 bandit12 bandit12 2639 Jul  7 05:58 data.txt
-rw-rw-r--  1 bandit12 bandit12  441 Jul  7 06:04 revert

Still same we use xxd to see the file header. 1f8b which is gz like earlier and now we can see some actual words there.

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ xxd revert | head
00000000: 1f8b 0808 b2f0 3b6a 0203 6461 7461 342e  ......;j..data4.
00000010: 6269 6e00 edd1 4d48 d371 18c0 f147 3772  bin...MH.q...G7r
00000020: 60ca 0e09 3a3c 8c5e 9609 e6ef ffdb 7f7f  `...:<.^........
00000030: 312f bdc8 48cb a886 f882 221b 9a0e 4441  1/..H....."...DA
00000040: e721 289a b55e 1409 0a83 ed50 8494 d5a5  .!(..^.....P....
00000050: 5387 5117 d18b e029 0541 10ec 106e d82d  S.Q....).A...n.-
00000060: 3d84 4173 752c c893 6ff0 fd5c 9e07 9ee7  =.Asu,..o..\....
00000070: f6ed 0c46 82be d3a1 709f ec1c 9565 99e6  ...F....p....e..
00000080: 9f99 f5d7 d4e6 efdd f069 c3aa aa52 dad2  .........i...R..
00000090: a20c 43fb 94b8 95ec 82a1 c148 70c0 ed96  ..C........Hp...

Decompressed it with gzip

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ mv revert revert.gz
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ gzip -d revert.gz
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls -la
total 24
drwx------  2 bandit12 bandit12    80 Jul  7 06:13 .
drwxrwx-wt 98 root     root      2440 Jul  7 06:13 ..
-rw-r-----  1 bandit12 bandit12  2639 Jul  7 05:58 data.txt
-rw-rw-r--  1 bandit12 bandit12 20480 Jul  7 06:04 revert

Now when you try to use xxd and look at file header and you google the 6461 you wont find anything useful. But we saw the data5.bin from there we can conclude it might be something. Then you try to use cat to see the content and you saw ustar.

ustar is a magic string for tar archive. From there we can conclude its a tar archive

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ xxd revert | head
00000000: 6461 7461 352e 6269 6e00 0000 0000 0000  data5.bin.......
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 0000 3030 3030 3634 3400 3030 3030  ....0000644.0000
00000070: 3030 3000 3030 3030 3030 3000 3030 3030  000.0000000.0000
00000080: 3030 3234 3030 3000 3135 3231 3637 3730  0024000.15216770
00000090: 3236 3200 3031 3132 3530 0020 3000 0000  262.011250. 0...
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ cat revert
data5.bin0000644000000000000000000002400015216770262011250 0ustar  rootrootdata6.bin00006440000000000000002���'�▒SQ�b13D2h�2▒b24%l߈▒I�U▒�]�/6b"�Ӄ��:��;W�X�}�i�F�������\@�W��P#�t1��LF|� �
                                                          �N���&�0�slM��*����*�](X�;_yia�����0fJZ�U��i���K\��-�
     gu$/�R����)�e��(bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ 

Now we can use tar to extract the archive

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ mv revert revert.tar
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ tar -xf revert.tar
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls -la
total 36
drwx------   2 bandit12 bandit12   100 Jul  7 06:22 .
drwxrwx-wt 101 root     root      2520 Jul  7 06:22 ..
-rw-r-----   1 bandit12 bandit12  2639 Jul  7 05:58 data.txt
-rw-r--r--   1 bandit12 bandit12 10240 Jun 24 14:58 data5.bin
-rw-rw-r--   1 bandit12 bandit12 20480 Jul  7 06:04 revert.tar

Now we got data5.bin. If you cat data5.bin you still see the ustar. So extract with tar again

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ cat data5.bin
data6.bin0000644000000000000000000000034115216770262011253 0ustar  rootrootBZh91AY&SY�������\�N���&�0�slM��*����*�](X�;_yia�����0fJZ�U��i���Kgu$/�R����)�e��(bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ 
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ tar -xf data5.bin
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls-la
ls-la: command not found
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls -la
total 40
drwx------   2 bandit12 bandit12   120 Jul  7 06:24 .
drwxrwx-wt 101 root     root      2500 Jul  7 06:24 ..
-rw-r-----   1 bandit12 bandit12  2639 Jul  7 05:58 data.txt
-rw-r--r--   1 bandit12 bandit12 10240 Jun 24 14:58 data5.bin
-rw-r--r--   1 bandit12 bandit12   225 Jun 24 14:58 data6.bin
-rw-rw-r--   1 bandit12 bandit12 20480 Jul  7 06:04 revert.tar

Now we got data6.bin we try to cat and see no ustar so we try to xxd see the hexdump and saw 425a file signature for bz2

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ cat data6.bin
2���'�▒SQ�b13D2h�2▒b24%l߈▒I�U▒�]�/6b"�Ӄ��:��;W�X�}�i�F����gu$/�R����)�e��

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ xxd data6.bin | head
00000000: 425a 6839 3141 5926 5359 8cb4 9e85 0000  BZh91AY&SY......
00000010: 8a7f ffdc 5c00 40c0 57ff e800 5023 8074  ....\.@.W...P#.t
00000020: 31fe 8000 4c04 0000 4610 0000 7c82 0001  1...L...F...|...
00000030: 0044 0820 0094 0d48 d353 434d 3403 4698  .D. ...H.SCM4.F.
00000040: 8699 0d32 0687 a098 27a8 1a53 51ea 6231  ...2....'..SQ.b1
00000050: 3344 1932 68c8 3200 1a62 3234 1c25 6cdf  3D.2h.2..b24.%l.
00000060: 8810 180e 0102 0749 e755 18f2 5db8 2f36  .......I.U..]./6
00000070: 6222 03e6 d383 a5d9 08eb 3aae 9d3b 57f4  b"........:..;W.
00000080: 58a2 7de8 6999 46e0 10f3 e4c3 0c80 4eb8  X.}.i.F.......N.
00000090: 8991 26e7 3081 736c 4de8 dc2a a7b8 faa6  ..&.0.slM..*....

Now just decompressed it with bzip2

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ mv data6.bin data6.bz2
andit12@bandit:/tmp/tmp.Pt4PrPkKwz$ bzip2 -d data6.bz2
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls -la
total 48
drwx------   2 bandit12 bandit12   120 Jul  7 06:29 .
drwxrwx-wt 103 root     root      2540 Jul  7 06:29 ..
-rw-r-----   1 bandit12 bandit12  2639 Jul  7 05:58 data.txt
-rw-r--r--   1 bandit12 bandit12 10240 Jun 24 14:58 data5.bin
-rw-r--r--   1 bandit12 bandit12 10240 Jun 24 14:58 data6
-rw-rw-r--   1 bandit12 bandit12 20480 Jul  7 06:04 revert.tar

Now cat data6 and its ustar so extract with tar

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ mv data6 data6.tar
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ tar -xf data6.tar
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls -la
total 52
drwx------   2 bandit12 bandit12   140 Jul  7 06:32 .
drwxrwx-wt 104 root     root      2460 Jul  7 06:32 ..
-rw-r-----   1 bandit12 bandit12  2639 Jul  7 05:58 data.txt
-rw-r--r--   1 bandit12 bandit12 10240 Jun 24 14:58 data5.bin
-rw-r--r--   1 bandit12 bandit12 10240 Jun 24 14:58 data6.tar
-rw-r--r--   1 bandit12 bandit12    79 Jun 24 14:58 data8.bin
-rw-rw-r--   1 bandit12 bandit12 20480 Jul  7 06:04 revert.tar

Now if you xxd data8.bin we will get 1f8b header which is gzip. Decompressed it and open the file to see the password

bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ xxd data8.bin
00000000: 1f8b 0808 b2f0 3b6a 0203 6461 7461 392e  ......;j..data9.
00000010: 6269 6e00 0bc9 4855 2848 2c2e 2ecf 2f4a  bin...HU(H,.../J
00000020: 51c8 2c56 280c 8c0c ccf4 f077 0a08 b2a8  Q.,V(......w....
00000030: 0a32 332c ac88 2c8c 3031 2d2c 2dcb cc70  .23,..,.01-,-..p
00000040: 332a adca e602 0071 64a8 9431 0000 00    3*.....qd..1...
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ mv data8.bin data8.gz
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ gzip -d data8.gz
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ ls -la
total 52
drwx------   2 bandit12 bandit12   140 Jul  7 06:34 .
drwxrwx-wt 105 root     root      2500 Jul  7 06:34 ..
-rw-r-----   1 bandit12 bandit12  2639 Jul  7 05:58 data.txt
-rw-r--r--   1 bandit12 bandit12 10240 Jun 24 14:58 data5.bin
-rw-r--r--   1 bandit12 bandit12 10240 Jun 24 14:58 data6.tar
-rw-r--r--   1 bandit12 bandit12    49 Jun 24 14:58 data8
-rw-rw-r--   1 bandit12 bandit12 20480 Jul  7 06:04 revert.tar
bandit12@bandit:/tmp/tmp.Pt4PrPkKwz$ cat data8
The password is qQYQiHOBPR8zR61qxYqX45quvihF2uzk