SecurityRonin/winevt-forensic
GitHub: SecurityRonin/winevt-forensic
一个Rust实现的EVTX取证库,专门用于从损坏、截断或被篡改的Windows事件日志文件中恢复记录并检测结构异常。
Stars: 3 | Forks: 0
# winevt-forensic
**先恢复日志,再进行分析。**
每个检测工具都假设事件日志是完整的。在实际事件中,日志往往并不完整——被清除、截断、部分覆盖,或在传输过程中被勒索软件加密。该库尽可能恢复数据,并准确告诉你文件结构本身说明了什么。
```
cargo install wt-cli
wt carve /evidence/Security.evtx
wt verify /evidence/Security.evtx
```
**[完整文档 →](https://securityronin.github.io/winevt-forensic/)**
## 安装
**Cargo**
```
cargo install wt-cli
```
**从源码构建**
```
git clone https://github.com/SecurityRonin/winevt-forensic.git
cd winevt-forensic
cargo build --release
./target/release/wt --help
```
**库 crates**
```
[dependencies]
winevt-core = "0.1" # types + binary format constants
winevt-integrity = "0.1" # structural anomaly detection
winevt-carver = "0.1" # record carving from files, bytes, disk images
```
## 使用场景
### 从遭受勒索软件攻击的机器恢复事件日志
勒索软件快速加密存储。一些勒索软件家族故意只加密每个文件的一部分——追求速度而非彻底性。另一些则被 EDR、电源中断或网络切断所打断。无论哪种方式,受害者驱动器上的 Security 日志都会部分加密:某些块完整,某些则是乱码。每个主流 EVTX 解析器都会在遇到第一个损坏的块时失败并返回空结果。
```
# 部分加密NTFS卷的部分获取
wt carve /mnt/victim/Windows/System32/winevt/Logs/Security.evtx
```
```
{
"stats": {
"bytes_scanned": 1114112,
"chunks_found": 17,
"chunks_valid": 14,
"chunks_corrupt": 3,
"records_recovered": 4021,
"records_corrupt": 12
},
"indicators": [
{ "RecordIdGap": { "chunk_offset": 720896, "expected": 3102, "found": 3201 } }
]
}
```
14 个有效块加上从 3 个损坏块中的部分恢复。记录 ID 间隙可以确定这些块中原本包含哪些记录。
### 验证完整性后再信任时间线
在针对事件日志运行检测规则之前,需了解该文件在结构上是否健全。被清除、回滚或选择性编辑的日志会留下结构痕迹,这些痕迹早于任何规则匹配。
```
wt verify /evidence/Security.evtx
```
```
[
{
"ChunkChecksumMismatch": {
"chunk_offset": 69632,
"computed": 2881145975,
"stored": 3735928559
}
},
{
"RecordIdGap": {
"chunk_offset": 135168,
"expected": 4097,
"found": 4201
}
}
]
```
这些是结构性事实,而非取证结论。文件显示校验和不匹配且记录缺失。这些缺失记录的含义以及 104 条缺失记录中原本包含的内容,需要由分析师来判断。
### 从原始字节中恢复 — 磁盘镜像、内存转储、空闲空间
```
use winevt_carver::carve_from_bytes;
// Works on memory dumps, unallocated disk space, raw sector reads
let raw: Vec = std::fs::read("/dev/sda1")?;
let result = carve_from_bytes(&raw);
println!("Scanned {} bytes, found {} chunks, recovered {} records",
result.stats.bytes_scanned,
result.stats.chunks_found,
result.stats.records_recovered,
);
```
在任意 8 字节偏移处查找 `ElfChnk` 魔术值。不需要对齐假设,也不需要文件头。
## 定位说明
这不是检测工具。[Hayabusa](https://github.com/Yamato-Security/hayabusa) 在基于 Sigma 的威胁狩猎和 MITRE ATT&CK 标记方面做得远比这里构建的任何工具更好。[Log Parser Studio](https://github.com/microsoft/LogParserStudio) 拥有多年查询基础设施。这些工具是恢复日志的原因——这样才能为它们提供可处理的数据。
该库解决的问题是上游的:从其他工具无法打开的文件中提取记录。
| | [winevt-forensic](https://github.com/SecurityRonin/winevt-forensic) | [evtx](https://github.com/omerbenamram/evtx) | [python-evtx](https://github.com/williballenthin/python-evtx) | [hayabusa](https://github.com/Yamato-Security/hayabusa) | [Log Parser Studio](https://github.com/microsoft/LogParserStudio) |
|--|:-:|:-:|:-:|:-:|:-:|
| 可在 Linux / macOS 上运行 | ✅ | ✅ | ✅ | ✅ | — |
| 单个静态二进制文件 | ✅ | ✅ | — | ✅ | — |
| 无需 Python / .NET 运行时 | ✅ | ✅ | — | ✅ | — |
| 恢复损坏的块 | ✅ | — | — | — | — |
| 从原始磁盘/内存中恢复 | ✅ | — | — | — | — |
| CRC32 校验和验证 | ✅ | — | — | — | — |
| 记录 ID 间隙检测 | ✅ | — | — | — | — |
| JSON 输出 | ✅ | ✅ | — | ✅ | — |
| SQL 查询接口 | — | — | — | — | ✅ |
| 基于 Sigma 的检测规则 | — | — | — | ✅ | — |
| MITRE ATT&CK 标记 | — | — | — | ✅ | — |
| 免费(无成本) | ✅ | ✅ | ✅ | ✅ | ✅ |
| 开源 | ✅ | ✅ | ✅ | ✅ | — |
## 结构完整性检查
`winevt-integrity` 在二进制级别检查异常——原始事实,而非取证结论:
**块头 CRC32 不匹配** — 偏移 `0x78` 处的存储校验和与字节 `0x00..0x78` 的 CRC32 不匹配。块头在写入后被修改。
**记录 ID 间隙** — 块 N+1 的 `LastEventRecordNumber` 与块 N+1 的 `FirstEventRecordNumber` 不相等。这些 ID 之间的记录在文件中缺失。
**文件头不一致** — 文件头中的 `NextRecordId` 低于所有块中看到的最高 `LastEventRecordId`。标头在记录写入后被重写。
**时间戳乱序** — 同一块中某条记录的时间戳早于前一条记录的时间戳。单调性被破坏。
**日志已清除(EID 1102 / 104)** — 标准 Windows 事件,表示 Security 或 System 日志被明确清除。
这些是取证推理的输入。[RapidTriage](https://github.com/SecurityRonin/rapidtriage) 将它们与会话关联和频率分析结合使用,以产生解释层。
## Crate 结构
| 二进制格式常量(`ELFFILE_MAGIC`、`ELFCHNK_MAGIC`、`RECORD_MAGIC`)、域类型(`EvtxEvent`、`LogonSession`)、`IntegrityIndicator` 枚举。无外部依赖。 |
| [`winevt-integrity`](crates/winevt-integrity/) | 检测算法 — `detect_record_id_gaps()`、`verify_chunk_header_checksum()`、`check_timestamp_monotonicity()`、`check_file_header_consistency()` |
| [`winevt-carver`]( | 从损坏文件、原始字节、磁盘镜像中恢复 EVTX 块/记录。`carve_from_bytes()`、`carve_from_file()`、`verify_integrity()`。 |
| [`winevt-memory`]( | 从内存转储中恢复的 EVTX/ETW 数据的类型和分析。`MemoryRecoveredChunk`、`RecoveredEtwSession`、`detect_etw_tampering()`。 |
| [`wt-cli`]( | `wt` 二进制文件 — 封装 `winevt-carver`,输出 JSON。 |
```
# 在您自己的项目中使用提取工具
[dependencies]
winevt-carver = "0.1"
```
## 依赖关系图
```
graph LR
A[winevt-core] --> B[winevt-integrity]
B --> C[winevt-carver]
B --> E[winevt-memory]
C --> D[wt-cli]
```
## EVTX 二进制格式参考
## 相关项目
- **[RapidTriage](https://github.com/SecurityRonin/rapidtriage)** — 使用 winevt-forensic 进行 EVTX 恢复;提供会话关联、频率分析和 `rt` CLI
- **[srumensic](https://github.com/SecurityRonin/srum-forensic)** — 用于 Windows SRUM (ESE) 取证的姐妹库
- **[evtx](https://github.com/omerbenamram/evtx)** — 完整 EVTX 解析器,适用于正常(非损坏)文件;文件干净时的正确工具
- **[hayabusa](https://github.com/Yamato-Security/hayabusa)** — 基于 Sigma 的 EVTX 威胁狩猎;在恢复日志后使用此工具
显示 crate 布局
| Crate | 功能说明 | |-------|-------------| | [`winevt-core`](显示格式参考
### 文件头(128 字节,位于偏移 0) | 偏移 | 大小 | 字段 | |--------|------|-------| | 0x00 | 8 | 魔术值 `ElfFile\0` | | 0x08 | 8 | FirstChunkNumber | | 0x10 | 8 | LastChunkNumber | | 0x18 | 8 | NextRecordId | | 0x28 | 2 | HeaderBlockSize (0x1000) | | 0x2A | 2 | ChunkCount | | 0x78 | 4 | FileFlags (0x1=dirty, 0x2=full) | | 0x7C | 4 | Checksum (CRC32 of 0x00..0x78) | ### 块头(128 字节,位于块起始处,块大小 = 64 KiB) | 偏移 | 大小 | 字段 | |--------|------|-------| | 0x00 | 8 | 魔术值 `ElfChnk\0` | | 0x08 | 8 | FirstEventRecordNumber | | 0x10 | 8 | LastEventRecordNumber | | 0x34 | 4 | EventRecordsChecksum (CRC32 of records area) | | 0x78 | 4 | HeaderChecksum (CRC32 of 0x00..0x78) | ### 事件记录 | 偏移 | 大小 | 字段 | |--------|------|-------| | 0x00 | 4 | 魔术值 `\x2a\x2a\x00\x00` | | 0x04 | 4 | Size (total including header + trailer) | | 0x08 | 8 | RecordId | | 0x10 | 8 | Timestamp (Windows FILETIME) | | 0x18 | … | BinXml payload | | Size-4 | 4 | CopyOfSize (for backward traversal) | 记录从块偏移 `0x200` 开始。每个块正好是 `0x10000` 字节。标签:DAST, ETW, EVTX, HTTPS请求, HTTP工具, NTFS取证, Rust, Windows取证, 事件日志, 二进制分析, 云安全运维, 勒索软件, 取证工具, 可视化界面, 子域名变形, 安全事件响应, 库, 应急响应, 恶意软件分析, 数字取证, 数据恢复, 日志 carving, 痕迹检测, 磁盘镜像, 篡改检测, 结构异常检测, 网络信息收集, 网络流量审计, 自动化脚本, 通知系统