sumeshi/prefetch2es

GitHub: sumeshi/prefetch2es

一款将 Windows Prefetch 文件解析为结构化记录并导入 Elasticsearch 或导出为 JSON 的数字取证工具。

Stars: 9 | Forks: 4

# prefetch2es [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) [![PyPI version](https://badge.fury.io/py/prefetch2es.svg)](https://badge.fury.io/py/prefetch2es) [![pytest](https://github.com/sumeshi/prefetch2es/actions/workflows/test.yaml/badge.svg)](https://github.com/sumeshi/prefetch2es/actions/workflows/test.yaml) ![prefetch2es logo](https://gist.githubusercontent.com/sumeshi/c2f430d352ae763273faadf9616a29e5/raw/fd3921cb75a484af98d795f194e9e4cb16b88515/prefetch2es.svg) 一个用于解析 Windows Prefetch 文件并将结果导入 Elasticsearch 的命令行工具。 **prefetch2es** 基于 [pyscca](https://github.com/libyal/libscca/tree/main/pyscca) 构建,可将 Windows Prefetch 痕迹转换为适配 Elasticsearch 的记录。 ## 功能 - 使用 pyscca 解析 Windows Prefetch (`.pf`) 文件 - 处理单个文件、多个文件或包含 `.pf` 文件的整个目录 - 将解析后的记录导入 Elasticsearch (`prefetch2es`) - 将解析后的记录导出为 JSON (`prefetch2json`) - 生成用于取证分析的以时间线为导向的记录 (`--timeline`) ## 安装说明 ### 从 PyPI 安装 ``` $ pip install prefetch2es ``` ### 从 GitHub Releases 安装 从 GitHub Releases 中可以获取使用 Nuitka 构建的独立二进制文件。 ``` $ chmod +x ./prefetch2es $ ./prefetch2es {{options...}} ``` ``` > prefetch2es.exe {{options...}} ``` ## 用法 **prefetch2es** 可以从命令行执行,也可以集成到 Python 脚本中。 ``` $ prefetch2es /path/to/your/file.pf ``` ``` from prefetch2es import prefetch2es prefetch2es("/path/to/your/file.pf") ``` ### 参数 prefetch2es 可以同时处理多个文件。 ``` $ prefetch2es file1.pf file2.pf file3.pf ``` prefetch2es 可以递归处理指定目录下的所有 `.pf` 文件。 ``` $ tree . pffiles/ ├── file1.pf ├── file2.pf ├── file3.pf └── subdirectory/ ├── file4.pf └── subsubdirectory/ ├── file5.pf └── file6.pf $ prefetch2es /pffiles/ # The path is recursively expanded to all .pf files. ``` ### 选项 ``` --version, -v --help, -h --quiet, -q Suppress standard output (default: False) --multiprocess, -m: Enable multiprocessing for faster execution (default: False) --size: Number of files to process per chunk (default: 500) --host: Elasticsearch host address (default: localhost) --port: Elasticsearch port number (default: 9200) --index: Destination index name (default: prefetch2es) --scheme: Protocol scheme to use (http or https) (default: http) --pipeline: Elasticsearch Ingest Pipeline to use (default: ) --timeline: Enable timeline analysis mode for forensic investigation (default: False) --tags: Comma-separated tags to add to each record for identification (e.g., hostname, domain name) (default: ) --login: Username for Elasticsearch authentication --pwd: Password for Elasticsearch authentication ``` ### 示例 在命令行中使用时: ``` $ prefetch2es /path/to/your/file.pf --host=localhost --port=9200 --index=foobar --size=500 ``` 在 Python 脚本中使用时: ``` if __name__ == '__main__': prefetch2es('/path/to/your/file.pf', host='localhost', port=9200, index='foobar', size=500) ``` 使用 Elastic Security 的凭证时: ``` $ prefetch2es /path/to/your/file.pf --host=localhost --port=9200 --index=foobar --login=elastic --pwd=****** ``` 使用时间线分析模式时: ``` $ prefetch2es /path/to/your/file.pf --timeline --index=prefetch-timeline ``` 使用自定义标签进行系统识别时: ``` # 单个 tag $ prefetch2es /path/to/your/file.pf --timeline --tags="WORKSTATION-01" --index=prefetch-timeline # 多个 tags(逗号分隔) $ prefetch2es /path/to/your/file.pf --timeline --tags="WORKSTATION-01,FOO,BAR" --index=prefetch-timeline ``` ## 附录 ### prefetch2json 一个附加功能::sushi: :sushi: :sushi: 将 Windows Prefetch 文件转换为 Python 的 `List[dict]` 对象。 ``` $ prefetch2json /path/to/your/file.pf -o /path/to/output/target.json ``` 将 Windows Prefetch 转换为 Python 的 List[dict] 对象。 ``` from prefetch2es import prefetch2json if __name__ == '__main__': filepath = '/path/to/your/file.pf' result: List[dict] = prefetch2json(filepath) ``` 结合时间线分析和自定义标签: ``` $ prefetch2json /path/to/your/file.pf --timeline --tags="WORKSTATION-01,FINANCE" -o output.json ``` ### 时间线分析 prefetch2es 支持时间线分析模式,该模式会创建专门用于取证调查的时间线记录。 标准模式为每个 Prefetch 文件创建一条记录。 时间线模式为每个记录的执行时间戳创建一条记录。 ``` $ prefetch2es /path/to/your/file.pf --timeline --index=prefetch-timeline ``` 此模式创建的记录经过了优化,非常适合对应用程序执行模式进行时序分析,从而更轻松地调查系统随时间的活动情况。 #### 用于系统识别的标签 使用 `--tags` 选项添加自定义标签,以便更好地进行组织和过滤: ``` # 识别 source system 和 department $ prefetch2es /path/to/prefetch/ --timeline --tags="WORKSTATION-01" --index=prefetch-timeline # 添加 criticality level $ prefetch2es /path/to/prefetch/ --timeline --tags="SERVER-02,FOO,BAR" --index=prefetch-timeline ``` ## 输出格式示例 ### 标准模式 ``` [ { "name": "CMD.EXE", "filenames": [ "\\VOLUME{01d1217a9c4c6779-8c9f49ec}\\WINDOWS\\SYSTEM32\\DISKPART.EXE", "\\VOLUME{01d12173f395296c-66f451bc}\\CMDER129\\VENDOR\\CLINK\\CLINK_DLL_X64.DLL", "\\VOLUME{01d1217a9c4c6779-8c9f49ec}\\WINDOWS\\SYSTEM32\\NTDLL.DLL", "\\VOLUME{01d1217a9c4c6779-8c9f49ec}\\WINDOWS\\SYSTEM32\\CMD.EXE", ... ], "exec_count": 55, "last_exec_times": [ "2016-01-12T20:07:03.981069Z", "2016-01-10T02:29:02.788726Z", "2016-01-04T23:27:28.405869Z", "2016-01-04T23:27:28.726891Z", "2016-01-04T18:38:10.935655Z", "2016-01-04T18:38:11.344163Z", "2015-12-31T21:42:29.667018Z", "2015-12-17T22:34:21.579861Z" ], "format_version": 30, "prefetch_hash": "D269B812", "number_of_volumes": 2, "number_of_filenames": 62, "number_of_file_metrics_entries": 62, "metrics": [ { "filename": "\\VOLUME{01d1217a9c4c6779-8c9f49ec}\\WINDOWS\\SYSTEM32\\DISKPART.EXE", "file_reference": "0X1000000009EF4" }, { "filename": "\\VOLUME{01d12173f395296c-66f451bc}\\CMDER129\\VENDOR\\CLINK\\CLINK_DLL_X64.DLL", "file_reference": "0X100000000B5A6" }, { "filename": "\\VOLUME{01d1217a9c4c6779-8c9f49ec}\\WINDOWS\\SYSTEM32\\NTDLL.DLL", "file_reference": "0X10000000575F4" }, { "filename": "\\VOLUME{01d1217a9c4c6779-8c9f49ec}\\WINDOWS\\SYSTEM32\\CMD.EXE", "file_reference": "0X1000000009CA8" }, ... ], "volumes": [ { "path": "\\VOLUME{01d12173f395296c-66f451bc}", "creation_time": "2015-11-17T20:10:06.204964Z", "serial_number": "66F451BC" }, { "path": "\\VOLUME{01d1217a9c4c6779-8c9f49ec}", "creation_time": "2015-11-17T20:57:46.243468Z", "serial_number": "8C9F49EC" } ], "source_file": "/workspace/tests/cache/CMD.EXE-D269B812.pf", "tags": [ "prefetch" ] }, ... ] ``` ### 时间线模式 ``` [ { "@timestamp": "2016-01-12T20:07:03.981069Z", "event": { "action": "prefetch-executed", "category": [ "process" ], "type": [ "start" ], "kind": "event", "provider": "prefetch", "module": "windows", "dataset": "windows.prefetch" }, "process": { "name": "CMD.EXE", "start": "2016-01-12T20:07:03.981069Z" }, "windows": { "prefetch": { "exec_count": 55, "hash": { "prefetch": "D269B812" }, "format_version": 30, "volumes": [ { "path": "\\VOLUME{01d12173f395296c-66f451bc}", "creation_time": "2015-11-17T20:10:06.204964Z", "serial_number": "66F451BC" }, { "path": "\\VOLUME{01d1217a9c4c6779-8c9f49ec}", "creation_time": "2015-11-17T20:57:46.243468Z", "serial_number": "8C9F49EC" } ], "metrics": [ { "filename": "\\VOLUME{01d1217a9c4c6779-8c9f49ec}\\WINDOWS\\SYSTEM32\\DISKPART.EXE", "file_reference": "0X1000000009EF4" }, { "filename": "\\VOLUME{01d12173f395296c-66f451bc}\\CMDER129\\VENDOR\\CLINK\\CLINK_DLL_X64.DLL", "file_reference": "0X100000000B5A6" }, { "filename": "\\VOLUME{01d1217a9c4c6779-8c9f49ec}\\WINDOWS\\SYSTEM32\\NTDLL.DLL", "file_reference": "0X10000000575F4" }, { "filename": "\\VOLUME{01d1217a9c4c6779-8c9f49ec}\\WINDOWS\\SYSTEM32\\CMD.EXE", "file_reference": "0X1000000009CA8" }, ... ] } }, "log": { "file": { "path": "/workspace/tests/cache/CMD.EXE-D269B812.pf" } }, "tags": [ "prefetch" ] }, ... ] ``` ## 支持的 Prefetch 版本 - Windows XP - Windows 2003 - Windows Vista (SP0) - Windows 7 (SP0) - Windows 8.1 - Windows 10 1809 - Windows 10 1903 - Windows 11 24H2 如需了解更多信息,请访问 [libscca](https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc)。 ## 许可证 prefetch2es 是基于 [MIT](https://github.com/sumeshi/prefetch2es/blob/master/LICENSE) 许可证发布的。 ### 第三方许可证 通过 GitHub Releases 分发的独立二进制文件捆绑了 [libscca / pyscca](https://github.com/libyal/libscca), 其受 [GNU Lesser General Public License v3.0 or later (LGPL-3.0-or-later)](https://www.gnu.org/licenses/lgpl-3.0.html) 许可证的约束。 - 上游源码:https://github.com/libyal/libscca - 捆绑版本:[`libscca-python==20260527`](https://pypi.org/project/libscca-python/20260527/) (源码:https://github.com/libyal/libscca/releases/tag/20260527) - 许可证文本:https://github.com/libyal/libscca/blob/main/COPYING.LESSER 您可以根据 LGPL 的规定,从上述上游源码获取、修改并重新构建 libscca。
标签:Elasticsearch, Windows预读取文件, 代码示例, 数字取证, 数据分析, 日志解析, 自动化脚本, 证书伪造, 逆向工具