Labs / Forensics / The analyst's bench

Lab 2 of 5 · The analyst's bench

File carving: getting back what someone deleted

Recover deleted files two ways: from file-system metadata, and by carving raw bytes.

Start this lab 4 steps

The idea

Hana, who runs IT at Fenwick Logistics, pulled a USB drive from the dispatch laptop lp03. Its data folder is empty, yet last week it held the route list. Get the deleted files back for her, two different ways.

What a delete changes, and what it leaves
What a delete changes, and what it leaves
The address still leads to the bytes
The address still leads to the bytes
A carver only sees signatures
A carver only sees signatures
What each method gives back
What each method gives back

Steps

  1. What "delete" actually does

    When you delete a file, almost nothing happens to the file's data. The file system keeps a directory of names, each pointing at the blocks that hold the content. Deleting marks the directory entry as deleted and frees those blocks for reuse, but it does not scrub them.

    The content stays on the drive, untouched, until some new file is written over the top of it. Until then it can be recovered in full.

    That is why an investigator never trusts an empty folder. Hana's drive was copied byte for byte into one file, /evidence/field-drive.img, called an image, so the drive itself stays untouched. The Sleuth Kit's fls lists a file system's directory entries straight from the image, and -d shows the deleted ones, which an ordinary ls hides. Each gets a * and an address: the number the file system used to find the file's content, which you'll use next to read it back.

    So before you tell Hana her route list is gone, list the deleted entries on the drive's first partition (it starts at sector 2048).

    analyst:~# fls -r -d -o 2048 /evidence/field-drive.img
  2. Method one: recover by metadata

    The fastest recovery uses what the file system left behind. A deleted entry still leads to the blocks that held the file, so icat reads them straight back, as long as nothing has overwritten them. This is metadata recovery: give icat the address fls printed, and it prints the file's content.

    Its big advantage is that you keep the context the file system knew: the file's name, its folder, often its size and times. When the file system is intact, this is the method to reach for first.

    Read Hana's missing route list back by its address, 583.

    analyst:~# icat -o 2048 /evidence/field-drive.img 583
  3. Method two: carve by header

    Sometimes the file system itself is gone: reformatted, corrupted, or a raw dump with no structure to read. Then you have no directory entries and no addresses to follow, and icat has nothing to work with. You fall back to carving: ignore the file system entirely and scan every byte of the image for the signatures that mark where a file of a given type begins and ends.

    Most file types have them. A JPEG starts with the bytes FF D8 FF and ends FF D9; a ZIP starts PK\x03\x04.

    A carver like foremost finds those markers and writes out whatever lies between as a recovered file. It needs no file system at all, only the raw bytes.

    Carve the JPEGs and ZIPs out of the image.

    analyst:~# foremost -t jpg,zip -i /evidence/field-drive.img -o carved
    analyst:~# cat carved/audit.txt
  4. Two methods, two jobs

    Put the two recoveries side by side and each one's job becomes clear. Start with what carving named its files.

    ls the carved output, then run file on the carved JPEG to confirm it really is a valid image and not a false hit. A carver can be fooled: any stretch of bytes that happens to start with FF D8 FF looks like a JPEG header to it.

    analyst:~# ls -R carved
    analyst:~# file carved/jpg/00002160.jpg

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab