ZIP in Disguise: Reading File Magic Bytes Instead of the Extension

Forense Digital & Resposta a Incidentes Nível 3/4 ~5 min 2026-07-08

O desafio

Um analista extraiu report.pdf do notebook de um suspeito, mas ele nunca abre num leitor de PDF. Abra-o no visualizador hexadecimal, compare os primeiros bytes com as assinaturas de referência e digite o formato real do contêiner.

O que você vai aprender

  • Read the first bytes of a file in a hex viewer and recognise a known file signature
  • Match the 50 4B 03 04 'PK' signature to the ZIP container family
  • Explain why a file extension is metadata and the magic bytes are ground truth
  • Recognise that Office documents and APKs are ZIP containers underneath
  • Rule out PDF, RAR, and 7-Zip by comparing their distinct leading signatures

Habilidades testadas

File signature / magic byte identificationHex header readingFile-type triage during incident response

Pré-requisitos

  • Comfort reading hexadecimal byte values
  • Awareness that a file extension can be changed freely without altering the contents

Como funciona

Every common file format begins with a fixed sequence of bytes called a magic number or signature. The operating system and most viewers, however, decide which application to launch based on the file extension - a piece of metadata in the name that any user can rename in a second. That gap is what this challenge exploits: a file called report.pdf whose actual contents are not a PDF at all.

A genuine PDF starts with the ASCII bytes 25 50 44 46, which spell %PDF. The file in front of you instead starts with 50 4B 03 04. The first two bytes, 50 4B, are ASCII PK - the initials of Phil Katz, who created the ZIP format - and 03 04 is the local file header marker. That four-byte sequence is the unmistakable signature of a ZIP archive.

This matters far beyond renamed files. Modern Office documents (.docx, .xlsx, .pptx), Java JARs, and Android APKs are all ZIP containers wearing a different extension. A defender who trusts the extension will mis-triage all of them. The reliable move is always the same: open the header and read the magic bytes.

Erros comuns

  • Trusting the extension. Assuming report.pdf is a PDF because the name says so. The name is metadata; the bytes are the file.
  • Misreading 50 4B as 'PK was unreadable'. Skipping the ASCII gutter where 50 4B clearly renders as PK, the giveaway for the ZIP family.
  • Confusing ZIP with RAR or 7-Zip. RAR begins 52 61 72 21 ('Rar!') and 7-Zip begins 37 7A BC AF; only 50 4B 03 04 is ZIP.
  • Stopping at 'it is an archive'. The prompt asks for the specific container format, and the signature names exactly one: ZIP.

Como se proteger

Detection and triage must key on content, not file names, and uploads must be validated by their real type before being stored or processed.

  • Use a content-based identifier (a libmagic-style check) on every uploaded or quarantined file rather than its extension.
  • For an upload allow-list, verify the magic bytes match the claimed type and reject mismatches, since ZIP-in-PDF is a classic smuggling trick.
  • Treat any ZIP-family signature (50 4B 03 04) carrying a non-archive extension as suspicious and route it for deeper inspection.
  • When unzipping unknown archives, do so in a sandbox and guard against path traversal (Zip Slip) inside the entries.

Solução completa

Membros Pro e Max desbloqueiam o passo a passo completo.

Assinar Pro

Estatísticas da comunidade

79 resoluções
82% taxa de sucesso
Vicusol Primeiro sangue

Hacks de hoje relacionados

17.000+ Hackers 100+ Labs & Cursos Grátis
Comece Grátis