Study guide
7.3 File Signatures, Magic Bytes, Hex Headers/Footers & File Carving Techniques
Computer Hacking Forensic Investigator CHFI 312-49
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: Foundations of Digital Forensics & Cybercrime Investigation
1.1 Cybercrime Classifications, Forensic Science Principles & Legal Admissibility 1.2 RFC 3227 Order of Volatility, Live vs. Dead Acquisition & Forensic Readiness 1.3 Indicators of Compromise (IoCs), Cyber Attribution & Threat Intelligence 1.4 AI-Assisted Forensics, GitOps, Automation/Orchestration & Forensics-as-a-Service (FaaS)
2 Chapter 2: Modern Forensic Environments & Emerging Threats
2.1 Fileless Malware, In-Memory Execution & Living-off-the-Land (LotL) 2.2 IoT & Operational Technology (OT/SCADA) Forensic Fundamentals 2.3 Dark Web, Tor Network, Onion Routing & Hidden Services Forensics 2.4 Blockchain Transactions, Cryptocurrency Tracing & Digital Asset Investigations
3 Chapter 3: Legal Frameworks, Search Warrants & Evidence Rules
3.1 Federal Rules of Evidence (FRE 702, 901, 902, 1001-1003) & Daubert/Frye Standards 3.2 Fourth Amendment, Warrant Exceptions, Workplace Search & Consent Protocols 3.3 International Standards: ISO/IEC 27037, ACPO Principles & ENFSI Guidelines 3.4 Cybercrime Statutes, Privacy Compliance, CAN-SPAM & International Cooperation
4 Chapter 4: eDiscovery, Chain of Custody & Professional Ethics
4.1 Electronic Discovery Reference Model (EDRM) & Legal Spoliation Holds 4.2 Chain of Custody Documentation, Evidence Packaging & Tamper-Evident Handling 4.3 Expert Witness Testimony, Report Writing Standards & EC-Council Code of Ethics
5 Chapter 5: Storage Architecture, Boot Sequences & Media Forensics
5.1 Storage Media Architecture: Sectors, Clusters, RAM/File Slack & Unallocated Space 5.2 Partition Tables & Boot Structures: MBR, GPT, VBR, BIOS vs. UEFI Secure Boot 5.3 RAID Reconstruction (RAID 0, 1, 5, 6, 10) & SSD Forensic Challenges (TRIM, Wear Leveling)
6 Chapter 6: Windows File Systems: NTFS & FAT
6.1 NTFS Architecture: Master File Table ($MFT) Record Structure & Attribute Headers 6.2 NTFS Artifacts: Alternate Data Streams (ADS), Volume Shadow Copies (VSS) & $LogFile 6.3 FAT12/16/32 and exFAT Architecture, Directory Entries & File Deletion Mechanics
7 Chapter 7: Non-Windows File Systems & File Signatures
7.1 Linux File Systems: ext2/ext3/ext4 Inode Architecture, Superblocks & Journaling Forensics 7.2 macOS File Systems: HFS+ and Apple File System (APFS) Architecture & Snapshots 7.3 File Signatures, Magic Bytes, Hex Headers/Footers & File Carving Techniques
8 Chapter 8: Investigation Lifecycle, Lab Setup & First Response
8.1 Forensic Laboratory Accreditation: ISO/IEC 17025 Standards & Hardware/Software Controls 8.2 First Responder Duties: Crime Scene Containment, Electronic Triage & Volatile Triage 8.3 Physical Evidence Packaging, Anti-Static/Faraday Protection & Transport Security
9 Chapter 9: Forensic Acquisition & Verification Methodology
9.1 Hardware and Software Write-Blockers: Operational Validation & Bridge Verification 9.2 Bit-Stream Disk Imaging, Physical vs. Logical vs. Targeted Acquisition Methodology 9.3 Forensic Image Formats (RAW/DD, E01, AFF) & Cryptographic Hashing Verification (MD5, SHA-256)
10 Chapter 10: Anti-Forensics Techniques & Countermeasures
10.1 Steganography Detection: Spatial/Frequency Domain Steganalysis & Hidden Carrier Extraction 10.2 Timestomping Countermeasures: Comparing $STANDARD_INFORMATION vs $FILE_NAME Timestamps 10.3 Secure Wiping, Degaussing, File Shredding Countermeasures & Residual Artifact Recovery
11 Chapter 11: Windows Operating System Forensics
11.1 Windows Registry Forensics: SYSTEM, SOFTWARE, SAM & NTUSER.DAT Hive Analysis 11.2 Execution Artifacts: Prefetch (.pf), Shimcache (AppCompatCache), Amcache.hve & UserAssist 11.3 User Activity Artifacts: ShellBags, LNK Shortcut Files, Jump Lists & Recycle Bin ($I/$R) 11.4 Windows Event Log Forensics: Security Audit IDs (4624, 4625, 4688, 4720, 7045) & EVTX Parsing
12 Chapter 12: Memory Forensics & Malware Analysis
12.1 Volatile Memory Acquisition: RAM Capture, Crash Dumps, Hiberfil.sys & Pagefile.sys 12.2 Memory Analysis with Volatility 3: pslist, pstree, malfind, netscan & Vadinfo 12.3 Static Malware Triage: Strings, PE Headers, Import Tables, Hashes & YARA Rule Matching 12.4 Dynamic Malware Analysis: Sandboxing, Process Monitor (Procmon), Regshot & Network Callouts 12.5 .NET Managed Malware Analysis & the GOOTLOADER Fileless Infection Chain
13 Chapter 13: Network, Web Application & Email Forensics
13.1 Network Forensics: PCAP Analysis, Protocol Dissection, Snort/Suricata & Flow Analysis 13.2 Web Server Forensics: Apache/IIS Access Logs, SQL Injection, XSS & Web Shell Detection 13.3 Email Forensics: RFC 5322 Headers, Authentication (SPF, DKIM, DMARC) & Mbox/PST Extraction 13.4 SIEM Event Correlation, Cross-Source Timeline Analysis & Super-Timeline Construction 13.5 Investigating Directory Traversal, Command Injection, Parameter Tampering, XXE, Cookie Poisoning & Brute Force 13.6 Network Device & Service Log Forensics: Firewall, IDS, Honeypot, Router, DHCP, Switch, VPN, DNS & SSH 13.7 Wireless Network Forensics: Rogue APs, Evil Twins, MAC Spoofing, Deauthentication & Jamming
14 Chapter 14: Mobile, Cloud & IoT Forensics
14.1 Mobile Device Forensics: Manual, Logical, File System & Physical Extraction (Android/iOS) 14.2 Mobile Artifact Analysis: Call Logs, SMS/Chat SQLite Databases, Location Data & Plists 14.3 Cloud Forensics: AWS CloudTrail, Azure Activity Logs & Multi-Tenant Evidence Collection 14.4 IoT Forensics: UART/JTAG Physical Interfaces, Firmware Extraction & Sensor Telemetry
15 Chapter 15: Commercial & Open-Source Forensic Suites
15.1 Commercial Forensic Platforms: EnCase Forensic, FTK (Forensic Toolkit) & FTK Imager 15.2 Open-Source Forensic Platforms: Autopsy, The Sleuth Kit (TSK) & SIFT/CAINE Workstations 15.3 Specialized DFIR Utilities: Eric Zimmerman Tools (EZ Tools) & Sysinternals Forensic Suite
16 Chapter 16: Analysis Toolkits, Python Scripting & Tool Validation
16.1 Reverse Engineering & Password Cracking: Ghidra, IDA Pro, Hashcat & John the Ripper 16.2 Python for Digital Forensics: Parsing Raw Artifacts, Custom Scapy Scripts & Evidence Automation 16.3 Forensic Tool Testing & Validation: NIST CFTT Methodology, ISO/IEC 17025 Standards & Daubert Compliance
17 Chapter 17: Database Forensics & Web Application Firewalls
17.1 MySQL Forensics: Internal Architecture, Data Directory, Information Schema & Utility Programs 17.2 SQL Server Forensics: SSMS, ApexSQL, SQLCMD Transaction-Log Collection, Plan Cache & Trace Files 17.3 Web Application Firewall (WAF) Architecture, Audit Logs, Benefits & Limitations
18 Chapter 18: Social, Virtualized, Multimedia & Browser Investigations
18.1 Social Media, Social Engineering, Insider Threat & Identity Theft Forensics 18.2 Virtualization, Container & Microservices Forensics, Bluetooth and Electron Chat Applications 18.3 Multimedia Forensics: Image, Audio & Video Authentication, EXIF, PRNU and Deepfake Detection 18.4 Browser Artifact Recovery, Private Browsing, USB Enumeration, Partition Recovery & Packer Unpacking Tools
7.3 File Signatures, Magic Bytes, Hex Headers/Footers & File Carving Techniques
Key Takeaways Explain This Topic AI
Operating system file extensions are superficial user-space indicators that can be trivially spoofed; true file type verification requires inspecting binary file signatures (magic bytes) located at defined offsets (typically offset 0x00).
CHFI candidates must memorize core forensic magic numbers, including JPEG (FF D8 FF ... trailer FF D9), PNG (89 50 4E 47 0D 0A 1A 0A ... trailer 49 45 4E 44 AE 42 60 82), GIF (47 49 46 38 37/39 61 ... trailer 00 3B), and PDF (25 50 44 46 ... trailer 25 25 45 4F 46).
Archive and executable signatures are critical for detecting masquerading: ZIP and modern Microsoft Office documents (DOCX, XLSX, PPTX) start with 50 4B 03 04; Windows executables feature the MZ header 4D 5A with the PE signature 50 45 00 00 at offset 0x3C; Linux binaries begin with 7F 45 4C 46 (ELF); and macOS binaries use Mach-O magic numbers (FE ED FA CE / CF or CF FA ED FE).
File carving extracts files from unallocated clusters without filesystem metadata using Header-Footer carving (scanning for SOF/EOF), File Length carving (parsing header-declared byte lengths), or Bifragment Gap Carving (reassembling non-contiguous fragmented files).
Standard forensic carving utilities include foremost (configuration-driven rules), scalpel (high-performance two-pass indexing), photorec (signature database of 480+ extensions), and bulk_extractor (stream-based feature extraction ignoring filesystem structures).
Last updated: September 2026
7.3 File Signatures, Magic Bytes, Hex Headers/Footers & File Carving Techniques
Quick Answer: File signatures (magic bytes) are standardized byte sequences placed at fixed offsets (usually byte 0x00 ) that authoritatively identify a file's format regardless of its file extension. Malicious actors routinely disguise malware or exfiltrate sensitive data by altering extensions (e.g., renaming a Windows executable malware.exe to invoice.pdf ). Forensic investigators expose extension mismatches by analyzing raw hex headers. Critical magic numbers include JPEG ( FF D8 FF / trailer FF D9 ), PNG ( 89 50 4E 47 0D 0A 1A 0A / trailer 49 45 4E 44 AE 42 60 82 ), PDF ( 25 50 44 46 / trailer 25 25 45 4F 46 ), ZIP/Office XML ( 50 4B 03 04 ), and Windows PE ( 4D 5A with 50 45 00 00 at offset 0x3C ). When file system metadata is wiped or corrupted, file carving reconstructs files from unallocated clusters using Header-Footer , File Length , or Bifragment Gap Carving with tools like foremost , scalpel , photorec , and bulk_extractor .
The Concept of File Signatures (Magic Bytes)
In modern operating systems, graphical file managers (such as Windows Explorer or macOS Finder) use file extensions ( .docx , .jpg , .pdf ) as superficial hints to select the default application for opening a file. However, file extensions provide zero cryptographic or forensic guarantee of file integrity.
Extension Spoofing vs. Magic Byte Analysis
Adversaries exploit operating system extension reliance through extension masquerading :
Renaming a malicious Portable Executable (PE) payload.exe to employee_roster.xlsx allows it to bypass basic email attachment filters.
Renaming an exfiltrated ZIP archive containing stolen intellectual property to system_diagnostic.log conceals outbound data transfer.
Digital forensics suites (Autopsy, EnCase, FTK) execute automated File Extension Mismatch Analysis , flagging any file whose declared extension conflicts with the binary magic bytes extracted from its file header. +---------------------------------------------------------------------------------------------------+
- | EXTENSION SPOOFING DETECTION |
- +---------------------------------------------------------------------------------------------------+
- | File Name: quarterly_financials.xlsx |
- | Declared Type: Microsoft Excel Worksheet |
- | Hex Bytes at 0x00: 4D 5A 90 00 03 00 00 00 ... (ASCII 'MZ') |
- | Hex Bytes at e_lfanew: 50 45 00 00 (ASCII 'PE' followed by 0x00 0x00) |
- | Forensic Finding: CRITICAL MISMATCH -> Windows Executable masquerading as an Excel workbook! |
- +---------------------------------------------------------------------------------------------------+
- Master Table of Critical CHFI File Signatures
The following hex headers, trailers, and offset rules represent core factual knowledge tested on the EC-Council CHFI exam:
File Format Header Signature (Hex) ASCII Representation Footer / Trailer (Hex) Key Forensic Characteristics & Offsets
JPEG / JFIF FF D8 FF E0 ÿØÿà FF D9 Standard JPEG JFIF format; begins with Start of Image (SOI FF D8 ).
JPEG / EXIF FF D8 FF E1 ÿØÿá FF D9 Digital camera/smartphone photos; contains EXIF metadata tags.
JPEG / Generic FF D8 FF DB / EE ÿØÿÛ / ÿØÿî FF D9 Samsung/raw camera JPEG; ends with End of Image (EOI FF D9 ).
PNG 89 50 4E 47 0D 0A 1A 0A .PNG.... 49 45 4E 44 AE 42 60 82 8-byte magic sequence; ends with the 12-byte IEND chunk.
GIF87a 47 49 46 38 37 61 GIF87a 00 3B Legacy CompuServe Graphics Interchange Format; trailer is 3B .
GIF89a 47 49 46 38 39 61 GIF89a 00 3B Animated GIF format; trailer byte 3B is preceded by block terminator 00 .
PDF 25 50 44 46 %PDF 25 25 45 4F 46 Version string follows (e.g., -1.7 ); footer is %%EOF (often with \r\n ).
ZIP Archive 50 4B 03 04 PK.. 50 4B 05 06 Local file header; End of Central Directory (EOCD) is 50 4B 05 06 .
MS Office OpenXML 50 4B 03 04 PK.. 50 4B 05 06 .docx , .xlsx , .pptx are ZIP containers holding XML files and folders.
RAR Archive (v4.x) 52 61 72 21 1A 07 00 Rar!... None (Block-based) Roshal Archive legacy 7-byte signature.
RAR Archive (v5.x) 52 61 72 21 1A 07 01 00 Rar!.... None (Block-based) Modern RAR5 8-byte signature.
7-Zip Archive 37 7A BC AF 27 1C 7z¼¯'. None (Header-based) Open-source high-compression archive format.
Windows PE (EXE/DLL) 4D 5A MZ None DOS header at 0x00 ; offset 0x3C ( e_lfanew ) points to 50 45 00 00 .
Linux ELF Binary 7F 45 4C 46 .ELF None Executable and Linkable Format; Byte 4: 1=32-bit, 2=64-bit; Byte 5: 1=LE, 2=BE.
macOS Mach-O (32-bit) FE ED FA CE þíúÎ None Big-Endian 32-bit Mach-O binary ( CE FA ED FE for Little-Endian).
macOS Mach-O (64-bit) FE ED FA CF þíúÏ None Big-Endian 64-bit Mach-O binary ( CF FA ED FE for Little-Endian).
Mach-O Fat Binary CA FE BA BE Êþº¾ None Universal binary holding multi-architecture Mach-O slices (Shared with Java class!).
- Deep-Dive: Executable and Document Signatures
- 1. Windows Portable Executable (PE) Internal Offsets
Every Windows executable ( .exe ), dynamic link library ( .dll ), kernel driver ( .sys ), and Control Panel applet ( .cpl ) follows the Portable Executable format:
Offset 0x00 - 0x01 : DOS Header Magic 4D 5A (ASCII MZ , honoring Mark Zbikowski, architect of MS-DOS).
Offset 0x3C - 0x3F ( e_lfanew ): A 4-byte little-endian pointer specifying the exact byte offset where the true NT PE File Header begins.
PE Header Signature: At the offset specified by e_lfanew , the file MUST contain the 4-byte signature 50 45 00 00 (ASCII PE followed by two null bytes 0x00 0x00 ).
Machine Architecture (Offset e_lfanew + 4 ): 0x014C indicates 32-bit x86; 0x8664 indicates 64-bit AMD64/x86_64. +---------------------------------------------------------------------------------------------------+
- | WINDOWS PORTABLE EXECUTABLE (PE) ANATOMY |
- +---------------------------------------------------------------------------------------------------+
- | 0x00: DOS Header Magic -> 4D 5A ('MZ') |
- | ... |
- | 0x3C: e_lfanew Pointer -> E0 00 00 00 (Points to byte offset 0xE0) |
- | ... |
- | 0xE0: NT PE Signature -> 50 45 00 00 ('PE' + 0x00 0x00) |
- | 0xE4: Machine Field -> 64 86 (0x8664 = 64-Bit x86_64 Executable) |
- +---------------------------------------------------------------------------------------------------+
- 2. Microsoft Office: OLE Compound Documents vs. OpenXML
Legacy Office (DOC, XLS, PPT): Begin with the OLE CF (Compound File) Header : D0 CF 11 E0 A1 B1 1A E1 (colloquially remembered as "DocFile" ). This is a structured virtual filesystem inside a single file.
Modern Office (DOCX, XLSX, PPTX): Built upon Microsoft Office Open XML standards. Because OpenXML files are standard ZIP archives containing XML structures and media, they begin identically with the PK zip header: 50 4B 03 04 .
3. Java Bytecode vs. Mach-O Fat Binary Collision
Notice that the hex sequence CA FE BA BE ( "Babe Cafe" ) represents both:
A compiled Java Class File ( .class ).
A macOS Mach-O Fat / Universal Binary .
Forensic Disambiguation: Examiners distinguish between them by inspecting bytes 4–7: in a Java class file, bytes 4–7 specify the Java minor/major version (e.g., 00 00 00 34 for Java 8); in a Mach-O fat binary, bytes 4–7 specify the number of fat architecture headers ( fat_arch count).
File Carving Methodologies & Algorithms
File carving is the forensic process of reassembling and extracting files from raw unstructured data streams (such as unallocated space, drive slack, or raw memory dumps) without relying on file system metadata (such as MFT records, FAT directories, or ext4 inodes). +---------------------------------------------------------------------------------------------------+
- | FILE CARVING METHODOLOGIES |
- +---------------------------------------------------------------------------------------------------+
- | 1. Header-Footer (SOF/EOF) -> Scans for Start-of-File and stops at End-of-File marker |
- | 2. File Length Carving -> Reads internal length field in header and extracts exact byte count |
- | 3. Bifragment Gap Carving -> Carves fragmented clusters across non-contiguous gaps |
- +---------------------------------------------------------------------------------------------------+
- 1. Header-Footer (SOF / EOF) Carving
Mechanism: The carver scans sector by sector for a known Start of File (SOF) signature (e.g., FF D8 FF for JPEG). Once detected, the carver writes subsequent contiguous sectors to an output file until it encounters the designated End of File (EOF) trailer (e.g., FF D9 for JPEG or 49 45 4E 44 AE 42 60 82 for PNG).
Forensic Challenge - False Trailers: Embedded data can fool naive header-footer carvers. For example, a digital camera JPEG frequently contains a smaller thumbnail JPEG inside its EXIF metadata. A naive carver encountering the thumbnail's FF D9 trailer prematurely halts, yielding a corrupt, truncated image.
2. File Length / Structure Carving
Many common file formats do not possess a static footer marker (e.g., BMP, WAV, AVI, ZIP). Instead, they define their file size within internal header structures:
Bitmap (BMP): Bytes 0x02 - 0x05 specify the total file size as a 32-bit little-endian integer.
PNG: Operates via sequential chunks ( IHDR , IDAT , PLTE , IEND ). Each chunk starts with a 4-byte length field. The carver jumps from chunk to chunk until the IEND chunk is processed.
ZIP / Office Documents: The carver locates the End of Central Directory (EOCD) signature 50 4B 05 06 , parses the Central Directory offset, and computes the archive boundary.
3. Fragmentation Carving & Bifragment Gap Carving
On heavily utilized or aging storage drives, files are rarely written into contiguous physical sectors. When a file is fragmented, standard linear carving captures unrelated cluster data (gap data), producing corrupted files.
Bifragment Gap Carving Algorithm:
Locates the header (Fragment A) and potential footers (Fragment B) across unallocated space.
Employs hypothesis testing : assumes the file is split into two fragments with an arbitrary intervening gap.
Validates candidate reassemblies using semantic parsers, entropy transitions, or format-specific decompression checks (e.g., verifying that zlib/DEFLATE blocks decompress without CRC checksum errors).
Practical Forensic Carving Tools & Workflows
Digital forensics laboratories utilize specialized open-source and commercial utilities to carve unallocated space. +---------------------------------------------------------------------------------------------------+
- | FORENSIC CARVING TOOL COMPARISON |
- +-------------------+--------------------+------------------------+---------------------------------+
- | Tool | Author / Origin | Operational Model | Primary Forensic Strength |
- +-------------------+--------------------+------------------------+---------------------------------+
- | **foremost** | US Air Force OSI | Rule-based linear scan | Lightweight, config-driven |
- | **scalpel** | Golden G. Richard | Two-pass indexed scan | High-speed on massive TB images |
- | **photorec** | Christophe Grenier | Signature & structural | 480+ formats, ignores filesys |
- | **bulk_extractor**| Simson Garfinkel | Feature stream parser | Extracts URLs, PII, EXIF, zlib |
- +-------------------+--------------------+------------------------+---------------------------------+
- 1. foremost
Originally developed by the United States Air Force Office of Special Investigations (AFOSI). Reads configuration parameters from /etc/foremost.conf .
Configuration Syntax: extension case_sensitive max_size header footer # Foremost configuration file syntax (hex values preceded by \x)
- # Format: extension case_sensitive max_size header_signature trailer_signature
- jpg y 20000000 \xff\xd8\xff \xff\xd9
- png y 20000000 \x89\x50\x4e\x47\x0d\x0a\x1a\x0a \x49\x45\x4e\x44\xae\x42\x60\x82
- pdf y 50000000 \x25\x50\x44\x46 \x25\x25\x45\x4f\x46
- Command Execution: # Carve all supported image and document formats from unallocated space
- foremost -t jpg,png,pdf,docx -i /evidence/unallocated.raw -o /cases/carved_output/
- 2. scalpel
A total rewrite of foremost designed to eliminate excessive memory consumption and redundant disk I/O on massive storage volumes.
Two-Pass Architecture: Pass 1 scans the entire raw disk image to build an in-memory index of all header and footer locations. Pass 2 resolves fragment boundaries and writes carved files to disk.
Requires un-commenting target file signatures in scalpel.conf prior to execution: # Execute scalpel against raw disk image
- scalpel -c /etc/scalpel/scalpel.conf -o /cases/scalpel_output/ /evidence/disk_image.dd
- 3. photorec
Maintained by CGSecurity, photorec is an exceptionally robust carving utility bundled with testdisk . It recognizes over 480 file extensions and handles non-contiguous fragments by checking cluster continuity and internal file structures.
4. bulk_extractor
Unlike traditional carvers that output complete reconstructed files, bulk_extractor operates as a stream-based feature extraction tool .
It scans every byte of raw disk images, pagefiles, or memory captures, completely ignoring file systems and partition tables.
Carves and indexes high-value forensic tokens: email addresses, URLs, domain names, credit card numbers, phone numbers, GPS EXIF coordinates, and compressed zlib streams .
Automatically decompresses internal raw zlib streams to carve nested artifacts (such as SQLite databases or browser caches embedded in RAM): # Run bulk_extractor across memory dump to extract telemetry and network tokens
- bulk_extractor -o /cases/bulk_results/ /evidence/memory.dmp
- Carving Validation & False Positive Reduction
Carving algorithms inevitably produce false positives—random byte sequences that coincidentally match a 3-byte header signature.
Validation Parsers: Forensic pipelines execute post-carve validation scripts (e.g., verifying that carved JPEGs can be rendered by libjpeg , or testing that carved ZIP archives pass unzip -t integrity validation).
CRC32 Checksum Validation: Formats like PNG incorporate 4-byte CRC32 checksums at the end of each chunk. If the calculated CRC32 does not match the stored checksum, the fragment is discarded.
Entropy Heuristics: Unallocated clusters containing encrypted volumes (BitLocker, FileVault) display near-maximum Shannon entropy (~7.99 bits/byte). Carvers must suppress header matching on high-entropy blocks to prevent carving garbled noise.