sumeshi/mft2es
GitHub: sumeshi/mft2es
mft2es:解析Windows MFT并导入Elasticsearch的工具
Stars: 13 | Forks: 4
# mft2es
[](LICENSE)
[](https://pypi.org/project/mft2es/)

A command-line tool and Python library for parsing Windows Master File Table (`$MFT`) and importing the results into Elasticsearch.
**mft2es** leverages the Rust-based parser [pymft-rs](https://github.com/omerbenamram/pymft-rs),使它在许多情况下比纯 Python 解析器更快。
## 使用方法
**mft2es** 可以作为独立的命令行工具或直接集成到您的 Python 脚本中。
```
$ mft2es '/path/to/your/$MFT'
```
```
from mft2es import mft2es
mft2es("/path/to/your/$MFT")
```
### 参数
**mft2es** 可以一次性处理多个文件:
```
$ mft2es 'file1/$MFT' 'file2/$MFT' 'file3/$MFT'
```
mft2es 可以递归地处理指定目录下的所有 `MFT` 和 `$MFT` 文件:
```
$ tree .
mftfiles/
├── $MFT
└── subdirectory/
├── $MFT
└── subsubdirectory/
└── $MFT
$ mft2es /mftfiles/ # The path is recursively expanded to all MFT and $MFT files.
```
### 选项
```
--version, -v
--help, -h
--quiet, -q
Suppress standard output
(default: False)
--multiprocess, -m:
Enable multiprocessing for faster execution
(default: False)
--size:
Number of records to process per chunk (default: 500)
--host:
Elasticsearch host address (default: localhost)
--port:
Elasticsearch port number (default: 9200)
--index:
Destination index name (default: mft2es)
--scheme:
Protocol scheme to use (http or https) (default: http)
--pipeline:
Elasticsearch Ingest Pipeline to use (default: )
--timeline:
Enable timeline analysis mode for MACB format
(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
--no-verify-certs:
Disable TLS certificate verification for Elasticsearch connections (default: False)
```
### 示例
当从命令行使用时:
```
$ mft2es '/path/to/your/$MFT' --host=localhost --port=9200 --index=foobar --size=500
```
当从 Python 脚本中使用时:
```
mft2es("/path/to/your/$MFT", host="localhost", port=9200, index="foobar", size=500)
```
使用 Elastic Security 凭据:
```
$ mft2es '/path/to/your/$MFT' --host=localhost --port=9200 --index=foobar --login=elastic --pwd=******
```
使用时间线分析模式:
```
$ mft2es '/path/to/your/$MFT' --timeline --index=mft-timeline
```
使用标签进行主机识别:
```
$ mft2es '/path/to/your/$MFT' --tags "WORKSTATION-1,DOMAIN-ABC" --index=host-analysis
```
## 附录
### mft2json
**mft2es** 还包括 `mft2json`,这是一个命令行工具,用于将 Windows Master File Table 记录转换为 JSON 文件。 :sushi: :sushi: :sushi:
```
$ mft2json '/path/to/your/$MFT' -o /path/to/output/target.json
```
使用标签进行主机识别:
```
$ mft2json '/path/to/your/$MFT' --tags "WORKSTATION-1,DOMAIN-ABC" -o /path/to/output/target.json
```
您还可以直接将 `$MFT` 记录转换为 Python List[dict] 对象:
```
from mft2es import mft2json
result: List[dict] = mft2json("/path/to/your/$MFT")
```
### 时间线分析
mft2es 支持时间线分析模式,为取证调查创建 MACB(修改、访问、更改、出生)时间线记录。
```
$ mft2es '/path/to/your/$MFT' --timeline --index=mft-timeline
```
## 输出格式示例
### 标准模式
```
[
{
"header": {
"signature": [
70,
73,
76,
69
],
"usa_offset": 48,
"usa_size": 3,
"metadata_transaction_journal": 172848302,
"sequence": 1,
"hard_link_count": 1,
"first_attribute_record_offset": 56,
"flags": "ALLOCATED",
"used_entry_size": 416,
"total_entry_size": 1024,
"base_reference": {
"entry": 0,
"sequence": 0
},
"first_attribute_id": 6,
"record_number": 0
},
"attributes": {
"StandardInformation": {
"header": {
"type_code": "StandardInformation",
"record_length": 96,
"form_code": 0,
"residential_header": {
"index_flag": 0
},
"name_size": 0,
"name_offset": null,
"data_flags": "(empty)",
"instance": 0,
"name": ""
},
"data": {
"created": "2019-03-11T16:42:33.593750Z",
"modified": "2019-03-11T16:42:33.593750Z",
"mft_modified": "2019-03-11T16:42:33.593750Z",
"accessed": "2019-03-11T16:42:33.593750Z",
"file_flags": "FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM",
"max_version": 0,
"version": 0,
"class_id": 0,
"owner_id": 0,
"security_id": 256,
"quota": 0,
"usn": 0
}
},
"FileName": {
"header": {
"type_code": "FileName",
"record_length": 104,
"form_code": 0,
"residential_header": {
"index_flag": 1
},
"name_size": 0,
"name_offset": null,
"data_flags": "(empty)",
"instance": 3,
"name": ""
},
"data": {
"parent": {
"entry": 5,
"sequence": 5
},
"created": "2019-03-11T16:42:33.593750Z",
"modified": "2019-03-11T16:42:33.593750Z",
"mft_modified": "2019-03-11T16:42:33.593750Z",
"accessed": "2019-03-11T16:42:33.593750Z",
"logical_size": 16384,
"physical_size": 16384,
"flags": "FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM",
"reparse_value": 0,
"name_length": 4,
"namespace": "Win32AndDos",
"name": "$MFT",
"path": "$MFT"
}
},
"DATA": {
"header": {
"type_code": "DATA",
"record_length": 72,
"form_code": 1,
"residential_header": {
"vnc_first": 0,
"vnc_last": "0x198f",
"unit_compression_size": 0,
"allocated_length": 62390272,
"file_size": 62390272,
"valid_data_length": 62390272,
"total_allocated": null
},
"name_size": 0,
"name_offset": null,
"data_flags": "(empty)",
"instance": 1,
"name": ""
},
"data": null
},
"BITMAP": {
"header": {
"type_code": "BITMAP",
"record_length": 80,
"form_code": 1,
"residential_header": {
"vnc_first": 0,
"vnc_last": 0,
"unit_compression_size": 0,
"allocated_length": 12288,
"file_size": 8200,
"valid_data_length": 8200,
"total_allocated": null
},
"name_size": 0,
"name_offset": null,
"data_flags": "(empty)",
"instance": 5,
"name": ""
},
"data": null
}
},
"tags": ["mft", "WORKSTATION-1", "DOMAIN-ABC"]
},
...
]
```
### 时间线模式
```
[
{
"@timestamp": "2007-06-30T12:50:52.252395Z",
"event": {
"action": "mft-standardinformation-m",
"category": [
"file"
],
"type": [
"change"
],
"kind": "event",
"provider": "mft",
"module": "windows",
"dataset": "windows.mft"
},
"windows": {
"mft": {
"record": {
"number": 0,
"name": "$MFT",
"path": "$MFT"
},
"header": {
"signature": [
70,
73,
76,
69
],
"usa_offset": 48,
"usa_size": 3,
"metadata_transaction_journal": 77648146,
"sequence": 1,
"hard_link_count": 1,
"first_attribute_record_offset": 56,
"flags": "ALLOCATED",
"used_entry_size": 424,
"total_entry_size": 1024,
"base_reference": {
"entry": 0,
"sequence": 0
},
"first_attribute_id": 6
},
"attribute": {
"type": "StandardInformation",
"macb_type": "M",
"header": {
"record_length": 96,
"form_code": 0,
"residential_header": {
"index_flag": 0
},
"name_size": 0,
"name_offset": null,
"data_flags": "(empty)",
"instance": 0,
"name": ""
},
"data": {
"file_flags": "FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM",
"max_version": 0,
"version": 0,
"class_id": 0,
"owner_id": 0,
"security_id": 256,
"quota": 0,
"usn": 0
}
}
}
},
"log": {
"file": {
"path": "/path/to/your/MFT"
}
},
"tags": [
"mft"
]
},
...
]
```
## 安装
### 从 PyPI 安装
```
$ pip install mft2es
```
### 使用 uv
```
$ uv add mft2es
```
### 从 GitHub 发布版
使用 Nuitka 构建的独立二进制文件可以从 GitHub 发布版获取,适用于没有 Python 环境的系统。
```
$ chmod +x ./mft2es
$ ./mft2es {{options...}}
```
```
> mft2es.exe {{options...}}
```
## 贡献
**mft2es** 的源代码托管在 GitHub 上:https://github.com/sumeshi/mft2es。
请报告问题和功能请求。 :sushi: :sushi: :sushi:
## 包含在
- [Tsurugi Linux [Lab]](https://tsurugi-linux.org/) — 包含在选定版本中。
感谢您对 mft2es 的关注!
## 许可证
在 [MIT](LICENSE) 许可证下发布。
## 第三方许可证
通过 GitHub 发布版分发的独立二进制文件可能包含以下第三方库。
这些库保留其原始许可证。
### Apache-2.0
- [elasticsearch-py / elasticsearch](https://github.com/elastic/elasticsearch-py) — 根据 Apache License 2.0 许可。
- 打包版本:`elasticsearch==9.4.1`
- 许可证文本:https://github.com/elastic/elasticsearch-py/blob/main/LICENSE
### MIT
- [mft / pymft-rs](https://github.com/omerbenamram/pymft-rs) — 根据 MIT 许可证。
- 打包版本:`mft==0.6.1`
- 许可证文本:https://github.com/omerbenamram/pymft-rs/blob/master/pyproject.toml
- [urllib3](https://github.com/urllib3/urllib3) — 根据 MIT 许可证。
- 打包版本:`urllib3==2.6.3`
- 许可证文本:https://github.com/urllib3/urllib3/blob/main/LICENSE.txt
### Apache-2.0 OR MIT,包含 MPL-2.0 组件
- [orjson](https://github.com/ijl/orjson) — 根据 Apache-2.0 OR MIT 许可,并包含根据 MPL-2.0 许可的源代码。
- 打包版本:`orjson==3.11.9`
- 许可证文本:
- https://github.com/ijl/orjson/blob/master/LICENSE-APACHE
- https://github.com/ijl/orjson/blob/master/LICENSE-MIT
- https://github.com/ijl/orjson/blob/master/LICENSE-MPL-2.0
### MIT 和 MPL-2.0
- [tqdm](https://github.com/tqdm/tqdm) — 根据 MIT 许可,包含受 MPL-2.0 覆盖的文件/组件。
- 打包版本:`tqdm==4.67.3`
- 许可证文本:https://github.com/tqdm/tqdm/blob/master/LICENCE
标签:Elasticsearch集成, MACB格式, MFT解析, MIT许可, PyPI, Rust语言, SEO优化, Windows系统, 可视化界面, 多进程, 安全可观测性, 开源许可, 性能优化, 数据导入, 检测绕过, 版本控制, 逆向工具, 递归处理