Skip to content

foiovituh/hash-watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” HashWatcher

GitHub License

A cross-platform file integrity monitoring tool that detects file changes using SHA-256 hashes.

banner

πŸ“¦ Installation

Build the project:

go build -o hash-watcher cmd/main.go

The binary should be generated from the project's root directory.

πŸ’‘ How It Works

HashWatcher monitors files by calculating their SHA-256 hashes.

Whenever a monitored file changes (even by a single byte) the generated hash changes as well. By comparing the current hash with a previously trusted hash, HashWatcher detects modifications and can optionally send Slack notifications.

Note: HashWatcher detects file modifications by comparing SHA-256 hashes. While this is an effective way to identify changes in file contents, it is not a complete file integrity or security solution. For example, if both a file and its trusted reference hash are modified by an attacker, the change cannot be detected. HashWatcher should therefore be used as one layer within a broader monitoring strategy.

βš™οΈ Configuration

Create a JSON configuration file for each directory you want to monitor.

Example:

{
  "directoryPath": "/full/path/to/directory/",
  "fileNames": [],
  "checkFrequencyInSeconds": 60
}

To monitor only specific files:

{
  "directoryPath": "/full/path/to/directory/",
  "fileNames": [
    "file-1.txt",
    "file-2.txt"
  ],
  "checkFrequencyInSeconds": 60
}

To enable Slack notifications:

{
  "directoryPath": "/full/path/to/directory/",
  "fileNames": [
    "file-1.txt",
    "file-2.txt"
  ],
  "checkFrequencyInSeconds": 60,
  "notification": {
    "endpoint": "CXXXXXXXXXX",
    "token": "xoxb-xxxxxxxxxxxxxxxxxxxxxxxx"
  }
}

πŸš€ Usage

Run HashWatcher by passing the configuration file:

./hash-watcher /full/path/to/configuration/settings.json

Example output:

2024/07/09 11:44:43 => Watching...
2024/07/09 11:45:43 => file-1.txt was modified!
  - Before: e6de32585e70330a8de848b7b7859911e1e108e00dd6527391533853dd7c9409
  - Now:    ea6fcfe57703205da4d1b74ec99a8c67f721b2ab2e9c31d2222da066606d5d44

πŸ’¬ Slack Integration

HashWatcher can send notifications to Slack using a Slack App.

For more information about Slack manifests, see:

https://api.slack.com/reference/manifests

Create the Slack App

  1. Go to https://api.slack.com/apps and click Create New App.

create_an_app

  1. Choose From an app manifest and select your workspace.

pick_a_workspace

  1. Copy the manifest located at:
doc/slack/slack_app_manifest.yml

Paste it into Slack.

enter_app_manifest_bellow

  1. Review the configuration and create the app.

review_summary_and_create_your_app

  1. Open Settings β†’ Basic Information and optionally set the project logo (doc/slack/logo.png) as the app icon.

display_information

  1. Go to Features β†’ OAuth & Permissions and copy the generated Bot User OAuth Token.

oauth_tokens_for_your_workspace

  1. Finally, add the app to the desired Slack channel and use the channel ID (endpoint) together with the OAuth token in your HashWatcher configuration.

πŸ—ΊοΈ Roadmap

  • Monitor subdirectories
  • Custom monitoring schedules
  • Unit tests
  • Functional tests

⭐ Support the Project

If you like this project or find it useful, please give it a star! It helps increase its visibility and supports future development.

πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.