# Agent Skill Package: acquiring-disk-image-with-dd-and-dcfldd You are loading a published Agent Skill. Follow SKILL.md exactly. Supporting files from the original zip are inlined below. When SKILL.md says to read `references/...` or `scripts/...`, use the matching FILE section here — do not say the file is missing. Canonical URL: https://skill.hk/s/acquiring-disk-image-with-dd-and-dcfldd.md Human page: https://skill.hk/s/acquiring-disk-image-with-dd-and-dcfldd Files (4): - SKILL.md - LICENSE - references/api-reference.md - scripts/agent.py ======================================================================== FILE: SKILL.md ======================================================================== --- name: acquiring-disk-image-with-dd-and-dcfldd description: Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis. domain: cybersecurity subdomain: digital-forensics tags: - forensics - disk-imaging - evidence-acquisition - dd - dcfldd - hash-verification version: '1.0' author: mahipal license: Apache-2.0 nist_csf: - RS.AN-03 - DE.AE-02 - RS.MA-01 mitre_attack: - T1006 - T1005 - T1025 - T1074.001 --- # Acquiring Disk Image with dd and dcfldd ## When to Use - When you need to create a forensic copy of a suspect drive for investigation - During incident response when preserving volatile disk evidence before analysis - When law enforcement or legal proceedings require a verified bit-for-bit copy - Before performing any destructive analysis on a storage device - When acquiring images from physical drives, USB devices, or memory cards ## Prerequisites - Linux-based forensic workstation (SIFT, Kali, or any Linux distro) - `dd` (pre-installed on all Linux systems) or `dcfldd` (enhanced forensic version) - Write-blocker hardware or software write-blocking configured - Destination drive with sufficient storage (larger than source) - Root/sudo privileges on the forensic workstation - SHA-256 or MD5 hashing utilities (`sha256sum`, `md5sum`) ## Workflow ### Step 1: Identify the Target Device and Enable Write Protection ```bash # List all connected block devices to identify the target lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,MODEL # Verify the device details fdisk -l /dev/sdb # Enable software write-blocking (if no hardware blocker) blockdev --setro /dev/sdb # Verify read-only status blockdev --getro /dev/sdb # Output: 1 (means read-only is enabled) # Alternatively, use udev rules for persistent write-blocking echo 'SUBSYSTEM=="block", ATTRS{serial}=="WD-WCAV5H861234", ATTR{ro}="1"' > /etc/udev/rules.d/99-writeblock.rules udevadm control --reload-rules ``` ### Step 2: Prepare the Destination and Document the Source ```bash # Create case directory structure mkdir -p /cases/case-2024-001/{images,hashes,logs,notes} # Document source drive information hdparm -I /dev/sdb > /cases/case-2024-001/notes/source_drive_info.txt # Record the serial number and model smartctl -i /dev/sdb >> /cases/case-2024-001/notes/source_drive_info.txt # Pre-hash the source device sha256sum /dev/sdb | tee /cases/case-2024-001/hashes/source_hash_before.txt ``` ### Step 3: Acquire the Image Using dd ```bash # Basic dd acquisition with progress and error handling dd if=/dev/sdb of=/cases/case-2024-001/images/evidence.dd \ bs=4096 \ conv=noerror,sync \ status=progress 2>&1 | tee /cases/case-2024-001/logs/dd_acquisition.log # For compressed images to save space dd if=/dev/sdb bs=4096 conv=noerror,sync status=progress | \ gzip -c > /cases/case-2024-001/images/evidence.dd.gz # Using dd with a specific count for partial acquisition dd if=/dev/sdb of=/cases/case-2024-001/images/first_1gb.dd \ bs=1M count=1024 status=progress ``` ### Step 4: Acquire Using dcfldd (Preferred Forensic Method) ```bash # Install dcfldd if not present apt-get install dcfldd # Acquire image with built-in hashing and split output dcfldd if=/dev/sdb \ of=/cases/case-2024-001/images/evidence.dd \ hash=sha256,md5 \ hashwindow=1G \ hashlog=/cases/case-2024-001/hashes/acquisition_hashes.txt \ bs=4096 \ conv=noerror,sync \ errlog=/cases/case-2024-001/logs/dcfldd_errors.log # Split large images into manageable segments dcfldd if=/dev/sdb \ of=/cases/case-2024-001/images/evidence.dd \ hash=sha256 \ hashlog=/cases/case-2024-001/hashes/split_hashes.txt \ bs=4096 \ split=2G \ splitformat=aa # Acquire with verification pass dcfldd if=/dev/sdb \ of=/cases/case-2024-001/images/evidence.dd \ hash=sha256 \ hashlog=/cases/case-2024-001/hashes/verification.txt \ vf=/cases/case-2024-001/images/evidence.dd \ verifylog=/cases/case-2024-001/logs/verify.log ``` ### Step 5: Verify Image Integrity ```bash # Hash the acquired image sha256sum /cases/case-2024-001/images/evidence.dd | \ tee /cases/case-2024-001/hashes/image_hash.txt # Compare source and image hashes diff <(sha256sum /dev/sdb | awk '{print $1}') \ <(sha256sum /cases/case-2024-001/images/evidence.dd | awk '{print $1}') # If using split images, verify each segment sha256sum /cases/case-2024-001/images/evidence.dd.* | \ tee /cases/case-2024-001/hashes/split_image_hashes.txt # Re-hash source to confirm no changes occurred sha256sum /dev/sdb | tee /cases/case-2024-001/hashes/source_hash_after.txt diff /cases/case-2024-001/hashes/source_hash_before.txt \ /cases/case-2024-001/hashes/source_hash_after.txt ``` ### Step 6: Document the Acquisition Process ```bash # Generate acquisition report cat << 'EOF' > /cases/case-2024-001/notes/acquisition_report.txt DISK IMAGE ACQUISITION REPORT ============================== Case Number: 2024-001 Date/Time: $(date -u +"%Y-%m-%d %H:%M:%S UTC") Examiner: [Name] Source Device: /dev/sdb Model: [from hdparm output] Serial: [from hdparm output] Size: [from fdisk output] Acquisition Tool: dcfldd v1.9.1 Block Size: 4096 Write Blocker: [Hardware/Software model] Image File: evidence.dd Image Hash (SHA-256): [from hash file] Source Hash (SHA-256): [from hash file] Hash Match: YES/NO Errors During Acquisition: [from error log] EOF # Compress logs for archival tar -czf /cases/case-2024-001/acquisition_package.tar.gz \ /cases/case-2024-001/hashes/ \ /cases/case-2024-001/logs/ \ /cases/case-2024-001/notes/ ``` ## Key Concepts | Concept | Description | |---------|-------------| | Bit-for-bit copy | Exact replica of source including unallocated space and slack space | | Write blocker | Hardware or software mechanism preventing writes to evidence media | | Hash verification | Cryptographic hash comparing source and image to prove integrity | | Block size (bs) | Transfer chunk size affecting speed; 4096 or 64K typical for forensics | | conv=noerror,sync | Continue on read errors and pad with zeros to maintain offset alignment | | Chain of custody | Documented trail proving evidence has not been tampered with | | Split imaging | Breaking large images into smaller files for storage and transport | | Raw/dd format | Bit-for-bit image format without metadata container overhead | ## Tools & Systems | Tool | Purpose | |------|---------| | dd | Standard Unix disk duplication utility for raw imaging | | dcfldd | DoD Computer Forensics Laboratory enhanced version of dd with hashing | | dc3dd | Another forensic dd variant from the DoD Cyber Crime Center | | sha256sum | SHA-256 hash calculation for integrity verification | | blockdev | Linux command to set block device read-only mode | | hdparm | Drive identification and parameter reporting | | smartctl | S.M.A.R.T. data retrieval for drive health and identification | | lsblk | Block device enumeration and identification | ## Common Scenarios **Scenario 1: Acquiring a Suspect Laptop Hard Drive** Connect the drive via a Tableau T35u hardware write-blocker, identify as `/dev/sdb`, use dcfldd with SHA-256 hashing, split into 4GB segments for DVD archival, verify hashes match, document in case notes. **Scenario 2: Imaging a USB Flash Drive from a Compromised Workstation** Use software write-blocking with `blockdev --setro`, acquire with dcfldd including MD5 and SHA-256 dual hashing, image is small enough for single file, verify and store on encrypted case drive. **Scenario 3: Remote Acquisition Over Network** Use dd piped through netcat or ssh for remote acquisition: `ssh root@remote "dd if=/dev/sda bs=4096" | dd of=remote_image.dd bs=4096`, hash both ends independently to verify transfer integrity. **Scenario 4: Acquiring from a Failing Drive** Use `ddrescue` first to recover readable sectors, then use dd with `conv=noerror,sync` to fill gaps with zeros, document which sectors were unreadable in the error log. ## Output Format ``` Acquisition Summary: Source: /dev/sdb (500GB Western Digital WD5000AAKX) Destination: /cases/case-2024-001/images/evidence.dd Tool: dcfldd 1.9.1 Block Size: 4096 bytes Duration: 2h 15m 32s Bytes Copied: 500,107,862,016 Errors: 0 bad sectors Source SHA-256: a3f2b8c9d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1 Image SHA-256: a3f2b8c9d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1 Verification: PASSED - Hashes match ``` ======================================================================== FILE: LICENSE ======================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to the Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by the Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding any notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. Please do not remove or change the license header comment from a contributed file except when necessary. Copyright 2026 mukul975 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ======================================================================== FILE: references/api-reference.md ======================================================================== # API Reference: dd and dcfldd Disk Imaging ## dd - Standard Unix Disk Duplication ### Basic Syntax ```bash dd if= of= [options] ``` ### Key Options | Flag | Description | Example | |------|-------------|---------| | `if=` | Input file (source device) | `if=/dev/sdb` | | `of=` | Output file (destination image) | `of=evidence.dd` | | `bs=` | Block size for read/write | `bs=4096` (forensic standard) | | `count=` | Number of blocks to copy | `count=1024` | | `skip=` | Skip N blocks from input start | `skip=2048` | | `conv=` | Conversion options | `conv=noerror,sync` | | `status=` | Transfer statistics level | `status=progress` | ### conv= Values - `noerror` - Continue on read errors (do not abort) - `sync` - Pad input blocks with zeros on error (preserves offset alignment) - `notrunc` - Do not truncate output file ### Output Format ``` 500107862016 bytes (500 GB, 466 GiB) copied, 8132.45 s, 61.5 MB/s 976773168+0 records in 976773168+0 records out ``` ## dcfldd - DoD Forensic dd ### Basic Syntax ```bash dcfldd if= of= [options] ``` ### Extended Options | Flag | Description | Example | |------|-------------|---------| | `hash=` | Hash algorithm(s) | `hash=sha256,md5` | | `hashlog=` | File for hash output | `hashlog=hashes.txt` | | `hashwindow=` | Hash every N bytes | `hashwindow=1G` | | `hashconv=` | Hash before or after conversion | `hashconv=after` | | `errlog=` | Error log file | `errlog=errors.log` | | `split=` | Split output into chunks | `split=2G` | | `splitformat=` | Suffix format for split files | `splitformat=aa` | | `vf=` | Verification file | `vf=evidence.dd` | | `verifylog=` | Verification result log | `verifylog=verify.log` | ### Output Format ``` Total (sha256): a3f2b8c9d4e5f6a7b8c9d0e1f2a3b4c5... 1024+0 records in 1024+0 records out ``` ## sha256sum - Hash Verification ### Syntax ```bash sha256sum sha256sum -c ``` ### Output Format ``` a3f2b8c9d4e5f6... /dev/sdb a3f2b8c9d4e5f6... evidence.dd ``` ## blockdev - Write Protection ### Syntax ```bash blockdev --setro # Set read-only blockdev --setrw # Set read-write blockdev --getro # Check: 1=RO, 0=RW blockdev --getsize64 # Size in bytes ``` ## lsblk - Block Device Enumeration ### Syntax ```bash lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,MODEL,SERIAL,RO lsblk -J # JSON output lsblk -p # Full device paths ``` ## hdparm - Drive Identification ### Syntax ```bash hdparm -I # Detailed drive info hdparm -i # Summary identification ``` ======================================================================== FILE: scripts/agent.py ======================================================================== #!/usr/bin/env python3 """Forensic disk image acquisition agent using dd and dcfldd with hash verification.""" import shlex import subprocess import hashlib import os import datetime import json def run_cmd(cmd, capture=True): """Execute a command and return output.""" if isinstance(cmd, str): cmd = shlex.split(cmd) result = subprocess.run(cmd, capture_output=capture, text=True, timeout=120) return result.stdout.strip(), result.stderr.strip(), result.returncode def list_block_devices(): """Enumerate connected block devices.""" stdout, _, rc = run_cmd("lsblk -J -o NAME,SIZE,TYPE,MOUNTPOINT,MODEL,SERIAL,RO") if rc == 0 and stdout: return json.loads(stdout) return {"blockdevices": []} def check_write_protection(device): """Verify a device is set to read-only mode.""" stdout, _, rc = run_cmd(f"blockdev --getro {device}") if rc == 0: return stdout.strip() == "1" return False def enable_write_protection(device): """Enable software write-blocking on the target device.""" _, _, rc = run_cmd(f"blockdev --setro {device}") if rc != 0: print(f"[ERROR] Failed to set {device} read-only. Run as root.") return False if check_write_protection(device): print(f"[OK] Write protection enabled on {device}") return True print(f"[ERROR] Write protection verification failed for {device}") return False def compute_hash(path, algorithm="sha256", block_size=65536): """Compute the SHA-256 or MD5 hash of a file or device.""" h = hashlib.new(algorithm) try: with open(path, "rb") as f: while True: block = f.read(block_size) if not block: break h.update(block) except PermissionError: print(f"[ERROR] Permission denied reading {path}. Run as root.") return None except FileNotFoundError: print(f"[ERROR] Path not found: {path}") return None return h.hexdigest() def acquire_with_dd(source, destination, block_size=4096, log_file=None): """Acquire a forensic image using dd with error handling.""" dd_cmd = [ "dd", f"if={source}", f"of={destination}", f"bs={block_size}", "conv=noerror,sync", "status=progress" ] print(f"[*] Starting dd acquisition: {source} -> {destination}") print(f"[*] Block size: {block_size}") start = datetime.datetime.utcnow() if log_file: dd_proc = subprocess.run(dd_cmd, capture_output=True, text=True, timeout=120) combined = (dd_proc.stdout or "") + (dd_proc.stderr or "") with open(log_file, "w") as lf: lf.write(combined) rc = dd_proc.returncode else: result = subprocess.run(dd_cmd, text=True, timeout=120) rc = result.returncode elapsed = (datetime.datetime.utcnow() - start).total_seconds() print(f"[*] Acquisition completed in {elapsed:.1f} seconds (rc={rc})") return rc == 0 def acquire_with_dcfldd(source, destination, hash_alg="sha256", hash_log=None, error_log=None, block_size=4096, split_size=None): """Acquire a forensic image using dcfldd with built-in hashing.""" cmd = [ "dcfldd", f"if={source}", f"of={destination}", f"bs={block_size}", "conv=noerror,sync", f"hash={hash_alg}", "hashwindow=1G", ] if hash_log: cmd.append(f"hashlog={hash_log}") if error_log: cmd.append(f"errlog={error_log}") if split_size: cmd.extend([f"split={split_size}", "splitformat=aa"]) print(f"[*] Starting dcfldd acquisition: {source} -> {destination}") start = datetime.datetime.utcnow() result = subprocess.run(cmd, text=True, timeout=120) rc = result.returncode elapsed = (datetime.datetime.utcnow() - start).total_seconds() print(f"[*] dcfldd completed in {elapsed:.1f} seconds (rc={rc})") return rc == 0 def verify_image(source, image_path, algorithm="sha256"): """Verify image integrity by comparing hashes of source and acquired image.""" print(f"[*] Computing {algorithm} hash of source: {source}") source_hash = compute_hash(source, algorithm) print(f" Source hash: {source_hash}") print(f"[*] Computing {algorithm} hash of image: {image_path}") image_hash = compute_hash(image_path, algorithm) print(f" Image hash: {image_hash}") if source_hash and image_hash: match = source_hash == image_hash status = "PASSED" if match else "FAILED" print(f"[{'OK' if match else 'FAIL'}] Verification: {status}") return match, source_hash, image_hash return False, source_hash, image_hash def generate_report(case_dir, source_device, image_path, tool_used, source_hash, image_hash, verified, elapsed_seconds=0): """Generate a forensic acquisition report.""" report = { "report_type": "Disk Image Acquisition", "timestamp": datetime.datetime.utcnow().isoformat() + "Z", "case_directory": case_dir, "source_device": source_device, "image_file": image_path, "acquisition_tool": tool_used, "block_size": 4096, "source_hash_sha256": source_hash, "image_hash_sha256": image_hash, "hash_verified": verified, "duration_seconds": elapsed_seconds, } report_path = os.path.join(case_dir, "acquisition_report.json") with open(report_path, "w") as f: json.dump(report, f, indent=2) print(f"[*] Report saved to {report_path}") return report if __name__ == "__main__": print("=" * 60) print("Forensic Disk Image Acquisition Agent") print("Tools: dd / dcfldd with SHA-256 verification") print("=" * 60) # Demo: list block devices print("\n[*] Enumerating block devices...") devices = list_block_devices() for dev in devices.get("blockdevices", []): name = dev.get("name", "?") size = dev.get("size", "?") dtype = dev.get("type", "?") model = dev.get("model", "N/A") ro = "RO" if dev.get("ro") else "RW" print(f" /dev/{name} {size} {dtype} {model} [{ro}]") # Demo workflow (dry run) demo_source = "/dev/sdb" demo_case = "/cases/demo-case/images" demo_image = os.path.join(demo_case, "evidence.dd") print(f"\n[DEMO] Acquisition workflow for {demo_source}:") print(f" 1. Enable write protection: blockdev --setro {demo_source}") print(f" 2. Acquire with dcfldd: dcfldd if={demo_source} of={demo_image} " f"hash=sha256 hashwindow=1G bs=4096 conv=noerror,sync") print(f" 3. Verify: compare SHA-256 of {demo_source} and {demo_image}") print(f" 4. Generate acquisition report with chain-of-custody metadata") print("\n[*] Agent ready. Provide a source device and case directory to begin.")