Link: https://backdoor.sdslabs.co/challenges/CRC
Author: IamLupo
Points: 250
Category: crypto

Description

Backdoor user IamLupo wanted to submit his challenge for BackdoorCTF16 but he was struck by lightening and his challenge file shattered into 26 pieces. We want you to recover it for us (and maybe get the flag while you do it). Thanks in advance! Here is the zipped file:
http://hack.bckdr.in/CRC/challenge.zip

tl;dr

27 encrypted zip archives, each contains 5 character txt file. All files together make a php program. CRC32 checksum can be retrieved from zip archives. Brute force is reasonable, but takes a long time (too long). Use knowledge of php and already decrypted text to guess some characters in encrypted archives to speed up brute force attack.

Solution

In this task we get a zip file (challenge.zip) and we need to somehow get a flag out of it. The archive extracts to 27 separate .zip files, named 0.zip to 26.zip. Obviously we need to get the content of those archives, but they’re password protected…

The name of the challenge suggests us what to do next. A zip archive contains a CRC32 checksum for each archived file. Surprisingly most popular zip tools leave this checksum unencrypted for password protected archive. In fact all the metadata is easily available. We can just use python zipfile module to write simple script and list it all:

Huh, so each archive contains a single text file with 5 characters only? Except the last one is only 2 characters long? That one should be easy to brute-force, right? Python binascii module provides crc32() method that we can use for that. We just loop over 2-character printable strings (it’s txt after all) and look for the matching one:

Ok, that took 0.016 second to run and returned ?> as a result. Let’s try the same approach with other files.

Unfortunately brute forcing 5 character strings turns out to be waaay too slow on my laptop.

Maybe we can be a bit smarter about that? That string we got from 26.zip looks awfully familiar – I wonder if the message we’re trying to extract starts with <?php? Turns out it does. Also turns out, that if we can guess just one symbol in each archive (or just guess a reasonably small set of possible characters for it) we can brute the rest in just a few minutes.

For example we find out that one of the files contains  0x19. There is only a limited number of things that make sense before number literal in php, right? I would expect arithmetic and bit operators, =, <, > to be most likely candidates. Let’s just assume the last character of previous archive is one of those things and see if we’re right.

So I updated the initial script a bit to accept “hints” and we (Robert and Michal helped me there) spend a few hours guessing and waiting for the script to brute force full php code based on out guesses. Finally we get the full php code. Running it returns the flag.


The final script

I’ve removed most hints, to let you try yourself 🙂


Leave a Reply