sumeshi/evtx2es

GitHub: sumeshi/evtx2es

一个基于 Rust 解析器的高效 Windows 事件日志解析与 Elasticsearch 导入工具,支持命令行和 Python 库两种调用方式。

Stars: 86 | Forks: 16

# evtx2es [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) [![PyPI version](https://badge.fury.io/py/evtx2es.svg)](https://badge.fury.io/py/evtx2es) [![Python Versions](https://img.shields.io/pypi/pyversions/evtx2es.svg)](https://pypi.org/project/evtx2es/) [![pytest](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/c2544e27f9132100.svg)](https://github.com/sumeshi/evtx2es/actions/workflows/test.yaml) ![evtx2es logo](https://gist.githubusercontent.com/sumeshi/c2f430d352ae763273faadf9616a29e5/raw/1bf24feb55571bf7f0c7d8d4cb04bd0a511120f2/evtx2es.svg) 一个用于将 Windows 事件日志解析并导入 Elasticsearch 的快速库。 人生苦短,不要用 **纯 Python** 去处理**海量的 Windows 事件日志**。 **evtx2es** 利用了基于 Rust 的解析器 [pyevtx-rs](https://github.com/omerbenamram/pyevtx-rs),使其比传统工具快得多。 它还提供了解析功能,能够从损坏、部分覆盖或雕刻(carved)的 `.evtx` 文件中提取尽可能多的记录。 ## 用法 **evtx2es** 可以作为独立的命令行工具使用,也可以直接集成到您的 Python 脚本中。 ``` $ evtx2es /path/to/your/file.evtx ``` ``` from evtx2es import evtx2es if __name__ == '__main__': filepath = '/path/to/your/file.evtx' evtx2es(filepath) ``` ### 参数 **evtx2es** 支持同时导入多个文件: ``` $ evtx2es file1.evtx file2.evtx file3.evtx ``` 您也可以指定一个目录,以递归方式导入其中的所有 `.evtx` 文件: ``` $ tree . evtxfiles/ ├── file1.evtx ├── file2.evtx ├── file3.evtx └── subdirectory/ ├── file4.evtx └── subsubdirectory/ ├── file5.evtx └── file6.evtx $ evtx2es /evtxfiles/ # This recursively processes file1 through file6. ``` ### 选项 ``` --version, -v --help, -h --quiet, -q Suppress standard output (default: False) --multiprocess, -m: Enable multiprocessing for faster execution (default: False) --size: Chunk size for processing (default: 500) --host: Elasticsearch host address (default: localhost) --port: Elasticsearch port number (default: 9200) --index: Destination index name (default: evtx2es) --scheme: Protocol scheme to use (http or https) (default: http) --pipeline: Elasticsearch Ingest Pipeline to use (default: ) --datasetdate: Date of the latest record in the dataset, extracted from TimeCreated field (MM/DD/YYYY.HH:MM:SS) (default: 0) --login: The login to use if Elastic Security is enabled (default: ) --pwd: The password associated with the provided login (default: ) ``` ### 示例 在命令行中使用时: ``` $ evtx2es /path/to/your/file.evtx --host=localhost --port=9200 --index=foobar --size=500 ``` 在 Python 脚本中使用时: ``` if __name__ == '__main__': evtx2es('/path/to/your/file.evtx', host=localhost, port=9200, index='foobar', size=500) ``` 使用 Elastic Security 凭证时: ``` $ evtx2es /path/to/your/file.evtx --host=localhost --port=9200 --index=foobar --login=elastic --pwd=****** ``` **注意:** TLS/SSL 证书验证目前默认为禁用状态。 ## 附录 ### Evtx2json 作为额外的福利,**evtx2es** 包含了一个辅助工具,用于将 Windows 事件日志转换为 JSON 文件。 :sushi: :sushi: :sushi: ``` $ evtx2json /path/to/your/file.evtx /path/to/output/target.json ``` 您也可以直接将 `.evtx` 文件转换为 Python `List[dict]` 对象: ``` from evtx2es import evtx2json if __name__ == '__main__': filepath = '/path/to/your/file.evtx' result: List[dict] = evtx2json(filepath) ``` ## 输出格式示例 以 [JPCERT/CC:LogonTracer](https://github.com/JPCERTCC/LogonTracer) 的示例 evtx 文件为例。 ``` [ { "@timestamp": "2016-10-06T01:47:07.509504Z", "event": { "action": "eventlog-security-1102", "category": [ "host" ], "type": [ "info" ], "kind": "event", "provider": "microsoft-windows-eventlog", "module": "windows", "dataset": "windows.eventlog", "code": 1102, "created": "2016-10-06T01:47:07.509504Z" }, "winlog": { "channel": "Security", "computer_name": "WIN-WFBHIBE5GXZ.example.co.jp", "event_id": 1102, "opcode": 0, "record_id": 227126, "task": 104, "version": 0, "provider": { "name": "Microsoft-Windows-Eventlog", "guid": "{fc65ddd8-d6ef-4962-83d5-6e5cfe9ce148}" } }, "userdata": { "LogFileCleared": { "#attributes": { "xmlns:auto-ns3": "http://schemas.microsoft.com/win/2004/08/events", "xmlns": "http://manifests.microsoft.com/win/2004/08/windows/eventlog" }, "SubjectUserSid": "S-1-5-21-1524084746-3249201829-3114449661-500", "SubjectUserName": "Administrator", "SubjectDomainName": "EXAMPLE", "SubjectLogonId": "0x32cfb" } }, "process": { "pid": 960, "thread": { "id": 3020 } }, "log": { "file": { "path": "/path/to/your/Security.evtx" } }, "tags": [ "eventlog" ] }, ... ] ``` ## 性能评估 (v1.8.0) 使用来自 [JPCERT/CC:LogonTracer](https://github.com/JPCERTCC/LogonTracer) 的示例 `.evtx` 文件(约 30MB 二进制数据)进行性能评估。 ``` $ time uv run evtx2es Security.evtx Currently Importing Security.evtx. 1it [00:08, 8.09s/it] Bulk import completed: 1 batches processed Successfully indexed: 62031 documents Import completed. ________________________________________________________ Executed in 8.60 secs fish external usr time 4.85 secs 481.00 micros 4.85 secs sys time 0.40 secs 0.00 micros 0.40 secs ``` ### 运行环境 ``` OS: Ubuntu 20.04 (Dev Container on WSL2) CPU: Intel Core i5-12400F RAM: DDR4 32GB ``` 测试在提供的开发容器中进行,将数据推送到本地 Elasticsearch 9.0.2 Docker 容器。 https://hub.docker.com/_/elasticsearch ## 安装 ### 从 PyPI 安装 ``` $ pip install evtx2es ``` ### 使用 uv 安装 ``` $ uv add evtx2es ``` ### 从 GitHub Releases 安装 适用于没有 Python 环境的系统的预编译独立二进制文件(使用 Nuitka 构建)。 ``` $ chmod +x ./evtx2es $ ./evtx2es {{options...}} ``` ``` > evtx2es.exe {{options...}} ``` ## 贡献 **evtx2es** 的源代码托管在 GitHub 上:https://github.com/sumeshi/evtx2es 非常欢迎贡献、复刻(fork)和代码审查!请随时开启 issue 或提交功能请求。 :sushi: :sushi: :sushi: ## 收录于 - [Tsurugi Linux [Lab] 2022 - 2024](https://tsurugi-linux.org/) - DFIR Linux 发行版 感谢您对 evtx2es 的关注! ## 许可证 evtx2es 根据 [MIT](https://github.com/sumeshi/evtx2es/blob/master/LICENSE) 许可证发布。 由以下库提供支持: - [pyevtx-rs](https://github.com/omerbenamram/pyevtx-rs) - [Nuitka](https://github.com/Nuitka/Nuitka) 灵感来源于 [EvtxtoElk](https://github.com/dgunter/evtxtoelk)。
标签:Awesome, Elasticsearch, evtx, JSON, pyevtx-rs, Rust加速, Windows事件日志, 二进制发布, 可视化界面, 多进程, 开源工具, 数字取证, 文件恢复, 日志导入, 日志解析, 系统管理, 自动化脚本, 证书伪造, 逆向工具