Skip to main content
Be Bitwise

Disk Forensics for Low-Level Analysis

Binary Forensics & Crash Analysis · Defense & Forensics track

7 min read

In this module

Below the Filesystem

Disk forensics examines storage at the lowest levels — raw sectors, partition tables, filesystem structures, and the residue between allocated files. Memory forensics chases volatile state; disk forensics recovers the persistent kind: deleted files, hidden data, and traces that survive reboots.

Raw Disk Analysis

A disk is fundamentally a linear array of sectors (typically 512 bytes or 4096 bytes). Everything on the disk - partition tables, filesystems, files, free space - is just data at specific sector offsets. Raw disk analysis works directly with these sectors, bypassing the operating system's filesystem layer.

Disk imaging creates a bit-for-bit copy of the entire disk, preserving everything including unallocated space, slack space, and deleted file remnants:

bash
# Create a forensic disk image with dd
dd if=/dev/sda of=/evidence/disk.img bs=4M status=progress
# Better: use dcfldd or dc3dd for forensic imaging with hashing
dcfldd if=/dev/sda of=/evidence/disk.img hash=sha256 hashlog=/evidence/hash.log
# Verify the image integrity
sha256sum /evidence/disk.img

Always work with images, never the original. The original is evidence and must stay unmodified. Use a hardware write blocker during imaging — no exceptions.

MBR and GPT Analysis

The first sectors of a disk contain the partition table, which maps the disk's layout:

MBR (Master Boot Record): Located at sector 0 (first 512 bytes). Contains the boot code (446 bytes), partition table (4 entries of 16 bytes each), and the boot signature (0x55AA). Examining the MBR reveals the disk's partition layout and whether the boot code has been modified (as some bootkits do).

GPT (GUID Partition Table): Used on modern UEFI systems. Located starting at sector 1 (sector 0 contains a protective MBR). GPT includes CRC32 checksums of the header and partition entries, with a backup copy at the end of the disk.

bash
# Examine partition layout
fdisk -l /evidence/disk.img
# Detailed GPT analysis
gdisk -l /evidence/disk.img
# Parse MBR with The Sleuth Kit
mmls /evidence/disk.img

Forensic analysts examine partition tables for anomalies: hidden partitions, gaps between partitions that might contain hidden data, or modified boot code that indicates a bootkit infection.

File Carving

When files are deleted, the filesystem marks their clusters as free but typically does not overwrite the data. File carving recovers this data by scanning raw disk sectors for file signatures:

bash
# File carving with Scalpel
scalpel -c /etc/scalpel/scalpel.conf -o /evidence/carved/ /evidence/disk.img
# File carving with foremost
foremost -i /evidence/disk.img -o /evidence/carved/
# PhotoRec for multimedia recovery
photorec /evidence/disk.img

Carving works by identifying magic bytes (file headers) and either file footers or expected file sizes. For example, JPEG files start with 0xFFD8FF and end with 0xFFD9. PNG files start with 0x89504E47 and have a structured chunk format. PDF files start with %PDF-.

Fragmented Files

File carving works best when files are stored contiguously on disk. Fragmented files (split across non-adjacent clusters) produce corrupted carved results because the carver does not know the cluster chain. Advanced carving tools use filesystem metadata (when available) or file-format-specific validation to handle fragmentation, but recovery rates decrease with fragmentation.

Try it on a toy image below. Scan for signatures, then carve the first JPEG from its FFD8FF header to its FFD9 footer and watch the segment walk pass. Do the same for the JPEG at cluster 10: the carve swallows a cluster of someone's meeting notes and the walk falls over, so leave that cluster out (or let the gap search find it) and carve again.

Carve files from raw clusters

A 2 KiB slice of unallocated space, split into 32 clusters of 64 bytes. Real file systems usually use 4 KiB clusters; these are shrunk so the whole slice fits. Illustrative data, generated in code.

Clusters

Grey clusters are all zeros. A dot marks a signature once you've scanned. Blue is the carved range.

