dvlinuxx-max/intguard
GitHub: dvlinuxx-max/intguard
intguard 是一个零依赖的 Python CLI 文件完整性监控工具,通过 SHA-256 基准对比来检测目录树中文件的增删改。
Stars: 0 | Forks: 0
# intguard
一个文件完整性监控工具。记录目录树的 SHA-256 基准,然后检测后续任何被添加、修改或删除的文件。无依赖。
适合用于监控配置目录、web 根目录或已部署的制品是否发生了意外更改——这是 AIDE 和 Tripwire 等工具背后的核心理念,现在浓缩在一个小脚本中。
## 用法
```
# 1. 记录 baseline (默认写入 .intguard.json)
python intguard.py baseline /etc/nginx -m nginx.baseline.json
# 2. 之后,检查更改
python intguard.py check /etc/nginx -m nginx.baseline.json
```
当编辑了一个文件并添加了另一个文件后的示例输出:
```
integrity check /etc/nginx
modified (1)
~ nginx.conf
added (1)
+ sites-enabled/evil.conf
2 change(s) detected.
```
当没有更改时 `check` 以 `0` 退出,发现更改时以 `1` 退出,因此可以直接放入 cron 或 CI 中:
```
python intguard.py check /var/www --json || alert "web root changed"
```
## 排除项
默认情况下,`.git/`、`__pycache__/`、`*.pyc` 以及清单文件本身都会被排除。可以使用可重复的 `-x` glob 模式添加更多排除项:
```
python intguard.py baseline . -x '*.log' -x 'cache/*'
```
## 工作原理
```
intguard.py
scan walk the tree, hash each file (sha256, chunked)
save_manifest JSON: per-file sha256 + size, plus root and timestamp
diff set difference -> added / modified / removed
```
哈希处理以 64 KiB 为块进行流式传输,因此大文件不会被加载到内存中。
清单文件是纯 JSON 格式,可以在版本控制中进行差异对比。
## 环境要求
Python 3.9+。无需第三方包。
## 许可证
MIT
标签:Homebrew安装, Python, x64dbg, 哈希校验, 文档结构分析, 无后门, 系统运维, 逆向工具, 防御监控