Shattered zip, readable checksums
Backdoor CTF 2016 CRC: Recovering Text from Zip CRC32 Checksums
Twenty-seven password-protected zip files each hold a tiny text fragment. The passwords are never needed: the CRC32 stored in every header leaks enough to rebuild a PHP script.
- 01
Inspect
The outer file unpacks to 27 inner zip files, 0.zip to 26.zip, each protected by a password and each holding one tiny text entry.
- 02
Hypothesize
Zip headers store a CRC32 and the plaintext length in the clear, so each fragment can be searched for instead of decrypted.
- 03
Test
The two-character last fragment falls in milliseconds and reads as the closing tag of a PHP file, which suggests the whole text is PHP source.
- 04
Solve
Hints from PHP syntax shrink the search for each five-character piece until the full script can be assembled and run to print the flag.
What the challenge gives
The Backdoor CTF 2016 task named CRC, rated at 250 points in the crypto category, supplies one file. It unpacks to 27 smaller zip files, numbered 0.zip through 26.zip. The story attached to it says an author’s challenge file was shattered into pieces, and the job is to put it back together. Every inner zip asks for a password, and nothing in the task offers one.
Listing the contents with Python’s zipfile module shows how little is inside. Each inner file holds exactly one entry, named after its number with a .txt extension, and each entry is five bytes long. The final one, 26.txt, is two bytes. That adds up to 26 pieces of five characters and one of two, so 132 characters in total. The compressed size field reads 17 for a five-byte entry and 14 for the two-byte one. The difference of 12 between compressed and original size is the length of the encryption header that traditional zip encryption prepends, which also tells the reader the entries are stored without compression.
The checksum is not encrypted
The name of the challenge points at the next step. A zip entry carries a CRC32 of its uncompressed data, and the tools that produce password-protected zip files leave that field untouched. The headers are readable by design, so a script can print the CRC32 of every hidden fragment without knowing any password.
import zipfile
for n in range(27):
with zipfile.ZipFile(f"{n}.zip") as zf:
info = zf.infolist()[0]
print(n, info.file_size, f"{info.CRC:08x}")
CRC32, as used in zip, is a 32-bit cyclic redundancy check with the reflected polynomial 0xEDB88320, an initial value of 0xFFFFFFFF and a final inversion. It is built to catch accidental corruption and has no resistance against someone who searches for inputs. For a short, known length the whole input space can be enumerated and compared against the stored value.
The two-character piece
The last file, with a two-byte payload, is the sanity check. Looping over every pair of printable characters and comparing binascii.crc32(text) & 0xffffffff against the stored value finishes in a few hundredths of a second. The match is the pair ?>. That string is the closing tag of a PHP block, which is the first real clue: the pieces together are probably a PHP program, and the first piece plausibly begins with <?php.
Why plain brute force stalls
Five printable characters give roughly 95^5, about 7.7 billion candidates. That exceeds the 4.29 billion possible CRC32 values, so an exhaustive search over printable ASCII returns on average a couple of strings per checksum, most of them garbage. In pure Python the search is also slow, on the order of a million candidates per second, so a single piece takes hours and 26 of them are out of reach.
The way out is to shrink the alphabet and use knowledge of the language. A PHP script of this size is mostly lowercase letters, digits, whitespace and a handful of punctuation marks such as parentheses, braces, semicolons, brackets, =, + and -. A set of about fifty characters brings five positions down to roughly 312 million combinations, and every fixed character in a piece divides that by fifty again. Fixing two characters leaves around 125,000 candidates, which is instant.
Guessing with hints
The solver script takes a dictionary of hints per file, either a known start, a known end, or a list of alternatives to try. A piece that starts with cho is almost certainly the tail of echo split across a boundary. A piece known to end in fun limits the end. For a number literal such as 0x19, the character before it must be an operator, an assignment, a comparison or an opening bracket, so a handful of candidates can be tried for the last character of the previous piece. Each confirmed fragment adds context to its neighbours, because the script has to read as valid PHP across the seams.
This is slow, manual work: hints are entered, the script runs for minutes, and wrong guesses produce strings that look plausible for a character or two and then fall apart. The collision rate matters here. A hit that is not valid PHP is simply discarded. After a few hours of this alternation the 132 characters were assembled into a complete script. Executing that script prints the flag.
Faster ways to the same answer
CRC32 is affine over GF(2): the checksum of an XOR of equal-length inputs equals the XOR of their checksums combined with a constant. That linearity allows a meet-in-the-middle attack, solving for the bits that produce a target CRC directly, and tools that do this return every five-byte preimage in a fraction of a second. The hint-driven brute force still has an advantage in a contest, because it needs nothing beyond the standard library and keeps the PHP context in the loop.
What transfers to other challenges
A readable checksum or length field is an oracle. Whenever a container exposes a hash of secret data that has low entropy, the hash can be searched. Short zip entries, tiny database fields and truncated tokens all fall to the same approach. Keep the alphabet as small as the format allows, fix every byte that the syntax determines, and use a second source of truth, such as a parser, to filter collisions. The binary view of a zip file shows why this works: the headers stand out as low-entropy structure between the encrypted payloads, a pattern described further in the guide to binary data visualization. A different case where context rescues a brute force is the affine cipher on a base32 flag.
Questions readers ask
Why does a password-protected zip still reveal its CRC32?
The zip format keeps the local and central directory headers readable. Traditional zip encryption only scrambles the entry data, so name, sizes and the CRC32 of the plaintext stay visible to any tool that parses the headers, including Python's zipfile module.
Is a CRC32 match proof that a guess is right?
No. A CRC32 has 2^32 values, and five printable characters give around 7.7 billion candidates, so a given checksum matches about two strings on average. Context, such as valid PHP syntax, is what separates the real fragment from a collision.
Why is the last fragment so easy?
It holds two bytes. Two printable characters are fewer than ten thousand candidates, so the search ends in a few milliseconds. The result also hints at the file type, because it is the usual closing tag of a PHP script.
New to capture the flag? Formats, teams and a first-month plan in one place.
Read the CTF guide