Learn More about Benny Czarny's Book Cybersecurity Upside Down

Learn More
We utilize artificial intelligence for site translations, and while we strive for accuracy, they may not always be 100% precise. Your understanding is appreciated.

Your Scanner Sees One File. The ZIP Holds Two

A ZIP file lists its contents twice. Most tools read only one of the two lists. An attacker who leaves a file off that list hides it from the scan, while other tools can still unpack it.
By Nhut Ngo

Two Lists Inside Every ZIP

A ZIP archive describes each file it holds in two places. Before each file's data sits a small local header with the file's name and size. At the end of the archive sits the central directory. It is an index that lists every file and points to where each one starts.

The two lists should always agree. Nothing in the format forces them to. A file can be stored in the archive with its own valid local header and still be left out of the index. We call it an unlisted entry.

Most readers trust the index because it is fast. They read the end of the file, get the full list, and jump straight to each entry. A scanner that works this way checks the listed files and never visits the bytes between them. The scanner never sees the unlisted file, so it has nothing to flag.

your scanner sees one file the zip holds two 1
The same archive read two ways. The scanner that trusts the index sees one file. A program that walks the local headers sees two.

A Customer Archive With a Missing Entry

The problem reached us as a real case. A customer sent us an archive that physically held two files. The central directory listed only the benign one. The malicious file sat at an offset that no index entry pointed to. Every check that started from the index passed the archive, because the index described a clean archive.

This works as an attack because ZIP readers do not all agree. Readers that stream an archive from the first byte follow the local headers, not the index. So the same archive can show one file to the scanner and two files to the program that finally opens it. The attack depends on this difference between the two readers.

Read Both Lists, Then Compare

File Structure Validation Technology checks ZIP archives for this problem. The check has three steps.

  1. Read every local header. The engine walks the archive from the first byte and lists every local header. It compares that list with the central directory. A file missing from the central directory is an unlisted entry.
  2. Block the archive. The engine reports each unlisted entry by name and blocks the archive. No anti-malware signature is needed.
  3. Return hidden files for scanning. When this option is on, the engine extracts only the unlisted entries. MetaDefender™ Core scans each one as a separate object.

Two Settings Control the Check

Both behaviors are policy switches. "Detect unlisted", under ZIP Configuration, turns on the check and blocks archives that fail it. It is on by default.

your scanner sees one file the zip holds two 14

"Unlisted archive entry", under Return Analyzed Objects, hands the hidden files back to MetaDefender Core. It is off by default, and it works only when "Detect unlisted" is on.

your scanner sees one file the zip holds two 13
Detection is on by default. Returning hidden files to MetaDefender Core is a choice you make.

Reading every local header costs more than trusting the index, because the engine must read the whole archive. The check runs in the File Structure Validation engine, so archive extraction elsewhere in the product keeps its current speed and behavior.

Proven on a Hidden-Entry Archive

We built a test archive the way an attacker would. It holds two files: readme.txt and eicar.com, a real malware sample. The central directory lists only readme.txt. In its normal mode, 7-Zip lists one file in this archive: readme.txt.

your scanner sees one file the zip holds two 11

First, we scanned the archive with 12 anti-malware engines and File Structure Validation is disabled. None of the 12 engines detected the malware. They saw the file the index listed, and that file is clean.

your scanner sees one file the zip holds two 6
Without File Structure Validation, 0 of 12 engines flag the archive

We then ran the same archive through the File Structure Validation engine, using a build of the new feature.

your scanner sees one file the zip holds two
your scanner sees one file the zip holds two 7
Default settings ("Unlisted archive entry" not selected) blocked the archive; eicar.com reported as an unlisted entry

The engine named the file that 7-Zip did not show. The engine output for the hidden-entry archive (abridged):

your scanner sees one file the zip holds two 6

With "Unlisted archive entry" selected, the engine handed the hidden file back to MetaDefender Core as a separate object.

your scanner sees one file the zip holds two 7

The same 12 engines that missed it inside the archive now scanned it directly, and 12 of 12 detected it.

your scanner sees one file the zip holds two 8
"Unlisted archive entry" selected; eicar.com extracted and scanned by the 12 engines. The archive is reported infected

Because a file inside the archive is infected, MetaDefender Core reported the whole archive as infected.

your scanner sees one file the zip holds two 9

The table summarizes each test scenario.

Settings

Archive

Result

Default

Clean, both files listed

No finding

12 anti-malware engines, no File Structure Validation

Hidden entry

No detection; 0 of 12 engines flag the archive

Default

Hidden entry

Blocked; eicar.com reported as an unlisted entry

"Unlisted archive entry" selected

Hidden entry

Blocked; eicar.com extracted and scanned by the 12 engines; detected, so the archive is reported infected

"Detect unlisted" turned off

Hidden entry

No finding; the check is skipped

Ordinary Archives Pass

A structure check is useful only if ordinary archives pass it. In our QA runs, archives written by common tools passed without a finding: 7-Zip, .NET, PowerShell, and Python. Each hidden entry is reported by name, so an analyst sees exactly what the index left out. The check looks at structure only, so it works the same way whether the hidden file is a script, a program, or a document.

Same Rule as Polyglot Detection

This feature follows the same rule as our polyglot detection: judge the file by its structure. A polyglot file is one byte stream that two parsers read as two different formats. A ZIP with an unlisted entry is one byte stream that two ZIP readers read as two different file lists. In both cases each reader is satisfied and sees nothing wrong. Only a check that reads the file both ways finds the second view.

The Bottom Line

A ZIP archive that hides a file from its own index can pass every scanner that trusts the index.

File Structure Validation reads every local header, compares the result with the index, and blocks the archive. It can also hand the hidden file back to MetaDefender Core for a full scan. In our test, that scan caught malware that 12 anti-malware engines missed while it sat inside the archive.

your scanner sees one file the zip holds two 10
Nhut_Ngo
Author Bio

Nhut Ngo is Director of Software Engineering at OPSWAT, where he leads the engineering teams behind Deep CDR™ Technology and other file-processing technologies in MetaDefender Core™. With more than a decade of experience in software engineering and cybersecurity, he focuses on making file sanitization fast, accurate, and ready for critical infrastructure. Nhut earned his PhD in Information Science in 2015.

Nhut Ngo
Director of Software Engineering

Stay Up-to-Date With OPSWAT!

Sign up today to receive the latest company updates, stories, event info, and more.