Skip to content

edruela/invweb.diskRecovery

Repository files navigation

invweb.diskRecovery

License: MIT

Python helper to recover deleted files from USB drives and SD cards (including formatted partitions) using Foremost - a professional forensic file carving tool.

🚀 Battle-tested: Successfully recovered 100% of photos from a camera-formatted SD card where photorec only recovered ~10%.

Why Foremost?

After extensive testing, Foremost proved far superior to photorec:

  • ✅ Recovered 100% of files from camera-formatted drives
  • ✅ More aggressive file signature detection
  • ✅ Better handling of fragmented files
  • ✅ Used by law enforcement for digital forensics
  • ✅ Cleaner output organization (files sorted by type)

Requirements

  • Linux
  • Python 3.8+
  • foremost installed (sudo apt install foremost)
  • Root permissions (recommended for raw device access)

Quick Start

Simple Recovery (Interactive)

sudo ./run.sh

Automatically lists devices, prompts for selection, and recovers files.

Advanced Forensic Recovery (Recommended for Maximum Recovery)

For stubborn cases (camera-formatted cards, maximum recovery attempts):

sudo ./forensic_recovery.sh /dev/sdX

This runs 3 professional forensic tools in parallel:

  • Foremost - Law enforcement file carving tool
  • Scalpel - Aggressive header/footer matching
  • Sleuth Kit - Filesystem metadata analysis

Each tool uses different algorithms and may recover different files.

Usage

Interactive Mode (Recommended)

Simply run the script without arguments:

sudo ./run.sh

The tool will:

  1. List available removable devices (USB drives, SD cards)
  2. Prompt you to select a device
  3. Suggest an output directory with today's date
  4. Launch foremost to recover all files
  5. Automatically fix file permissions so you can access them without sudo

Direct Mode (Scripting/Automation)

Provide device and output path as arguments:

sudo ./run.sh --device /dev/sdb --output ~/recovered_files

This mode is useful for scripts or when you already know the device path.

What the Script Does

The script:

  • Verifies the output folder is local and not on the pendrive
  • Asks for confirmation before any recovery action
  • Launches foremost in unattended mode
  • Automatically carves files using forensic algorithms
  • Organizes recovered files by type (jpg/, png/, pdf/, etc.)

Why Foremost works better:

  • Camera-formatted drives: Foremost recovers 100%, photorec only ~10%
  • More aggressive byte-pattern matching
  • Better fragmented file handling
  • Professional forensic-grade tool

Automatic Permission Fix

When run with sudo, the tool automatically:

  • Detects your original user (not root)
  • Changes ownership of recovered files to your user
  • Sets readable permissions (0644)
  • No manual chown needed!

If you have existing recovered files owned by root, use:

./fix_permissions.sh

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License - see LICENSE file for details.

Acknowledgments

  • Foremost - Professional forensic tool by Jesse Kornblum
  • Scalpel - File carving by Golden G. Richard III
  • The Sleuth Kit - Digital investigation framework by Brian Carrier

Support

If this tool helped you recover important data, consider:

  • ⭐ Starring the repository
  • 📝 Sharing your success story in issues/discussions
  • 🤝 Contributing improvements

Disclaimer: This tool is provided as-is. Always test on non-critical data first. Data recovery success depends on many factors including how the data was deleted and whether it has been overwritten.