[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7E5PMENAXN5WJNAXAXKN8VA":3,"skill-same:01M7E5PMENAXN5WJNAXAXKN8VA":84},{"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":46,"commitSha":47,"skillDirectory":48,"forksCount":49,"repositoryHtmlUrl":50,"repositoryHomepageUrl":6,"ownerHtmlUrl":51,"ownerBlogUrl":6,"ownerDescription":52,"updatedAt":53,"install":54,"resources":67},"01M7E5PMENAXN5WJNAXAXKN8VA","performing-file-carving-with-foremost",null,"Recovers files from disk images and unallocated space using Foremost's header-footer signature carving, extracting evidence independent of the file system's state. Use during digital forensics investigations to carve deleted or fragmented files, such as documents, images, and archives, from raw disk images or unallocated space.","sanjeevafk\u002Fagent-skills","sanjeevafk","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F230678117?v=4","01M7C540EFY46ETG1NNWKS5X3Q","Sanjeev","01M7C540F366J5C1D587BMKH9Q",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fperforming-file-carving-with-foremost\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fperforming-file-carving-with-foremost\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: performing-file-carving-with-foremost\ndescription: Recovers files from disk images and unallocated space using Foremost's\n  header-footer signature carving, extracting evidence independent of the file system's\n  state. Use during digital forensics investigations to carve deleted or fragmented\n  files, such as documents, images, and archives, from raw disk images or unallocated\n  space.\ndomain: cybersecurity\nsubdomain: digital-forensics\ntags:\n- forensics\n- file-carving\n- foremost\n- data-recovery\n- evidence-recovery\n- unallocated-space\nversion: '1.0'\nauthor: mahipal\nlicense: Apache-2.0\nnist_csf:\n- RS.AN-03\n- DE.AE-02\n- RS.MA-01\nmitre_attack:\n- T1005\n- T1074\n- T1119\n- T1070\n- T1059\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,"nist_csf":35,"subdomain":39,"description":7,"mitre_attack":40},[26,27,28,29,30,31],"forensics","file-carving","foremost","data-recovery","evidence-recovery","unallocated-space","mahipal","cybersecurity","1.0",[36,37,38],"RS.AN-03","DE.AE-02","RS.MA-01","digital-forensics",[41,42,43,44,45],"T1005","T1074","T1119","T1070","T1059","main","4e084e84eb42fc53e144c89c0f7f48b39c8a4b0f","collections\u002Fcybersecurity-skills\u002Fskills\u002Fperforming-file-carving-with-foremost",1,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills","https:\u002F\u002Fgithub.com\u002Fsanjeevafk","First make it work. Then make it right. Then make it fast.","2026-11-14 13:36:16",{"source":8,"skillName":5,"commands":55,"prompt":65,"zipAvailable":66},[56,59,62],{"tool":57,"command":58},"npx","npx skills add sanjeevafk\u002Fagent-skills --skill performing-file-carving-with-foremost",{"tool":60,"command":61},"bunx","bunx skills add sanjeevafk\u002Fagent-skills --skill performing-file-carving-with-foremost",{"tool":63,"command":64},"pnpm","pnpm dlx skills add sanjeevafk\u002Fagent-skills --skill performing-file-carving-with-foremost","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fperforming-file-carving-with-foremost\u002FSKILL.md",true,[68,72,78],{"path":69,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":71,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":73,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":76,"sourceHtmlUrl":77},"references\u002Fapi-reference.md","REFERENCE","参考文档",1537,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fperforming-file-carving-with-foremost\u002Freferences\u002Fapi-reference.md",{"path":79,"resourceType":80,"resourceTypeDesc":81,"sizeBytes":82,"sourceHtmlUrl":83},"scripts\u002Fagent.py","SCRIPT","脚本",6954,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fperforming-file-carving-with-foremost\u002Fscripts\u002Fagent.py",[85,93,101,109,117,124],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":20},"01M7EFHX67M3KKXT1BXVPA5ADT","zarr-python","Chunked N-D arrays for cloud storage (Zarr-Python 3). Compressed arrays, parallel I\u002FO, S3\u002FGCS via fsspec, NumPy\u002FDask\u002FXarray compatible, for large-scale scientific computing pipelines.","MIT","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":97,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":20},"01M7EFFQGM51TZBGRENXY50ZYM","whiteboard-diagrams","Create accurate, simple, hand-drawn whiteboard diagrams from a user's process, system, architecture, learning workflow, comparison, or causal explanation. Use when the user asks for a scribbly whiteboard visual, educational workflow graphic, hand-drawn explainer, or diagram like the bundled reference; ask one focused clarification question when the subject or relationships are missing, then generate and visually verify the final image.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwhiteboard-diagrams\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwhiteboard-diagrams\u002FSKILL.md",[],[],{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":105,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":20},"01M7EFF1CSQNTDMHFK4ZGY6NYK","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwebapp-testing\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":15,"licenseFileUrl":113,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":20},"01M7EFE8106X6C28FT8PA74427","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fweb-artifacts-builder\u002FSKILL.md",[],[],{"skillNo":118,"name":119,"nameZh":6,"description":120,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":6,"sourceHtmlUrl":121,"categories":122,"keywords":123,"publishedAt":20},"01M7EFCSNZM9G7ZHS6F127Q71X","verification-loop","A comprehensive verification system for Claude Code sessions.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fverification-loop\u002FSKILL.md",[],[],{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":128,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":20},"01M7EFCE7EZMKPRYDDNKBQ9EEH","vercel-deploy","Deploy applications and websites to Vercel. Use when the user requests deployment actions like \"deploy my app\", \"deploy and give me the link\", \"push this live\", or \"create a preview deployment\".","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fvercel-deploy\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fvercel-deploy\u002FSKILL.md",[],[]]