SecurityRonin/vhdx-forensic

GitHub: SecurityRonin/vhdx-forensic

纯 Rust 编写的 Hyper-V VHDX 虚拟磁盘只读解析器与取证完整性审计工具,专为 DFIR 场景检测篡改、损坏及反取证痕迹。

Stars: 0 | Forks: 0

# vhdx-forensic [![Crates.io: vhdx-core](https://img.shields.io/crates/v/vhdx-core.svg?label=vhdx-core)](https://crates.io/crates/vhdx-core) [![Crates.io: vhdx-forensic](https://img.shields.io/crates/v/vhdx-forensic.svg?label=vhdx-forensic)](https://crates.io/crates/vhdx-forensic) [![Docs.rs](https://img.shields.io/docsrs/vhdx-core)](https://docs.rs/vhdx-core) [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/80ddefa0e2214903.svg)](https://github.com/SecurityRonin/vhdx-forensic/actions/workflows/ci.yml) [![Sponsor](https://img.shields.io/badge/sponsor-h4x0r-ea4aaa?logo=github-sponsors)](https://github.com/sponsors/h4x0r) **使用纯 Rust 读取和审计 Hyper-V VHDX 磁盘映像 —— 一个强化的 `Read + Seek` 容器读取器,外加一个专为 DFIR 设计的包含 63 个代码的结构完整性分析器。** 该工作区提供了两个 crate:**`vhdx-core`** —— VHDX/Hyper-V 虚拟磁盘容器读取器(支持动态、固定、差异磁盘,以及自动的脏日志恢复),提供针对虚拟扇区流的 `Read + Seek` 视图(发布为 `vhdx-core`,导入为 `vhdx`);以及 **`vhdx-forensic`** —— 完整性分析器,用于审计原始字节以检测篡改、损坏和反取证的 GUID/日志擦除,输出 `forensicnomicon::report::Finding` 以及可选的内存中 CRC 修复。无 `unsafe` 代码,无 C 绑定,无外部工具。 ``` [dependencies] vhdx-core = "0.2" # reader — imported as `vhdx` vhdx-forensic = "0.2" # analyzer — graded structural findings ``` ``` use vhdx_forensic::{anomalies_at_least, Severity, VhdxIntegrity}; let image = std::fs::read("disk.vhdx")?; let anomalies = VhdxIntegrity::new(&image).analyse(); for a in anomalies_at_least(&anomalies, Severity::Error) { println!("[{:?}] {}", a.severity(), a.forensic_significance()); } # Ok::<(), Box>(()) ``` ## 用法 ### 打开 VHDX 并读取扇区 ``` use vhdx::VhdxReader; use std::io::{Read, Seek, SeekFrom}; let mut reader = VhdxReader::open("disk.vhdx")?; println!("Virtual disk size: {} bytes", reader.virtual_disk_size()); println!("Logical sector size: {} bytes", reader.logical_sector_size()); // Read the first sector let mut sector = vec![0u8; reader.logical_sector_size() as usize]; reader.seek(SeekFrom::Start(0))?; reader.read_exact(&mut sector)?; ``` ### 传递给文件系统 crate `VhdxReader` 实现了 `Read + Seek`,因此可以直接插入任何接受 reader 的 crate: ``` use vhdx::VhdxReader; let reader = VhdxReader::open("disk.vhdx")?; // e.g. ext4fs_forensic::Filesystem::open(reader)?; ``` ### 从内存缓冲区读取 ``` use vhdx::VhdxReader; let data: Vec = std::fs::read("disk.vhdx")?; let reader = VhdxReader::from_bytes(data)?; ``` ### 打开差异(子)磁盘及其父磁盘 ``` use vhdx::VhdxReader; let parent = VhdxReader::from_bytes(std::fs::read("base.vhdx")?)?; let reader = VhdxReader::from_bytes_with_parent(std::fs::read("child.vhdx")?, parent)?; // Reads absent blocks in the child are transparently served from parent. ``` ## CLI `vhdx-cli` crate(包含在此工作区中)提供了一个 `vhdx info` 命令: ``` $ vhdx info disk.vhdx File: disk.vhdx Format: VHDX v1 (dynamic) Virtual disk size: 16,777,216 bytes (16.00 MiB) Logical sectors: 512 bytes ``` ## 支持的格式 | 格式 | 是否支持 | |--------|:---------:| | VHDX 版本 1 (Windows 8 / Server 2012+) | ✓ | | 动态磁盘(稀疏,BAT 寻址) | ✓ | | 固定磁盘(预分配) | ✓ | | 差异磁盘(单级父链) | ✓ | | 日志重放(脏日志恢复) | ✓ | 只读。差异磁盘需要通过 `VhdxReader::from_bytes_with_parent` 提供父映像。当活动标头携带非零的 LogGuid 时,在打开时会自动应用日志重放。 ## 取证分析 — `vhdx-forensic` `VhdxIntegrity::new(&bytes).analyse()` 通过六个阶段遍历原始容器 —— 容器/魔数、CRC 完整性、标头语义、区域布局、元数据以及 BAT/数据块分析 —— 并返回一个 `Vec`。它直接处理原始字节,不需要完全有效的结构。每个变体都包含一个稳定的 `code` 字符串、一个分级的 `severity()`、一段 `forensic_significance()` 描述以及 `mitre_techniques()`。共有 **63** 个不同的异常代码;以下是代表性示例: | 代码 | 严重程度 | 含义 | |------|----------|---------| | `VHDX-BAD-MAGIC` | Critical | 文件未以 `vhdxfile` 签名开头 | | `VHDX-BOTH-HEADER-COPIES-INVALID` | Critical | 两份标头副本均未通过 CRC32C 校验 —— 无法进行标头恢复 | | `VHDX-HEADER-CHECKSUM-MISMATCH` | Error | 标头副本存储的 CRC32C 与计算出的值不匹配 | | `VHDX-REGIONS-OVERLAP` | Error | 两个区域表条目声明占用了重叠的容器字节 | | `VHDX-LOG-ENTRY-CRC-MISMATCH` | Error | 某个日志条目的 CRC 校验失败 —— 重放会损坏映像 | | `VHDX-BAT-ENTRY-BEYOND-CONTAINER` | Error | BAT 条目指向超出文件末尾的位置 | | `VHDX-FILE-WRITE-GUID-ALL-ZEROS` | Warning | FileWriteGuid 被擦除 —— 符合反取证篡改的特征 | | `VHDX-GHOST-DATA-IN-ABSENT-BLOCK` | Warning | 标记为缺失的块中存在非零负载 —— 残留/隐藏数据 | | `VHDX-DIFFERENCING-DISK` | Warning | 映像是需要父映像才能读取的子磁盘 | | `VHDX-DIRTY-LOG` | Info | 存在活动日志 —— 映像未正常关闭 | 发现的观察结果仅作为客观现象,绝非法律结论 —— MITRE 映射以“符合特征”的形式呈现,供分析师权衡。`VhdxRepair::new(bytes).attempt_repair()` 会从内存中有效的对等副本重建标头和区域表的 CRC32C 校验和;它永远不会修改负载数据。 ## 信任但验证 - **处理恶意输入时不触发 panic。** 生产代码中不包含 `.unwrap()`/`.expect()`/`panic!` 或未经检查的索引(`unwrap_used`/`expect_used` 均为严格的 `deny` lint)。所有长度、偏移量和计数字段在进行任何算术运算前都会进行边界检查;BAT 寻址使用 `checked_mul`/`checked_add`。 - **经过模糊测试。** `cargo-fuzz` 工作区对解析和分析路径进行了测试;其不变性原则是“绝不触发 panic”。 - **针对真实产物进行验证。** 已使用 [log2timeline/dfvfs](https://github.com/log2timeline/dfvfs) 语料库和 QEMU v11.0.0 的输出中独立生成的映像进行了测试,并通过 `qemu-img info` 对虚拟磁盘大小进行了交叉验证。通过将损坏注入到真实 QEMU 映像中规范指定的字节偏移量处,证明了检测的有效性。参见 [`forensic/README.md`](forensic/README.md#testing) 和 [docs/VALIDATION.md](docs/VALIDATION.md)。 ## 相关 crate ### 容器读取器 | Crate | 格式 | 备注 | |-------|--------|-------| | [`ewf`](https://github.com/SecurityRonin/ewf) | E01 / EWF / Ex01 | 占主导地位的专业取证获取格式 | | [`aff4`](https://github.com/SecurityRonin/aff4) | AFF4 v1 | Evimetry / aff4-imager 取证磁盘映像,包含 Map 流 | | [`vmdk`](https://github.com/SecurityRonin/vmdk) | VMware VMDK | 来自 VMware Workstation / ESXi 的单体稀疏磁盘映像 | | [`vhd`](https://github.com/SecurityRonin/vhd) | 早期 VHD | Virtual PC / Hyper-V 第一代固定和动态磁盘映像 | | [`qcow2`](https://github.com/SecurityRonin/qcow2) | QCOW2 v2/v3 | QEMU / KVM / libvirt 磁盘映像 | | [`ufed`](https://github.com/SecurityRonin/ufed) | Cellebrite UFED | 包含 UFD XML 段映射的物理移动设备转储文件 | | [`dd`](https://github.com/SecurityRonin/dd) | 原始 / 扁平 / gz | dd、dcfldd 以及 gzip 封装的原始映像 | | [`iso9660-forensic`](https://github.com/SecurityRonin/iso9660-forensic) | ISO 9660 | 光盘映像:多会话、UDF 桥接、Rock Ridge、Joliet、El Torito | | [`dmg`](https://github.com/SecurityRonin/dmg) | Apple DMG / UDIF | macOS 磁盘映像,包含 koly 尾部、mish 块表、zlib 解压缩 | | [`dar`](https://github.com/SecurityRonin/dar) | DAR 归档 | 带有目录索引和 CRC32 验证的 Disk ARchiver 归档文件 | ### 取证分析器 | Crate | 格式 | 备注 | |-------|--------|-------| | [`vhdx-forensic`](https://github.com/SecurityRonin/vhdx-forensic) | VHDX | 基于此 crate 构建的取证完整性分析器和内存修复工具 | | [`ewf-forensic`](https://github.com/SecurityRonin/ewf-forensic) | E01 | 结构完整性审计、Adler-32 / MD5 哈希验证以及内存修复 | [隐私政策](https://securityronin.github.io/vhdx-forensic/privacy/) · [服务条款](https://securityronin.github.io/vhdx-forensic/terms/) · © 2026 Security Ronin Ltd
标签:Rust, VHDX, 可视化界面, 完整性分析, 数字取证, 网络流量审计, 自动化脚本, 虚拟化, 通知系统