kushal-soni-official/File-Integrity-Monitor

GitHub: kushal-soni-official/File-Integrity-Monitor

一个基于 Python 的文件完整性监控器,使用 SHA-256 哈希检测文件的增删改并支持实时监控。

Stars: 0 | Forks: 0

# 🔍 文件完整性监控器 ![Python](https://img.shields.io/badge/Python-3.8+-blue?logo=python) ![License](https://img.shields.io/badge/License-MIT-green) ![Status](https://img.shields.io/badge/Status-Active-brightgreen) ![Category](https://img.shields.io/badge/Category-Intrusion%20Detection-orange) 一个基于 Python 的文件完整性监控器(FIM),使用 **SHA-256 哈希** 检测 未经授权的文件变更 —— 就像企业级工具 Tripwire 和 AIDE 一样。 支持基于快照的扫描和实时监控。 ## 📸 预览 ``` ╔══════════════════════════════════════════╗ ║ 🔍 FILE INTEGRITY MONITOR ║ ║ SHA-256 Baseline + Live Watchdog ║ ╚══════════════════════════════════════════╝ [1] Create baseline snapshot [2] Run integrity scan [3] Start live real-time monitor [4] View saved baseline info [0] Exit ══════════════════════════════════════════════════════════════ FILE INTEGRITY REPORT Directory : C:\Users\user\Documents\secure-folder Scanned : 2025-01-01 14:32:11 ══════════════════════════════════════════════════════════════ [+] ADDED FILES (1): + reports\new_report.pdf Size: 204,800 bytes | Time: 2025-01-01 14:30:00 [-] DELETED FILES (1): - config\settings.cfg Was: 1,024 bytes | Last seen: 2024-12-30 10:00:00 [~] MODIFIED FILES (1): ~ passwords\vault.txt Old hash : a3f1c2d4e5b6... New hash : 9f8e7d6c5b4a... ⚠ ALERT: Changes detected that may indicate tampering! ``` ## 🚀 功能特性 - ✅ **SHA-256 基线** — 为目录中的每个文件生成指纹 - ✅ **3 种变更检测** — 新增、删除、修改 - ✅ **实时监控** — 使用 `watchdog` 实现即时告警 - ✅ **基线持久化** — 将快照保存为 JSON 以便后续比较 - ✅ **内存高效** — 以 8KB 分块读取文件(支持大文件) - ✅ **递归扫描** — 捕获所有子目录中的变更 - ✅ **安全告警** — 当敏感类型文件被修改时发出警告 ## ⚙️ 安装与使用 ### 要求 - Python 3.8+ ### 安装依赖 ``` pip install watchdog ``` ### 运行 ``` git clone https://github.com/yourusername/file-integrity-monitor.git cd file-integrity-monitor python file_integrity_monitor.py ``` ## 🔬 工作原理 ``` Step 1 — Create Baseline Walk directory → Hash every file with SHA-256 → Save to JSON Step 2 — Scan for Changes Walk directory again → Hash every file again Compare new hashes vs baseline: New file? → ADDED Hash changed? → MODIFIED File missing? → DELETED Step 3 — Live Monitor (optional) watchdog library watches filesystem events in real time → Prints instant alert when any file changes ``` ### 为何使用 SHA-256? ``` Original file : SHA-256 = a3f1c2d4e5b6... Change 1 byte : SHA-256 = 9f8e7d6c5b4a... ← Completely different! ``` SHA-256 是一种单向加密函数。即使仅修改一个字符, 也会产生完全不同的哈希值 —— 从而立即检测到篡改行为。 ## 🏢 现实中的等价工具 | 工具 | 使用方 | |------|---------| | Tripwire | 企业服务器 | | AIDE | Linux 系统 | | Windows 文件完整性监控 | Azure Defender | | **本项目** | 你! | ## 📁 项目结构 ``` file-integrity-monitor/ │ ├── file_integrity_monitor.py # Main script ├── fim_baseline.json # Auto-generated baseline (after first run) └── README.md # This file ``` ## 🧠 学习收获 - SHA-256 哈希的工作原理以及如何检测文件篡改 - 基线的概念以及企业入侵检测工具如何使用基线 - Python 的 `hashlib` 模块用于加密哈希 - 分块读取文件以实现内存高效处理 - 使用 `watchdog` 库实现实时文件系统监控 - `os.walk()` 如何递归遍历目录 ## ⚠️ 免责声明 本工具仅供 **教育和防御用途**。 请仅监控您拥有或已获授权监控的目录。 ## 📄 许可证 MIT —— 自由使用、修改和分发。
标签:AIDE, Homebrew安装, Python, SHA-256, Tripwire, WSL, 企业安全, 变更检测, 哈希校验, 完整性校验, 快照扫描, 文件完整性, 文件监控, 无后门, 系统完整性, 网络资产管理, 逆向工具