Disk and File Forensics
Chapters and transcript
Disk and File Forensics Most investigations involve a disk at some point. A disk holds files. But it also holds traces of files that were deleted, and hidden details about when and how files were used. In this lesson, you will learn how file systems store data, why deleted files can often be recovered, what timestamps reveal, and how file signatures expose fake extensions.
File systems A storage device is just a long list of numbered blocks. A file system organises those blocks into files and folders. It keeps a kind of index. For each file, it records the name and size, the timestamps, and which blocks belong to it.
File systems Common file systems. N T F S on Windows computers. Its main index is the Master File Table, where every file has at least one record. FAT thirty-two and exFAT on USB drives and memory cards. ext four on Linux computers and servers. Each file there has an inode, a record that points to its data blocks. And A P F S on Macs, iPhones and iPads.
Where data hides Two areas of a disk interest investigators. Allocated space is used by existing files. Unallocated space is marked as free, but may still hold data from old, deleted files. There is also slack space. Files are stored in fixed-size units called clusters. If a file does not fill its last cluster, the leftover part may still hold fragments of older data.
Deleted files What happens when you delete a file? In Windows, it usually goes to the Recycle Bin first, so it is easy to restore. When the bin is emptied, the file system does not erase the data. It marks the file record as no longer in use, and marks its blocks as free. The data stays on the disk until new files are written over it. That is why deleted files can often be recovered.
Deleted files Free tools such as Autopsy can list deleted files whose records still exist. But recovery is not always possible. If new data has overwritten the space, the old data is gone. Most SSDs use TRIM. The SSD may clear unneeded blocks soon after, so recovery is much harder. Secure deletion tools overwrite data on purpose. And encrypted drives may be unreadable without the key.
File carving Sometimes the record of a deleted file is gone, but the data is still in unallocated space. Then investigators use file carving. The tool searches raw disk data for a pattern that marks the start of a file type, and sometimes the end. It then cuts out the data between them. Carving can recover photos even from a formatted drive. But carved files have no original name, folder or timestamps, and large files may come back damaged.
Timestamps Metadata means data about data. File systems usually keep four timestamps, called M A C B. M is modified: when the content last changed. A is accessed: when the file was last read. C is changed: when the file system record changed, for example a rename. But some Windows tools use C for created, so check the documentation. And B is born: when the file was created.
Timestamps Timestamps help build a story. An employee is about to resign. A file of customer data is copied from the work laptop to a USB drive. On the USB drive, the file shows a creation time just before the resignation. That is an important clue.
Timestamps But treat timestamps with care. Access times are often not updated reliably, because updating them on every read slows systems down. Copying a file usually gives the copy a new creation time. Attackers can change timestamps on purpose. This is called timestomping. And timestamps may be stored in U T C or local time. Always note the time zone. Pakistan Standard Time is U T C plus five.
Metadata inside files Files also carry metadata inside them. Photos may contain EXIF data, such as the camera model and date taken, and sometimes the GPS location. Word and PDF documents may record the author name, and the software used and when the document was created. On Windows, you can see this under Properties, then Details. It is a good reminder to remove location data before sharing photos publicly.
File signatures An extension is only part of a name, and anyone can rename a file. The real type is shown by the file signature, also called magic bytes: a few fixed bytes at the very start. A PDF starts with percent P D F. A PNG image starts with dot P N G. A JPEG starts with F F D 8 F F. A ZIP file, which includes docx and xlsx, starts with P K. And a Windows program starts with M Z.
Try it yourself You can try this on your own files. On Linux or macOS, copy a photo and give the copy a dot txt name. The file command reads the signature, not the extension. It still reports a JPEG image. Then xxd shows the first bytes, and they start with F F D 8 F F.
Try it yourself On Windows PowerShell, Format-Hex shows the first bytes of a file. Here is a file called invoice dot pdf. A real PDF would start with percent P D F. But this one starts with M Z. It is a Windows program renamed to fool people. This is a signature mismatch, and forensic tools flag these automatically.
Quick check Quick check. A file named notes dot txt starts with the bytes 25 50 44 46, which read as percent P D F. What is this file really? Look back at the signatures, then choose.
Key takeaways Let us put it together. A file system is an index of blocks, files and timestamps. Deleting usually marks space as free, and the data stays until overwritten. Carving can recover files without their records. Timestamps tell a story, but check them against other evidence. And the signature shows the real file type. Now read the lesson below, try the lab, and answer the quiz.
Most digital investigations involve a disk at some point. The disk holds files, but it also holds traces of files that were deleted, and hidden details about when and how files were used. This lesson explains these ideas at a concept level, so you understand what forensic tools are showing you.
How file systems organise data
A storage device such as a hard drive or SSD is just a long list of numbered blocks. A file system is the system that organises those blocks into files and folders. It keeps a kind of index that says which blocks belong to which file, along with the file's name, size and timestamps.
Common file systems:
| File system | Usually found on |
|---|---|
| NTFS | Windows computers |
| FAT32 and exFAT | USB drives and memory cards |
| ext4 | Linux computers and servers |
| APFS | Apple Mac computers, iPhones and iPads |
In NTFS, the main index is called the Master File Table (MFT). Each file and folder has at least one record in it. In ext4, each file has an inode, a record that stores its details and points to its data blocks.
Two areas of a disk are especially interesting to investigators:
- Allocated space: blocks currently used by existing files.
- Unallocated space: blocks marked as free. They may still contain data from old, deleted files.
There is also slack space. Files are stored in fixed-size units called clusters. If a file does not fill its last cluster, the leftover part may still hold fragments of older data.
What happens when a file is deleted
When you delete a file in Windows, it usually goes to the Recycle Bin first. That is just a special folder, so the file is easy to restore.
When the Recycle Bin is emptied, or a file is deleted directly, the file system normally does not erase the data. It simply:
- Marks the file's record as no longer in use
- Marks its blocks as free for new data
The data stays on the disk until new files are written over it. This is why deleted files can often be recovered. Forensic tools such as Autopsy, a free and open-source tool, can list deleted files whose records still exist.
Recovery is not always possible:
- If the space has been overwritten by new data, the old data is gone.
- Most SSDs use a feature called TRIM. The operating system tells the SSD which blocks are no longer needed, and the SSD may clear them soon after. Deleted data on SSDs is often much harder to recover than on traditional hard drives.
- Secure deletion tools overwrite data on purpose.
- Encrypted drives may be unreadable without the key.
File carving
Sometimes the file system record of a deleted file is gone, but the data is still in unallocated space. Investigators can then use file carving. Carving tools search raw disk data for known patterns that mark the start, and sometimes the end, of a file type. They then cut out the data between them.
Carving can recover photos and documents even from a formatted drive. But carved files have no original name, folder or timestamps, and large or fragmented files may come back damaged.
Timestamps and metadata
Metadata means "data about data". For a file, it includes the name, size, owner and timestamps. File systems usually keep four kinds of timestamps, often called MACB:
| Letter | Meaning |
|---|---|
| M | Modified: when the file's content last changed |
| A | Accessed: when the file was last read |
| C | Changed: when the file system record changed (for example, a rename). On Windows tools, C sometimes means "created", so always check the tool's documentation |
| B | Born: when the file was created |
Timestamps help build a story. For example, if a file of customer data shows a creation time on a USB drive just before an employee resigned, that is important.
But timestamps must be treated with care:
- Access times are often not updated reliably, because updating them on every read slows systems down.
- Copying a file to a new place usually gives the copy a new creation time.
- Attackers can change timestamps on purpose. This is called timestomping.
- Timestamps may be stored in UTC or local time. Always note the time zone. Pakistan Standard Time is UTC+5.
Files also carry metadata inside them:
- Photos may contain EXIF data: camera model, date taken and sometimes GPS location.
- Word and PDF documents may record the author name, the software used and when the document was created.
File signatures and extensions
A file's extension, such as .jpg or .pdf, is only part of its name. Anyone can rename a file. The real type of a file is shown by its file signature, also called magic bytes: a few fixed bytes at the very start of the file.
| File type | Signature (hex) | As text |
|---|---|---|
25 50 44 46 |
%PDF |
|
| PNG image | 89 50 4E 47 |
.PNG |
| JPEG image | FF D8 FF |
(not readable) |
| ZIP (also .docx and .xlsx) | 50 4B 03 04 |
PK.. |
| Windows program (.exe, .dll) | 4D 5A |
MZ |
A signature mismatch is when the extension and signature do not agree. An executable program renamed invoice.pdf is a classic trick to fool people. Forensic tools flag these mismatches automatically, because a person hiding data or malware may rename files.
Try it yourself
You can look at file signatures and metadata safely on your own files.
On Linux or macOS, the file command reads the signature, not the extension:
cp photo.jpg test.txt
file test.txt
xxd test.txt | head -n 1
file will still report a JPEG image, and xxd shows the first bytes, starting with ffd8ff.
On Windows PowerShell, you can view the first bytes of a file like this:
Format-Hex .\test.txt | Select-Object -First 1
Also try this: right-click one of your own phone photos on a computer, choose Properties, then Details on Windows. You may see the camera model, date taken and even location. This is a good reminder to remove location data before sharing photos publicly.
HANDS-ON LAB
The Photo That Is Not a Photo
One file on a USB drive is not what its name says. Use file signatures to find it.
Check your understanding
Answer every question correctly to complete this lesson. If you miss one, try the quiz again.
1. A user deletes a file and empties the Recycle Bin on a hard drive. What usually happens to the file's data straight away?
2. A file named holiday.jpg starts with the bytes 4D 5A, which appear as the letters MZ. What is the most likely explanation?
3. Why should an investigator be careful about trusting a file's timestamps?
Locked: answer every quiz question above correctly to complete this lesson.
Spotted a mistake or something unclear? Report a mistake