SecurityRonin/ewf

GitHub: SecurityRonin/ewf

纯 Rust 实现的 EWF 取证磁盘镜像读取库与 CLI 工具,支持 E01/Ex01/L01 格式,提供 MCP 服务器用于 AI 辅助取证分析。

Stars: 8 | Forks: 3

# ewf [![Crates.io](https://img.shields.io/crates/v/ewf.svg)](https://crates.io/crates/ewf) [![docs.rs](https://img.shields.io/docsrs/ewf)](https://docs.rs/ewf) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/ae1df4dbab013827.svg)](https://github.com/SecurityRonin/ewf/actions) [![Coverage](https://img.shields.io/badge/coverage-99.86%25-brightgreen)](docs/VALIDATION.md) [![Sponsor](https://img.shields.io/badge/sponsor-h4x0r-ea4aaa?logo=github-sponsors)](https://github.com/sponsors/h4x0r) 纯 Rust 实现的 Expert Witness Format (E01/EWF) 取证磁盘镜像读取器。零 GPL 依赖。包含一个用于 AI 辅助取证分析的 CLI 和 MCP server。 ## 安装 ### CLI (预编译二进制文件) ``` # macOS (Homebrew) brew install SecurityRonin/tap/ewf # macOS / Linux (install 脚本) curl -sSL https://raw.githubusercontent.com/SecurityRonin/ewf/main/install.sh | bash # Windows (winget) winget install SecurityRonin.ewf # Debian / Ubuntu sudo dpkg -i ewf-cli_*.deb # 从源码构建(需要 Rust) cargo install ewf-cli ``` ### Rust 库 ``` [dependencies] ewf = "0.2" ``` ## CLI 用法 ``` ewf info image.E01 # Metadata, hashes, case info ewf verify image.E01 # Full-media MD5/SHA-1 verification ewf read image.E01 -o 510 -l 16 # Hex dump at offset ewf sections image.E01 # List internal EWF sections ewf search image.E01 55aa # Search for byte pattern ewf extract image.E01 -o 0 -l 512 -O mbr.bin # Extract bytes to file ewf info image.E01 --json # JSON output for scripting ``` ## MCP 服务器 `ewf mcp` 子命令会启动一个 [MCP](https://modelcontextprotocol.io/) server,通过 JSON-RPC stdio 进行 AI 辅助的取证镜像检查。 | 工具 | 描述 | |------|-------------| | `ewf_info` | 镜像元数据、几何结构、存储的哈希值、采集错误 | | `ewf_verify` | 全媒体哈希校验 (MD5 + SHA-1) | | `ewf_read_sectors` | 读取任意偏移量处的十六进制字节 | | `ewf_list_sections` | 列出所有分段的区块描述符 | | `ewf_search` | 使用十六进制输入进行字节模式搜索 | | `ewf_extract` | 将字节范围提取到文件 | ### 注册到 Claude Code ``` claude mcp add ewf -- ewf mcp ``` ### Claude Desktop 配置 ``` { "mcpServers": { "ewf": { "command": "ewf", "args": ["mcp"] } } } ``` ## 库快速入门 ``` use std::io::{Read, Seek, SeekFrom}; let mut reader = ewf::EwfReader::open("disk.E01")?; // Read the first sector let mut mbr = [0u8; 512]; reader.read_exact(&mut mbr)?; // Seek anywhere — O(1) via flat chunk index reader.seek(SeekFrom::Start(1_048_576))?; ``` `EwfReader` 实现了 `Read + Seek`,因此可以直接插入到 [`ntfs`](https://crates.io/crates/ntfs)、[`fatfs`](https://crates.io/crates/fatfs) 或任何期望可搜索流的 crate 中。 ## 库特性 - **EWF v1 格式** — 读取来自 EnCase, FTK Imager, Guymager, ewfacquire 等工具的镜像。 - **EWF v2 格式 (Ex01/Lx01)** — 读取 EnCase 7+ 镜像,带有格式自动检测功能 - **L01 逻辑证据文件** — 打开 `.L01`/`.l01` 文件 (相同的容器,逻辑采集) - **多分段** — 自动发现从 `.E01` 到 `.EZZ` (v1) 以及从 `.Ex01` 到 `.EzZZ` (v2) 的文件 - **zlib 解压** — 带有 LRU 缓存 (可配置,默认 100 个块 ~ 3.2 MB) - **O(1) 寻址** — 通过 `offset / chunk_size` 索引的扁平化块表 - **哈希校验** — `verify()` 通过 MD5/SHA-1 流式传输所有媒体数据,并与存储的哈希值进行比较 - **存储的哈希值** — 从 hash/digest 段 (v1) 和 Md5Hash/Sha1Hash 段 (v2) 读取 MD5 和 SHA-1 - **案件元数据** — 从 header (v1) 和 CaseData (v2) 段解析案件编号、检验员、描述、备注、采集日期 - **采集错误** — 从 error2 段提取读取错误条目 - **table + table2 容错性** — 处理两种段类型,正确进行去重 - **DoS 安全** — 防止具有异常表条目数的畸形镜像 - **MIT 许可** — 无 GPL,适用于专有的 DFIR 工具 ## 库 API 示例 ### 验证镜像完整性 ``` let mut reader = ewf::EwfReader::open("case001.E01")?; let result = reader.verify()?; if let Some(true) = result.md5_match { println!("MD5 verified: {:02x?}", result.computed_md5); } ``` ### 读取案件元数据 ``` let reader = ewf::EwfReader::open("case001.E01")?; let meta = reader.metadata(); println!("Case: {:?}", meta.case_number); println!("Examiner: {:?}", meta.examiner); println!("Software: {:?}", meta.acquiry_software); ``` ### 检查存储的哈希值 ``` let reader = ewf::EwfReader::open("case001.E01")?; let hashes = reader.stored_hashes(); if let Some(md5) = hashes.md5 { println!("Stored MD5: {:02x?}", md5); } ``` ### 调整大镜像的缓存 ``` // 1000 chunks ~ 32 MB cache — useful for sequential scans let mut reader = ewf::EwfReader::open_with_cache_size("case001.E01", 1000)?; ``` ### 配合 ntfs crate 使用 ``` use ewf::EwfReader; use ntfs::Ntfs; let mut reader = EwfReader::open("disk.E01")?; // Seek to NTFS partition offset, then: let ntfs = Ntfs::new(&mut reader)?; ``` ## 特性标志 | 标志 | 默认 | 描述 | |------|---------|-------------| | `verify` | 是 | 启用 `verify()` 方法 (增加 `md-5` 和 `sha-1` 依赖) | 要禁用哈希校验并减少依赖: ``` [dependencies] ewf = { version = "0.2", default-features = false } ``` ## 格式支持 | 格式 | 状态 | |--------|--------| | E01 (EWF v1) | 已支持 | | E01 多分段 (.E01-.EZZ) | 已支持 | | Ex01 (EWF v2) | 已支持 | | L01 (逻辑证据, v1) | 已支持 | | Lx01 (逻辑证据, v2) | 已支持 | | S01 (SMART) | 尚未支持 | ## 测试 - **127 个测试** (92 个单元测试 + 27 个端到端测试 + 8 个验证测试),**99.86% 的行覆盖率** (694/695 行) - 针对 libewf 和 The Sleuth Kit 的全媒体 MD5 对比,确认了在 6 个公开取证镜像 (303+ GiB 媒体数据) 上具有逐位相同的输出 - 测试镜像来源于 [Digital Corpora](https://digitalcorpora.org/) 和 [The Evidence Locker](https://theevidencelocker.github.io/) (Kevin Pagano) - 三个小镜像作为测试固件被提交并在 CI 中运行 详细结果、镜像来源和复现步骤请参见 [docs/VALIDATION.md](docs/VALIDATION.md)。 ## 致谢 架构参考了 [Velocidex/go-ewf](https://github.com/Velocidex/go-ewf) (Apache-2.0)。 ## 许可证 MIT
标签:AI辅助分析, E01, EWF, Expert Witness Format, JSON-RPC, MCP Server, MD5, MIT协议, Rust, Rust库, SHA-1, 可视化界面, 哈希校验, 域渗透, 开源, 数字取证, 数据恢复, 数据解析, 电子数据取证, 磁盘取证, 磁盘镜像, 网络安全, 网络流量审计, 自动化脚本, 通知系统, 镜像读取, 隐私保护, 零GPL依赖