[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M755FVAFK2S0BPAZTE4ETB7H":3,"skill-same:01M755FVAFK2S0BPAZTE4ETB7H":72},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":20,"linkOnly":21,"markdownContent":22,"markdownBody":23,"frontMatter":24,"refName":36,"commitSha":37,"skillDirectory":5,"forksCount":14,"repositoryHtmlUrl":38,"repositoryHomepageUrl":6,"ownerHtmlUrl":39,"ownerBlogUrl":40,"ownerDescription":6,"updatedAt":41,"install":42,"resources":55},"01M755FVAFK2S0BPAZTE4ETB7H","performing-file-carving-with-foremost",null,"Recover files from disk images and unallocated space using Foremost's header-footer signature carving to extract evidence regardless of file system state.","SamuelChien\u002Fmega-skills-collection","SamuelChien","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F4652114?v=4","01M74KK34WVHA0P5ZYSJRDDFMG","Samuel Chien","01M74KK35FQN1N9VZ9EPTH3P2S",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fperforming-file-carving-with-foremost\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fperforming-file-carving-with-foremost\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: performing-file-carving-with-foremost\ndescription: Recover files from disk images and unallocated space using Foremost's header-footer signature carving to extract evidence regardless of file system state.\ndomain: cybersecurity\nsubdomain: digital-forensics\ntags: [forensics, file-carving, foremost, data-recovery, evidence-recovery, unallocated-space]\nversion: \"1.0\"\nauthor: mahipal\nlicense: Apache-2.0\n---\n\n# Performing File Carving with Foremost\n\n## When to Use\n- When recovering files from unallocated disk space or corrupted file systems\n- For extracting evidence from formatted or wiped storage media\n- When file system metadata is unavailable but raw data sectors contain evidence\n- During investigations requiring recovery of specific file types from raw images\n- As a complement to file system-based recovery for maximum evidence extraction\n\n## Prerequisites\n- Foremost installed on forensic workstation\n- Forensic disk image in raw (dd) format\n- Sufficient output storage (potentially larger than source)\n- Custom foremost.conf for specialized file types (optional)\n- Understanding of file signatures (magic bytes) for target file types\n- Scalpel as an alternative for performance-critical carving\n\n## Workflow\n\n### Step 1: Install and Configure Foremost\n\n```bash\n# Install Foremost\nsudo apt-get install foremost\n\n# Verify installation\nforemost -V\n\n# Review default configuration\ncat \u002Fetc\u002Fforemost.conf\n\n# The default foremost.conf supports:\n# jpg, gif, png, bmp - Image formats\n# avi, exe, mpg, wav - Media and executables\n# riff, wmv, mov, pdf - Documents and video\n# ole (doc\u002Fxls\u002Fppt), zip, rar - Office and archives\n# htm, cpp, java - Text\u002Fcode files\n\n# Create custom configuration for additional file types\ncp \u002Fetc\u002Fforemost.conf \u002Fcases\u002Fcase-2024-001\u002Fcustom_foremost.conf\n\n# Add custom file signatures\ncat \u003C\u003C 'EOF' >> \u002Fcases\u002Fcase-2024-001\u002Fcustom_foremost.conf\n# Custom additions for investigation\n# Format: extension  case_sensitive  max_size  header  footer\n    docx    y    10000000    \\x50\\x4b\\x03\\x04    \\x50\\x4b\\x05\\x06\n    xlsx    y    10000000    \\x50\\x4b\\x03\\x04    \\x50\\x4b\\x05\\x06\n    pptx    y    10000000    \\x50\\x4b\\x03\\x04    \\x50\\x4b\\x05\\x06\n    sqlite  y    50000000    \\x53\\x51\\x4c\\x69\\x74\\x65\\x20\\x66\\x6f\\x72\\x6d\\x61\\x74\n    pst     y    500000000   \\x21\\x42\\x44\\x4e\n    eml     y    1000000     \\x46\\x72\\x6f\\x6d\\x3a    \\x0d\\x0a\\x0d\\x0a\n    evtx    y    50000000    \\x45\\x6c\\x66\\x46\\x69\\x6c\\x65\nEOF\n```\n\n### Step 2: Run Foremost Against the Disk Image\n\n```bash\n# Basic carving of all supported file types\nforemost -t all \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002F\n\n# Carve only specific file types\nforemost -t jpg,png,pdf,doc,xls,zip \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_targeted\u002F\n\n# Use custom configuration\nforemost -c \u002Fcases\u002Fcase-2024-001\u002Fcustom_foremost.conf \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_custom\u002F\n\n# Carve from a specific partition offset\n# First, find partitions\nmmls \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd\n# Then carve from unallocated space only\n# Extract unallocated space with blkls\nblkls -o 2048 \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   > \u002Fcases\u002Fcase-2024-001\u002Funallocated.dd\n\nforemost -t all \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Funallocated.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_unalloc\u002F\n\n# Verbose mode for detailed progress\nforemost -v -t all \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_verbose\u002F 2>&1 | \\\n   tee \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_log.txt\n\n# Indirect mode (process standard input)\ndd if=\u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd bs=512 skip=2048 | \\\n   foremost -t jpg,pdf -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_pipe\u002F\n```\n\n### Step 3: Use Scalpel for High-Performance Carving\n\n```bash\n# Install Scalpel (faster alternative based on Foremost)\nsudo apt-get install scalpel\n\n# Edit Scalpel configuration (uncomment desired file types)\ncp \u002Fetc\u002Fscalpel\u002Fscalpel.conf \u002Fcases\u002Fcase-2024-001\u002Fscalpel.conf\n# Uncomment lines for target file types in the config\n\n# Run Scalpel\nscalpel -c \u002Fcases\u002Fcase-2024-001\u002Fscalpel.conf \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fscalpel\u002F \\\n   \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd\n\n# Scalpel with file size limits\n# Edit scalpel.conf to set appropriate max sizes:\n# jpg  y  5000000  \\xff\\xd8\\xff  \\xff\\xd9\n# pdf  y  20000000 %PDF  %%EOF\n```\n\n### Step 4: Process and Validate Carved Files\n\n```bash\n# Review Foremost audit report\ncat \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Faudit.txt\n\n# The audit.txt contains:\n# - Number of files found per type\n# - Start and end offsets\n# - File sizes\n\n# Validate carved files\npython3 \u003C\u003C 'PYEOF'\nimport os\nimport subprocess\nfrom collections import defaultdict\n\ncarved_dir = '\u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002F'\nstats = defaultdict(lambda: {'total': 0, 'valid': 0, 'invalid': 0, 'size': 0})\n\nfor subdir in os.listdir(carved_dir):\n    subdir_path = os.path.join(carved_dir, subdir)\n    if not os.path.isdir(subdir_path) or subdir == 'audit.txt':\n        continue\n\n    for filename in os.listdir(subdir_path):\n        filepath = os.path.join(subdir_path, filename)\n        if not os.path.isfile(filepath):\n            continue\n\n        ext = subdir\n        filesize = os.path.getsize(filepath)\n        stats[ext]['total'] += 1\n        stats[ext]['size'] += filesize\n\n        # Validate file using 'file' command\n        result = subprocess.run(['file', '--brief', filepath], capture_output=True, text=True)\n        file_type = result.stdout.strip()\n\n        if 'data' in file_type.lower() or 'empty' in file_type.lower():\n            stats[ext]['invalid'] += 1\n        else:\n            stats[ext]['valid'] += 1\n\nprint(\"=== CARVED FILE VALIDATION ===\\n\")\nprint(f\"{'Type':\u003C10} {'Total':\u003C8} {'Valid':\u003C8} {'Invalid':\u003C10} {'Total Size':\u003C15}\")\nprint(\"-\" * 55)\nfor ext in sorted(stats.keys()):\n    s = stats[ext]\n    size_mb = s['size'] \u002F (1024*1024)\n    print(f\"{ext:\u003C10} {s['total']:\u003C8} {s['valid']:\u003C8} {s['invalid']:\u003C10} {size_mb:>10.1f} MB\")\n\n# Remove zero-byte files\nfor subdir in os.listdir(carved_dir):\n    subdir_path = os.path.join(carved_dir, subdir)\n    if os.path.isdir(subdir_path):\n        for filename in os.listdir(subdir_path):\n            filepath = os.path.join(subdir_path, filename)\n            if os.path.isfile(filepath) and os.path.getsize(filepath) == 0:\n                os.remove(filepath)\nPYEOF\n\n# Hash all valid carved files\nfind \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002F -type f ! -name \"audit.txt\" \\\n   -exec sha256sum {} \\; > \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fcarved_file_hashes.txt\n\n# Check against known-bad hash database\n# Check against NSRL known-good database to filter\n```\n\n### Step 5: Examine and Catalog Evidence Files\n\n```bash\n# Extract metadata from carved images (EXIF data including GPS)\nexiftool -r -csv \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Fjpg\u002F \\\n   > \u002Fcases\u002Fcase-2024-001\u002Fanalysis\u002Fcarved_image_metadata.csv\n\n# Search carved documents for keywords\nfind \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Fpdf\u002F -name \"*.pdf\" -exec pdftotext {} - \\; 2>\u002Fdev\u002Fnull | \\\n   grep -iE '(confidential|secret|password|account|ssn|credit.card)' \\\n   > \u002Fcases\u002Fcase-2024-001\u002Fanalysis\u002Fkeyword_hits_pdf.txt\n\n# Generate thumbnails for image review\nmkdir -p \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fthumbnails\u002F\nfind \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Fjpg\u002F -name \"*.jpg\" -exec \\\n   convert {} -thumbnail 200x200 \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fthumbnails\u002F{} \\; 2>\u002Fdev\u002Fnull\n\n# Create evidence catalog\npython3 \u003C\u003C 'PYEOF'\nimport os, hashlib, csv, subprocess\n\ncatalog = []\ncarved_dir = '\u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002F'\n\nfor subdir in sorted(os.listdir(carved_dir)):\n    subdir_path = os.path.join(carved_dir, subdir)\n    if not os.path.isdir(subdir_path):\n        continue\n    for filename in sorted(os.listdir(subdir_path)):\n        filepath = os.path.join(subdir_path, filename)\n        if not os.path.isfile(filepath):\n            continue\n        size = os.path.getsize(filepath)\n        sha256 = hashlib.sha256(open(filepath, 'rb').read()).hexdigest()\n        file_type = subprocess.run(['file', '--brief', filepath], capture_output=True, text=True).stdout.strip()\n\n        catalog.append({\n            'filename': filename,\n            'type': subdir,\n            'size': size,\n            'sha256': sha256,\n            'file_description': file_type[:100]\n        })\n\nwith open('\u002Fcases\u002Fcase-2024-001\u002Fanalysis\u002Fcarved_file_catalog.csv', 'w', newline='') as f:\n    writer = csv.DictWriter(f, fieldnames=['filename', 'type', 'size', 'sha256', 'file_description'])\n    writer.writeheader()\n    writer.writerows(catalog)\n\nprint(f\"Catalog created with {len(catalog)} files\")\nPYEOF\n```\n\n## Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| File carving | Recovering files by searching for known header\u002Ffooter byte sequences in raw data |\n| File signature | Unique byte pattern at the start (header) or end (footer) identifying a file type |\n| Unallocated space | Disk sectors not assigned to any file; primary target for carving |\n| Fragmentation | When file data is stored in non-contiguous sectors, complicating carving |\n| Header-footer carving | Extracting data between known file start and end signatures |\n| False positives | Carved data matching file signatures but containing corrupt or unrelated content |\n| Slack space | Unused bytes at the end of a file's last allocated cluster |\n| Sector alignment | Files typically start at sector boundaries, improving carving accuracy |\n\n## Tools & Systems\n\n| Tool | Purpose |\n|------|---------|\n| Foremost | Original header-footer file carving tool developed for US Air Force OSI |\n| Scalpel | High-performance file carver with configurable signatures |\n| PhotoRec | Signature-based file recovery supporting 300+ formats |\n| bulk_extractor | Extracts features (emails, URLs, credit cards) from raw data |\n| blkls | Sleuth Kit tool extracting unallocated space from disk images |\n| mmls | Partition table display for identifying carving targets |\n| ExifTool | Metadata extraction from carved image and document files |\n| hashdeep | Recursive hash computation for carved file cataloging |\n\n## Common Scenarios\n\n**Scenario 1: Recovering Deleted Evidence Documents**\nRun Foremost targeting doc, pdf, xlsx formats against the unallocated space extracted with blkls, validate carved documents, search content for case-relevant keywords, catalog and hash all recoverable documents, present as evidence.\n\n**Scenario 2: Image Recovery from Formatted Media**\nCarve JPEG, PNG, GIF, BMP from a formatted USB drive image, extract EXIF metadata including GPS coordinates and camera information, generate thumbnails for rapid visual review, identify evidence-relevant images, document recovery chain.\n\n**Scenario 3: Email Recovery from Damaged PST**\nUse custom foremost.conf with PST and EML signatures, carve email artifacts from damaged Outlook data file, attempt to open carved PST fragments in a viewer, extract individual EML messages, search for relevant communications.\n\n**Scenario 4: Database Recovery for Financial Investigation**\nConfigure Foremost to carve SQLite databases from unallocated space, recover application databases that were deleted, query recovered databases for financial records, cross-reference with known transaction data, document findings for prosecution.\n\n## Output Format\n\n```\nFile Carving Summary:\n  Tool: Foremost 1.5.7\n  Source: evidence.dd (500 GB)\n  Target: Unallocated space (234 GB)\n  Duration: 1h 45m\n\n  Files Carved:\n    jpg:    2,345 files (1.8 GB) - Valid: 2,100 \u002F Invalid: 245\n    png:      234 files (456 MB) - Valid: 210 \u002F Invalid: 24\n    pdf:      156 files (890 MB) - Valid: 134 \u002F Invalid: 22\n    doc:       89 files (234 MB) - Valid: 67 \u002F Invalid: 22\n    xls:       45 files (123 MB) - Valid: 38 \u002F Invalid: 7\n    zip:       67 files (567 MB) - Valid: 52 \u002F Invalid: 15\n    exe:       34 files (234 MB) - Valid: 30 \u002F Invalid: 4\n    sqlite:    12 files (89 MB)  - Valid: 10 \u002F Invalid: 2\n\n  Total Files: 2,982 (3.4 GB recovered)\n  Evidence-Relevant: 45 files flagged for review\n  Audit Log: \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Faudit.txt\n  File Catalog: \u002Fcases\u002Fcase-2024-001\u002Fanalysis\u002Fcarved_file_catalog.csv\n```\n","# Performing File Carving with Foremost\n\n## When to Use\n- When recovering files from unallocated disk space or corrupted file systems\n- For extracting evidence from formatted or wiped storage media\n- When file system metadata is unavailable but raw data sectors contain evidence\n- During investigations requiring recovery of specific file types from raw images\n- As a complement to file system-based recovery for maximum evidence extraction\n\n## Prerequisites\n- Foremost installed on forensic workstation\n- Forensic disk image in raw (dd) format\n- Sufficient output storage (potentially larger than source)\n- Custom foremost.conf for specialized file types (optional)\n- Understanding of file signatures (magic bytes) for target file types\n- Scalpel as an alternative for performance-critical carving\n\n## Workflow\n\n### Step 1: Install and Configure Foremost\n\n```bash\n# Install Foremost\nsudo apt-get install foremost\n\n# Verify installation\nforemost -V\n\n# Review default configuration\ncat \u002Fetc\u002Fforemost.conf\n\n# The default foremost.conf supports:\n# jpg, gif, png, bmp - Image formats\n# avi, exe, mpg, wav - Media and executables\n# riff, wmv, mov, pdf - Documents and video\n# ole (doc\u002Fxls\u002Fppt), zip, rar - Office and archives\n# htm, cpp, java - Text\u002Fcode files\n\n# Create custom configuration for additional file types\ncp \u002Fetc\u002Fforemost.conf \u002Fcases\u002Fcase-2024-001\u002Fcustom_foremost.conf\n\n# Add custom file signatures\ncat \u003C\u003C 'EOF' >> \u002Fcases\u002Fcase-2024-001\u002Fcustom_foremost.conf\n# Custom additions for investigation\n# Format: extension  case_sensitive  max_size  header  footer\n    docx    y    10000000    \\x50\\x4b\\x03\\x04    \\x50\\x4b\\x05\\x06\n    xlsx    y    10000000    \\x50\\x4b\\x03\\x04    \\x50\\x4b\\x05\\x06\n    pptx    y    10000000    \\x50\\x4b\\x03\\x04    \\x50\\x4b\\x05\\x06\n    sqlite  y    50000000    \\x53\\x51\\x4c\\x69\\x74\\x65\\x20\\x66\\x6f\\x72\\x6d\\x61\\x74\n    pst     y    500000000   \\x21\\x42\\x44\\x4e\n    eml     y    1000000     \\x46\\x72\\x6f\\x6d\\x3a    \\x0d\\x0a\\x0d\\x0a\n    evtx    y    50000000    \\x45\\x6c\\x66\\x46\\x69\\x6c\\x65\nEOF\n```\n\n### Step 2: Run Foremost Against the Disk Image\n\n```bash\n# Basic carving of all supported file types\nforemost -t all \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002F\n\n# Carve only specific file types\nforemost -t jpg,png,pdf,doc,xls,zip \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_targeted\u002F\n\n# Use custom configuration\nforemost -c \u002Fcases\u002Fcase-2024-001\u002Fcustom_foremost.conf \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_custom\u002F\n\n# Carve from a specific partition offset\n# First, find partitions\nmmls \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd\n# Then carve from unallocated space only\n# Extract unallocated space with blkls\nblkls -o 2048 \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   > \u002Fcases\u002Fcase-2024-001\u002Funallocated.dd\n\nforemost -t all \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Funallocated.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_unalloc\u002F\n\n# Verbose mode for detailed progress\nforemost -v -t all \\\n   -i \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_verbose\u002F 2>&1 | \\\n   tee \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_log.txt\n\n# Indirect mode (process standard input)\ndd if=\u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd bs=512 skip=2048 | \\\n   foremost -t jpg,pdf -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_pipe\u002F\n```\n\n### Step 3: Use Scalpel for High-Performance Carving\n\n```bash\n# Install Scalpel (faster alternative based on Foremost)\nsudo apt-get install scalpel\n\n# Edit Scalpel configuration (uncomment desired file types)\ncp \u002Fetc\u002Fscalpel\u002Fscalpel.conf \u002Fcases\u002Fcase-2024-001\u002Fscalpel.conf\n# Uncomment lines for target file types in the config\n\n# Run Scalpel\nscalpel -c \u002Fcases\u002Fcase-2024-001\u002Fscalpel.conf \\\n   -o \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fscalpel\u002F \\\n   \u002Fcases\u002Fcase-2024-001\u002Fimages\u002Fevidence.dd\n\n# Scalpel with file size limits\n# Edit scalpel.conf to set appropriate max sizes:\n# jpg  y  5000000  \\xff\\xd8\\xff  \\xff\\xd9\n# pdf  y  20000000 %PDF  %%EOF\n```\n\n### Step 4: Process and Validate Carved Files\n\n```bash\n# Review Foremost audit report\ncat \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Faudit.txt\n\n# The audit.txt contains:\n# - Number of files found per type\n# - Start and end offsets\n# - File sizes\n\n# Validate carved files\npython3 \u003C\u003C 'PYEOF'\nimport os\nimport subprocess\nfrom collections import defaultdict\n\ncarved_dir = '\u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002F'\nstats = defaultdict(lambda: {'total': 0, 'valid': 0, 'invalid': 0, 'size': 0})\n\nfor subdir in os.listdir(carved_dir):\n    subdir_path = os.path.join(carved_dir, subdir)\n    if not os.path.isdir(subdir_path) or subdir == 'audit.txt':\n        continue\n\n    for filename in os.listdir(subdir_path):\n        filepath = os.path.join(subdir_path, filename)\n        if not os.path.isfile(filepath):\n            continue\n\n        ext = subdir\n        filesize = os.path.getsize(filepath)\n        stats[ext]['total'] += 1\n        stats[ext]['size'] += filesize\n\n        # Validate file using 'file' command\n        result = subprocess.run(['file', '--brief', filepath], capture_output=True, text=True)\n        file_type = result.stdout.strip()\n\n        if 'data' in file_type.lower() or 'empty' in file_type.lower():\n            stats[ext]['invalid'] += 1\n        else:\n            stats[ext]['valid'] += 1\n\nprint(\"=== CARVED FILE VALIDATION ===\\n\")\nprint(f\"{'Type':\u003C10} {'Total':\u003C8} {'Valid':\u003C8} {'Invalid':\u003C10} {'Total Size':\u003C15}\")\nprint(\"-\" * 55)\nfor ext in sorted(stats.keys()):\n    s = stats[ext]\n    size_mb = s['size'] \u002F (1024*1024)\n    print(f\"{ext:\u003C10} {s['total']:\u003C8} {s['valid']:\u003C8} {s['invalid']:\u003C10} {size_mb:>10.1f} MB\")\n\n# Remove zero-byte files\nfor subdir in os.listdir(carved_dir):\n    subdir_path = os.path.join(carved_dir, subdir)\n    if os.path.isdir(subdir_path):\n        for filename in os.listdir(subdir_path):\n            filepath = os.path.join(subdir_path, filename)\n            if os.path.isfile(filepath) and os.path.getsize(filepath) == 0:\n                os.remove(filepath)\nPYEOF\n\n# Hash all valid carved files\nfind \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002F -type f ! -name \"audit.txt\" \\\n   -exec sha256sum {} \\; > \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fcarved_file_hashes.txt\n\n# Check against known-bad hash database\n# Check against NSRL known-good database to filter\n```\n\n### Step 5: Examine and Catalog Evidence Files\n\n```bash\n# Extract metadata from carved images (EXIF data including GPS)\nexiftool -r -csv \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Fjpg\u002F \\\n   > \u002Fcases\u002Fcase-2024-001\u002Fanalysis\u002Fcarved_image_metadata.csv\n\n# Search carved documents for keywords\nfind \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Fpdf\u002F -name \"*.pdf\" -exec pdftotext {} - \\; 2>\u002Fdev\u002Fnull | \\\n   grep -iE '(confidential|secret|password|account|ssn|credit.card)' \\\n   > \u002Fcases\u002Fcase-2024-001\u002Fanalysis\u002Fkeyword_hits_pdf.txt\n\n# Generate thumbnails for image review\nmkdir -p \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fthumbnails\u002F\nfind \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Fjpg\u002F -name \"*.jpg\" -exec \\\n   convert {} -thumbnail 200x200 \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fthumbnails\u002F{} \\; 2>\u002Fdev\u002Fnull\n\n# Create evidence catalog\npython3 \u003C\u003C 'PYEOF'\nimport os, hashlib, csv, subprocess\n\ncatalog = []\ncarved_dir = '\u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002F'\n\nfor subdir in sorted(os.listdir(carved_dir)):\n    subdir_path = os.path.join(carved_dir, subdir)\n    if not os.path.isdir(subdir_path):\n        continue\n    for filename in sorted(os.listdir(subdir_path)):\n        filepath = os.path.join(subdir_path, filename)\n        if not os.path.isfile(filepath):\n            continue\n        size = os.path.getsize(filepath)\n        sha256 = hashlib.sha256(open(filepath, 'rb').read()).hexdigest()\n        file_type = subprocess.run(['file', '--brief', filepath], capture_output=True, text=True).stdout.strip()\n\n        catalog.append({\n            'filename': filename,\n            'type': subdir,\n            'size': size,\n            'sha256': sha256,\n            'file_description': file_type[:100]\n        })\n\nwith open('\u002Fcases\u002Fcase-2024-001\u002Fanalysis\u002Fcarved_file_catalog.csv', 'w', newline='') as f:\n    writer = csv.DictWriter(f, fieldnames=['filename', 'type', 'size', 'sha256', 'file_description'])\n    writer.writeheader()\n    writer.writerows(catalog)\n\nprint(f\"Catalog created with {len(catalog)} files\")\nPYEOF\n```\n\n## Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| File carving | Recovering files by searching for known header\u002Ffooter byte sequences in raw data |\n| File signature | Unique byte pattern at the start (header) or end (footer) identifying a file type |\n| Unallocated space | Disk sectors not assigned to any file; primary target for carving |\n| Fragmentation | When file data is stored in non-contiguous sectors, complicating carving |\n| Header-footer carving | Extracting data between known file start and end signatures |\n| False positives | Carved data matching file signatures but containing corrupt or unrelated content |\n| Slack space | Unused bytes at the end of a file's last allocated cluster |\n| Sector alignment | Files typically start at sector boundaries, improving carving accuracy |\n\n## Tools & Systems\n\n| Tool | Purpose |\n|------|---------|\n| Foremost | Original header-footer file carving tool developed for US Air Force OSI |\n| Scalpel | High-performance file carver with configurable signatures |\n| PhotoRec | Signature-based file recovery supporting 300+ formats |\n| bulk_extractor | Extracts features (emails, URLs, credit cards) from raw data |\n| blkls | Sleuth Kit tool extracting unallocated space from disk images |\n| mmls | Partition table display for identifying carving targets |\n| ExifTool | Metadata extraction from carved image and document files |\n| hashdeep | Recursive hash computation for carved file cataloging |\n\n## Common Scenarios\n\n**Scenario 1: Recovering Deleted Evidence Documents**\nRun Foremost targeting doc, pdf, xlsx formats against the unallocated space extracted with blkls, validate carved documents, search content for case-relevant keywords, catalog and hash all recoverable documents, present as evidence.\n\n**Scenario 2: Image Recovery from Formatted Media**\nCarve JPEG, PNG, GIF, BMP from a formatted USB drive image, extract EXIF metadata including GPS coordinates and camera information, generate thumbnails for rapid visual review, identify evidence-relevant images, document recovery chain.\n\n**Scenario 3: Email Recovery from Damaged PST**\nUse custom foremost.conf with PST and EML signatures, carve email artifacts from damaged Outlook data file, attempt to open carved PST fragments in a viewer, extract individual EML messages, search for relevant communications.\n\n**Scenario 4: Database Recovery for Financial Investigation**\nConfigure Foremost to carve SQLite databases from unallocated space, recover application databases that were deleted, query recovered databases for financial records, cross-reference with known transaction data, document findings for prosecution.\n\n## Output Format\n\n```\nFile Carving Summary:\n  Tool: Foremost 1.5.7\n  Source: evidence.dd (500 GB)\n  Target: Unallocated space (234 GB)\n  Duration: 1h 45m\n\n  Files Carved:\n    jpg:    2,345 files (1.8 GB) - Valid: 2,100 \u002F Invalid: 245\n    png:      234 files (456 MB) - Valid: 210 \u002F Invalid: 24\n    pdf:      156 files (890 MB) - Valid: 134 \u002F Invalid: 22\n    doc:       89 files (234 MB) - Valid: 67 \u002F Invalid: 22\n    xls:       45 files (123 MB) - Valid: 38 \u002F Invalid: 7\n    zip:       67 files (567 MB) - Valid: 52 \u002F Invalid: 15\n    exe:       34 files (234 MB) - Valid: 30 \u002F Invalid: 4\n    sqlite:    12 files (89 MB)  - Valid: 10 \u002F Invalid: 2\n\n  Total Files: 2,982 (3.4 GB recovered)\n  Evidence-Relevant: 45 files flagged for review\n  Audit Log: \u002Fcases\u002Fcase-2024-001\u002Fcarved\u002Fforemost_all\u002Faudit.txt\n  File Catalog: \u002Fcases\u002Fcase-2024-001\u002Fanalysis\u002Fcarved_file_catalog.csv\n```\n",{"name":5,"tags":25,"author":32,"domain":33,"license":15,"version":34,"subdomain":35,"description":7},[26,27,28,29,30,31],"forensics","file-carving","foremost","data-recovery","evidence-recovery","unallocated-space","mahipal","cybersecurity","1.0","digital-forensics","main","c2b1fdccc779e99ac814e55fb69ca8d71215dd0f","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection","https:\u002F\u002Fgithub.com\u002FSamuelChien","http:\u002F\u002Fsamuelchien.com\u002F","2026-05-26 08:27:14",{"source":8,"skillName":5,"commands":43,"prompt":53,"zipAvailable":54},[44,47,50],{"tool":45,"command":46},"npx","npx skills add SamuelChien\u002Fmega-skills-collection --skill performing-file-carving-with-foremost",{"tool":48,"command":49},"bunx","bunx skills add SamuelChien\u002Fmega-skills-collection --skill performing-file-carving-with-foremost",{"tool":51,"command":52},"pnpm","pnpm dlx skills add SamuelChien\u002Fmega-skills-collection --skill performing-file-carving-with-foremost","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fperforming-file-carving-with-foremost\u002FSKILL.md",true,[56,60,66],{"path":57,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":59,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":61,"resourceType":62,"resourceTypeDesc":63,"sizeBytes":64,"sourceHtmlUrl":65},"references\u002Fapi-reference.md","REFERENCE","参考文档",1537,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fperforming-file-carving-with-foremost\u002Freferences\u002Fapi-reference.md",{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},"scripts\u002Fagent.py","SCRIPT","脚本",6954,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fperforming-file-carving-with-foremost\u002Fscripts\u002Fagent.py",[73,81,88,95,102,109],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":20},"01M76R4WZQZAXGGXMQCA0FZ716","zustand-store-ts","Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state\u002Faction separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.","MIT","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-ts\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":20},"01M76R4T9KENDH7FENGZQHBW4G","zustand-store-creator","Zustand Store Creator - Auto-activating skill for Frontend Development.\nTriggers on: zustand store creator, zustand store creator\nPart of the Frontend Development skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-creator\u002FSKILL.md",[],[],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":20},"01M76R3YWN84B7SANJ52X799ZE","zero-trust-config-helper","Zero Trust Config Helper - Auto-activating skill for Security Advanced.\nTriggers on: zero trust config helper, zero trust config helper\nPart of the Security Advanced skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzero-trust-config-helper\u002FSKILL.md",[],[],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":20},"01M76R3HNSV2AEYSKHM915GJ58","zapier-integration-helper","Zapier Integration Helper - Auto-activating skill for Business Automation.\nTriggers on: zapier integration helper, zapier integration helper\nPart of the Business Automation skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzapier-integration-helper\u002FSKILL.md",[],[],{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":20},"01M76R3DJSKAT4FA7DV4BF3GCE","zai-cli","Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP.\nUse when user needs image\u002Fvideo analysis, OCR, UI-to-code conversion, error diagnosis,\nreal-time web search, web page to markdown extraction, or GitHub code exploration.\nTrigger with phrases like \"analyze this image\", \"search the web for\", \"read this page\",\n\"explore this repo\", or \"use zai\". Requires Z_AI_API_KEY.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzai-cli\u002FSKILL.md",[],[],{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":20},"01M76R2KAM699XE9AJVAWE4H2E","yt-research","Research competitor YouTube channels, niches, and trending topics for your content strategy.\nUse this skill whenever the user says \"research channels\", \"analyze competitors\", \"find trending topics\",\n\"niche analysis\", \"competitive research\", \"what are other creators doing\", \"scrape YouTube channels\",\nor wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fyt-research\u002FSKILL.md",[],[]]