zip

The zip module parses ZIP archives and exposes the list of entries they contain, together with the compression method and the size of each one. It reads the archive’s metadata only, so a rule can reason about what an archive holds without the contents being decompressed.

This also covers the many formats that are ZIP archives with another extension, such as JAR, APK, DOCX, XLSX, ODT and EPUB.


Module structure

FieldTypeDescription
is_zipboolTrue if the data is a ZIP archive.
entriesEntry arrayOne entry per file or directory found.

Entry

These are the fields in each entry of the entries array.

FieldTypeDescription
file_pathstringPath of the entry as stored in the archive.
compressionCompressionCompression method used for the entry.
uncompressed_sizeintegerSize of the entry once decompressed, in bytes.
compressed_sizeintegerSize of the entry as stored in the archive, in bytes.

file_path is the path exactly as the archive stores it, which means it can contain directory separators, and it is decoded as UTF-8 replacing any invalid sequence, so it is not guaranteed to round-trip to the original bytes.

Both sizes come from the entry’s own header and are not verified against the data, so an archive can claim whatever it likes. Comparing the two is a cheap way to spot an entry whose declared ratio is implausible.

Entries that cannot be parsed are skipped, and no more than 100000 entries are reported for a single archive.

Example

import "zip"

rule apk_with_dex_at_the_root {
    condition:
        zip.is_zip and
        for any entry in zip.entries : (
            entry.file_path == "classes.dex"
        )
}

Compression

These are the possible values of the compression field. The names come from the compression method numbers defined by the ZIP specification, and an entry using a method that is not in this list is reported as UNKNOWN.

NameValue
STORED0
SHRUNK1
REDUCED_12
REDUCED_23
REDUCED_34
REDUCED_45
IMPLODED6
DEFLATED8
DEFLATE649
PKWARE_IMPLODING10
BZIP212
LZMA14
ZSTD93
XZ95
UNKNOWN255

Example

import "zip"

rule stored_entry_larger_than_1mb {
    condition:
        for any entry in zip.entries : (
            entry.compression == zip.STORED and
            entry.uncompressed_size > 1048576
        )
}