Skip to content

Instantly share code, notes, and snippets.

@vikasprogrammer
Created December 24, 2021 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikasprogrammer/de3da71c8541c0636e9e2eaae73f8bf3 to your computer and use it in GitHub Desktop.
Save vikasprogrammer/de3da71c8541c0636e9e2eaae73f8bf3 to your computer and use it in GitHub Desktop.
Monitor a file for changes and notifies via slack when its changed.
<?php
$changed = false;
$hash = "5718fb07bde7a1c585c533d1b720cf8b";
$filename = "index.php";
while(true) {
$current_hash = md5(file_get_contents($filename));
if($current_hash != $hash) {
if($changed == false) {
echo time() . "hacked\n";
shell_exec("curl -X POST --data-urlencode \"payload={'channel': '#nmon', 'username': 'newfilebot', 'text': '$filename changed `tail /var/logs/apache2/access.log`', 'icon_emoji': ':ghost:'}\" https://hooks.slack.com/services/xxx/xxx/xxxx");
}
$changed = true;
} else {
if($changed == true) { echo "restored\n"; }
$changed = false;
}
sleep(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment