UnixDroid

Lesson 4 of 8 · 8 min

Recovering deleted files with Sleuth Kit & PhotoRec

Bring deleted files back two ways: from leftover file system records, and by carving raw bytes.

You have a verified image. Now it's time to bring deleted files back. There are two main techniques, and a good investigator uses both.

TechniqueHow it worksWorks when
File system recoveryReads leftover file system records (MFT entries, inodes, FAT directory entries) that still point to the dataThe file system records haven't been overwritten
File carvingIgnores the file system and scans raw bytes for known file signaturesThe records are gone but the content survives

File system recovery with The Sleuth Kit

The Sleuth Kit (TSK) is a set of command-line forensic tools, pre-installed on Kali.

mmls case01.img           # show partitions and where they start
fsstat case01.img         # file system type and details
fls -r -d case01.img      # list deleted files only (-d), recursively (-r)

If the image is a whole disk with partitions, give the start sector from mmls with -o, for example fls -o 2048 -r -d disk.img.

fls output looks like this:

r/r * 12:   secret-plans.pdf

The * means deleted. 12 is the inode (or MFT entry) number. Recover the file with icat:

icat case01.img 12 > recovered-secret-plans.pdf

Tip: This works well on NTFS and FAT. On ext4, Linux wipes the block pointers when a file is deleted, so icat often returns an empty file. That's when you switch to carving.

File carving with PhotoRec

Every file type starts with a recognisable signature, called its magic bytes:

File typeMagic bytes (hex)
JPEGFF D8 FF
PNG89 50 4E 47
PDF25 50 44 46 (%PDF)
ZIP, DOCX, XLSX50 4B 03 04 (PK)

PhotoRec scans the whole image for these signatures and rebuilds whatever it finds:

photorec case01.img

Choose the partition, use [File Opt] to pick file types, choose an output folder and let it run. You can check any file's signature yourself with xxd file.jpg | head -1.

Carved files lose their original names and folders, so you'll get names like f0012345.jpg. That's normal. Sort them by type and check what's inside.

Autopsy: the GUI way

Autopsy is a free graphical front-end for The Sleuth Kit, used by police and corporate investigators. Load your image as a case and it automatically:

  • lists deleted files
  • carves unallocated space
  • extracts web history, photo EXIF data and recent documents
  • builds a timeline and a keyword search index

Autopsy 4 runs best on Windows. On Kali, the autopsy command starts the older browser-based version at http://localhost:9999/autopsy.

Record this for every recovered file

  • Original path and inode or MFT number
  • Recovery method (TSK or carving)
  • SHA-256 hash of the recovered file
  • Why it matters to the case

Deleted doesn't mean gone, but it does mean you need to prove exactly how you got it back.

Try it yourself
  1. Create a FAT practice USB: dd if=/dev/zero of=usb.img bs=1M count=50 and then mkfs.vfat usb.img
  2. Mount it with sudo mount -o loop usb.img mnt, copy in a JPEG and a text file, delete both, then run sudo umount mnt
  3. Run fls -r -d usb.img and note the inode numbers of your deleted files.
  4. Recover the text file with icat usb.img <inode> > recovered.txt and check it with cat recovered.txt
  5. Run photorec usb.img, carve the JPEG and confirm it opens.
No Linux machine? Practise in the free online terminal

Quick check

Which technique recovers files by scanning raw bytes for file signatures, ignoring the file system?

Need a hint?

PhotoRec does it. Think of a sculptor.

Finished this lesson?

Done lessons keep your daily streak going 🔥

0 day streak

0 lessons done

best 0 days

Log in to keep your streak on every device →