watchdog
(pour surveiller les modifications dans un dossier), os
, time
, logging
et autres.import timea fait :
import os
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class RansomwareHandler(FileSystemEventHandler):
def init(self):
self.modified_files = set()
self.deleted_files = set()
def on_modified(self, event):
if not event.is_directory:
self.modified_files.add(event.src_path)
print("Modified:", event.src_path)
def on_deleted(self, event):
if not event.is_directory:
self.deleted_files.add(event.src_path)
print("Deleted:", event.src_path)
def monitor(path_to_watch, check_interval=10):
event_handler = RansomwareHandler()
observer = Observer()
observer.schedule(event_handler, path=path_to_watch, recursive=True)
observer.start()
try:
while True:
time.sleep(check_interval)
# Logique simple : si trop de fichiers ont été modifiés ou supprimés pendant l'intervalle
if len(event_handler.modified_files) > 100 or len(event_handler.deleted_files) > 10:
print("Warning: Potential ransomware activity detected!")
# On peut enregistrer les événements
event_handler.modified_files.clear()
event_handler.deleted_files.clear()
except KeyboardInterrupt:
observer.stop()
observer.join()
if name == "main":
path = "/path/to/watch"
monitor(path, check_interval=10)📌 Ce que ç
🟢 Surveille le répertoire spécifié pour les événements de modification et suppression de fichiers🟢 Enregistre ces événements dans la console et dans un fichier (par exemple ransomware_detection.log)🟢 Vérifie périodiquement, si beaucoup de modifications/suppressions ont lieu — affiche un avertissement d'attaque potentielle
#scripts
Please open Telegram to view this post
VIEW IN TELEGRAM
GitHub
GitHub - mrgagan17/Ransomware-Detection-Tool: A simple Python tool to monitor file changes and detect ransomware-like behavior…
A simple Python tool to monitor file changes and detect ransomware-like behavior by tracking unusual activities in a specified folder. - mrgagan17/Ransomware-Detection-Tool