Cluster 0 (0x000)
0x00000000000000000000000000000000000
0x01000000000000000000000000000000000
0x02000000000000000000000000000000000
0x03000000000000000000000000000000000

Searches every byte for JPEG (FF D8 FF … FF D9) and PNG (89 50 4E 47 … IEND AE 42 60 82) magic numbers.

A carver never reads the file system, so it can't follow a cluster chain. It assumes everything from header to footer belongs to one file. When a file is fragmented, the carve picks up another file's clusters. Gap carving and structure checks like the walk above are how smarter carvers spot and repair that.

SSDs and TRIM

Everything above assumes a spinning disk, where deleted data sits untouched until something overwrites it. On an SSD with TRIM enabled, the operating system tells the drive which blocks are free when a file is deleted, and the drive's garbage collection erases them in the background, often within minutes. Most such drives then return zeros for trimmed blocks, so carving unallocated space on a modern SSD usually finds little or nothing. Wear levelling adds a second problem: the drive remaps blocks internally, so a sector-level image shows only what the controller chooses to expose.

Slack Space Analysis

Filesystem slack space contains remnants of previously deleted files:

File slack: The space between the end of a file's logical content and the end of its last allocated cluster. If a 1 KB file occupies a 4 KB cluster, the remaining 3 KB may contain data from a previously deleted file.

RAM slack: The space between the end of a file's content and the end of the current sector. This is typically zeroed by modern operating systems but may contain kernel memory contents on older systems.

bash
# Extract slack space with The Sleuth Kit
blkstat /evidence/disk.img BLOCK_NUMBER # Examine a specific block
fls -rd /evidence/disk.img # List deleted files
icat /evidence/disk.img INODE_NUMBER # Recover deleted file by inode

Hidden Data Detection

Beyond standard deleted file recovery, forensic analysts look for deliberately hidden data:

Host Protected Area (HPA) and Device Configuration Overlay (DCO) are disk regions hidden at the firmware level. The disk reports a smaller capacity than it actually has, and the hidden sectors are invisible to the operating system. Forensic tools like hdparm can detect and access these regions.

Alternate Data Streams (ADS) on NTFS allow data to be attached to a file without being visible in normal directory listings. Malware uses ADS to hide payloads in apparently innocuous files.

Filesystem journal/log analysis: Modern filesystems (ext4, NTFS, APFS) maintain journals that record recent filesystem changes. Examining the journal can reveal recently deleted files, renamed files, and permission changes even when the files themselves have been securely wiped.

Timeline Analysis

Forensic analysts construct timelines by correlating filesystem timestamps across all files:

  • MACB times: content Modified, last Accessed, metadata Changed (inode change on Unix, MFT entry change on NTFS) and Born (creation), for every file. Not every filesystem records all four; ext3, for one, has no birth time
  • Journal entries: Filesystem journal records with timestamps
  • Log files: Application and system log timestamps
  • Browser artifacts: History, cache, and cookie timestamps
bash
# Generate a timeline with The Sleuth Kit
fls -r -m "/" /evidence/disk.img > bodyfile.txt
mactime -b bodyfile.txt -d > timeline.csv

A timeline reconstructs the sequence of events: when malware landed on disk, when it ran, what files it touched, when cleanup happened. Timestamp anomalies need context before they mean anything. A creation date after the modification date is routine: copying a file on Windows usually gives the copy a new creation time but keeps the old modification time, and extracting an archive does much the same. Timestamps in the distant future or past, $STANDARD_INFORMATION times earlier than the matching $FILE_NAME times on NTFS, or suspiciously round values such as all-zero sub-second fields are much stronger hints of deliberate manipulation.

Anti-Forensics

Sophisticated attackers use anti-forensics techniques: secure file deletion (overwriting data before deleting), timestamp manipulation (timestomping), log clearing, and disk wiping. Understanding these techniques is essential for forensic analysts because detecting anti-forensics activity is itself evidence of compromise. Discrepancies between filesystem timestamps and journal timestamps, for example, reveal timestomping attempts.