Sixty-four million bytes and no folders
Open a disk image in a text viewer and you see bytes, not files. Yet somewhere in them is a USB stick's client list, deleted the night it went missing.
A disk has layers: a table of partitions, then a file system in each. Read them in order and the files, deleted ones too, come back.
By the end of this lesson
Note
I can find a partition in a disk image and list its files, deleted ones included.
Key words
| Word | What it means | Example |
|---|---|---|
| Sector | the smallest unit a disk reads, usually 512 bytes | |
| Partition table | a list of where each partition starts and ends | |
| Offset | how far into the image something starts | -o 2048 |
| File system | the structure that turns blocks into named files | |
| Inode | a record of one file's size, times and blocks | |
| Unallocated | space the file system has marked free |
The cells students fill in are left blank in this preview.
Starter
Have a go
Starter
4 questionsThe one rule
Important
Examine only your own lab copy. Reading another person's disk needs their written permission or a lawful order, under the Computer Misuse Act 1990. Larkfield Design, its staff and their files are made up.
The disk from lesson 1
This lesson reads suspect.img, the made-up firm's disk that lesson 1 made in ~/forensics. If the Run below says it is missing, do lesson 1's first Runs on this VM, then come back.
Move in and find the disk
cd ~/forensics && ls -l suspect.imgShown here, not run. Press Start lab to type it into your own lab’s terminal.
The partition table is 64 bytes
The first sector of an MBR disk ends with a partition table: four entries of 16 bytes from byte 446. Byte 4 of an entry is the type, bytes 8 to 11 the first sector and 12 to 15 the count, written low byte first.
Read the two entries yourself, then let mmls read them for you.
Print the first two partition entries
od -A d -t x1 -j 446 -N 32 suspect.imgShown here, not run. Press Start lab to type it into your own lab’s terminal.
Worked example: the first entry
| Bytes | Hex | Meaning |
|---|---|---|
| 4 | 06 | Type: FAT16 |
| 8 to 11 | 00 08 00 00 | 0x0800 = sector 2048 |
| 12 to 15 | 00 00 01 00 | 0x10000 = 65536 sectors |
| Offset | 2048 x 512 | 1048576 bytes in |
The cells students fill in are left blank in this preview.
Let mmls read the table
mmls suspect.imgShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check
Have a go
Check
3 questionsTry it: decode an entry
entry = bytes.fromhex("00 20 21 00 06 34 30 04 00 08 00 00 00 00 01 00")
kind = entry[4]
start = int.from_bytes(entry[8:12], "little")
sectors = int.from_bytes(entry[12:16], "little")
print("type", hex(kind), "starts at sector", start, "and holds", sectors, "sectors")
print("byte offset", start * 512)
# Change the start bytes 00 08 00 00 to 00 08 01 00, then press Run.
Make a free account to save your work and track your progress.
Each partition holds a file system
The Sleuth Kit's tools read one file system at a time, so you give the offset in sectors with -o. fsstat describes it, fls lists names and istat shows one file's record.
The stick is FAT16 and the laptop folder ext4. In ext4 each file's record is an inode; fls prints its number before the name.
Describe the stick's file system
fsstat -o 2048 suspect.img | head -8Shown here, not run. Press Start lab to type it into your own lab’s terminal.
List the stick's files
fls -o 2048 suspect.imgShown here, not run. Press Start lab to type it into your own lab’s terminal.
List every file in the laptop folder
fls -r -o 67584 suspect.imgShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check
Have a go
Check
3 questionsDeleted does not mean gone
FAT deletes a file by marking its directory entry with the byte E5 and freeing its clusters in the table. The bytes stay until something reuses them, so icat can read them back by the entry number.
ext4 is harsher. The kernel empties the inode's list of blocks, so the name survives but the path to the data does not. Those blocks are now unallocated.
Read the deleted CSV's record on the stick
istat -o 2048 suspect.img 9Shown here, not run. Press Start lab to type it into your own lab’s terminal.
Recover its first four lines
icat -o 2048 suspect.img 9 | head -4Shown here, not run. Press Start lab to type it into your own lab’s terminal.
Read the deleted download's inode on the laptop
istat -o 67584 suspect.img 25Shown here, not run. Press Start lab to type it into your own lab’s terminal.
A common mistake
Warning
Many people think deleting a file wipes its data. Usually only the record that points at it changes, and the bytes stay until something overwrites them. So a deleted file can come back, whole on FAT, or by carving when ext4 has lost its blocks.
Read the laptop's authorized_keys by its inode
icat -o 67584 suspect.img 26Shown here, not run. Press Start lab to type it into your own lab’s terminal.
Check
Have a go
Check
3 questionsAssignment: read a partition table
partitions(sector) takes the first 512 bytes of a disk and returns its MBR partitions as a list of dictionaries with "slot" (0 to 3), "type" (an int), "start" and "sectors", skipping any entry whose type is 0. The table starts at byte 446; each entry is 16 bytes, with the type at byte 4, the start at bytes 8 to 11 and the count at 12 to 15, little-endian. If the last two bytes are not 55 AA, return an empty list.
byte_offset(start, sector_size=512) returns where a partition starts in bytes.
fat_name(entry) takes a 32-byte FAT directory entry and returns (name, deleted): the name as BASE.EXT with the spaces removed (just BASE when there is no extension), and deleted True when the first byte is 0xE5, in which case the name starts with _.
def partitions(sector):
return []
def byte_offset(start, sector_size=512):
return 0
def fat_name(entry):
return ("", False)
Make a free account to save your work and track your progress.
Exit quiz
Have a go