A defensive file-integrity monitoring tool that uses SHA-256 hashes to detect files being added, removed, or changed.
- SHA-256 hashing
- Recursive scanning
- Baseline creation
- Added/removed/changed detection
- Continuous watch mode
- Custom baseline location
- Automated tests
- Read-only monitoring
- Windows, Linux, or macOS
- Python 3.11 or newer
- Git
Install Python from https://www.python.org/downloads/ and Git from https://git-scm.com/downloads/.
Verify:
python --version
git --versionClone:
git clone https://github.com/tavishshukla/File-Integrity-Monitor.git
cd File-Integrity-MonitorCreate a virtual environment.
python -m venv .venv
.venv\\Scripts\\activatepython3 -m venv .venv
source .venv/bin/activateInstall:
python -m pip install --upgrade pip
python -m pip install -r requirements.txtWindows:
mkdir sample_data
echo Hello > sample_data\\example.txtLinux/macOS:
mkdir -p sample_data
echo "Hello" > sample_data/example.txtpython main.py baseline --path ./sample_dataA SHA-256 hash is recorded for every file.
Use a custom baseline path if desired:
python main.py baseline --path ./sample_data --baseline ./data/baseline.jsonpython main.py check --path ./sample_dataEdit a file and run the check again. You should receive a CHANGED result.
Create a new file for an ADDED result and remove a file for a REMOVED result.
python main.py watch --path ./sample_data --interval 5Stop with Ctrl+C.
- Scan the selected directory recursively.
- Calculate SHA-256 for each file.
- Save the hashes as the known-good baseline.
- Scan again later.
- Compare current hashes with the baseline.
- Report added, removed, and changed files.
The monitor never changes the files it is checking.
python -m pytestFile-Integrity-Monitor/
├── main.py
├── fim.py
├── requirements.txt
├── README.md
└── tests/
└── test_fim.py
Only monitor directories you own or are authorized to inspect. For a production-style implementation, store the baseline outside the monitored directory and protect it from unauthorized modification.
Create the baseline first with python main.py baseline --path ./sample_data, make an authorized test-file change, and then run python main.py check --path ./sample_data. The monitor reports differences without modifying monitored files.
For scripts or automated checks, use:
python main.py check --path ./sample_data --fail-on-changeWith this option, detected changes produce exit status 2; an unchanged directory still exits normally.
When using a custom baseline filename, pass the same name to the scanner so the baseline file itself is excluded from integrity hashing.