Skip to main content

New : Cipher Breaker, the codebreaking assistant, is now on Android Discover

▮ CipherChronicle

Image methods Image file

Image + ZIP polyglot

A polyglot file is valid in two formats at once. The image + ZIP pair is the most famous, because the two formats are read from opposite ends: the image from the start, the archive from the end.

How does the image + ZIP polyglot work?

  • A PNG is read from the start: signature, chunks, then IEND. What follows is ignored.
  • A ZIP is read from the end: the reader looks there for a small record, the “end of central directory”, which says where the file table is, which in turn says where each file is.

So you just stick the archive behind the image:

┌─────────── PNG ───────────┐┌─────────────── ZIP ────────────────┐
 signature … IDAT … IEND      file · central directory · end
 └ read by the viewer ─→                       ←─ read by the unzipper ┘

One subtlety: the positions recorded in the archive are counted from the start of the file. Since the image comes first, they must be shifted by the size of the image. A plain cat image.png archive.zip yields an archive many programs still open, out of tolerance; an archive with corrected positions opens everywhere.

What does a file processed this way look like?

Like an ordinary image that every viewer displays. Renamed to .zip, or opened with unzip image.png, it reveals its content.

What are the weaknesses of the polyglot?

Strengths

  • Image untouched and perfectly valid.
  • Read without special tools: an unzipper is enough.
  • Free content: text, several files, folders.

Weaknesses

  • Visible ZIP signature. The PK bytes (50 4B 03 04) at the end of the file are recognised at once by binwalk or file.
  • Given away by file size.
  • Blocked by some filters: antivirus and messaging apps distrust files whose content does not match the extension, since the technique is also used to smuggle malware.
  • Removed by any re-save and by platforms that recompress.

How do you recover an archive hidden in an image?

Just try unzip -l image.png. Failing that, binwalk image.png lists the formats recognised inside the file and their position; binwalk -e extracts them.

What are the variants?

  • Password-protected archive — the content can no longer be read without the password; the presence of the archive stays visible.
  • Other pairs — JPEG + ZIP, GIF + archive, PDF + ZIP: any format read from the start combines with ZIP.
  • Polyglots of three formats or more — a popular exercise in security contests.
  • Data after the end — the version without an archive, where the text is appended as is.

In CipherChronicle

The workbench appends, after the image, a ZIP archive holding a single uncompressed text file, with corrected positions. The file name inside the archive is configurable (secret.txt by default). To check: rename the downloaded PNG to .zip and open it. In a chain, this method comes last when encrypting.