Deleted File Recovery
Recover deleted files from disk images and filesystems in CTF forensics challenges.
Deleted File Recovery
When a file is deleted, the data doesn't disappear. The filesystem marks the space as available, but the actual bytes remain on disk until they're overwritten. Recovery tools scan for these orphaned bytes and reconstruct the files.
In CTF challenges, the disk image is a forensic snapshot — nothing gets overwritten, so recovery almost always works.
How Deletion Works
| Filesystem | What Happens on Delete |
|---|---|
| ext4 | Inode unlinked, data blocks freed but not zeroed |
| NTFS | MFT entry marked unused, data may persist |
| FAT32 | Directory entry first byte set to 0xE5, clusters freed |
The data is recoverable until the disk space is reused by new files.
Recovery Workflow
Recovery Steps
Quick automated recovery with PhotoRec
sudo apt install testdisk
photorec disk.img
# Interactive: select disk → partition → filesystem → output dir → startOutput goes into numbered subdirectories — check for .txt, .pdf, .jpg with flags.
List deleted files with Sleuth Kit
sudo apt install sleuthkit
fls -rd disk.img | grep "deleted"
# Output: d/d * 45: secretfile.txt (asterisk = deleted)Recover file by inode
icat disk.img 45 > recovered_secretfile.txt
cat recovered_secretfile.txtSearch unallocated space
blkls disk.img > unallocated.bin
strings unallocated.bin | grep -i "flag{"
grep -a "flag{" unallocated.binTool Guide
Most comprehensive free file recovery — works on any filesystem:
sudo apt install testdisk # photorec included
photorec disk.img
# 1. Select disk (disk.img)
# 2. Select partition / whole disk
# 3. Choose filesystem type
# 4. Select output directory
# 5. Start recoveryRecovered files go into recup_dir.1/, recup_dir.2/, etc.
Special Cases
Checklist
-
photorec disk.img→ recover all files automatically -
testdisk→ recover partition tables and deleted files interactively -
fls -rd disk.img→ list deleted files with inodes -
icat disk.img <inode>→ recover specific deleted file -
strings disk.img | grep flag→ raw string search -
blkls + stringsfor unallocated space -
ntfsundeletefor Windows NTFS disk images -
debugfs+lsdelfor ext4 inode inspection - Check for deleted
.gitdirectories and SQLite databases
Last updated on