Deploying Ransomware Canary Files
When to Use
- Deploying proactive ransomware detection on file servers, NAS devices, or endpoint systems
- Building an early-warning system that detects ransomware before it encrypts business-critical data
- Supplementing EDR solutions with lightweight canary file monitoring on systems where agents cannot be deployed
- Testing ransomware incident response procedures by simulating canary file triggers
- Monitoring shared drives, home directories, and backup volumes for unauthorized file operations
Do not use as a replacement for endpoint protection, backup strategy, or network segmentation. Canary files are a detection layer, not a prevention mechanism.
Common Misconfigurations & Verification
- Decoy names that sort late:
Financial_Report_2026.docx sorts mid-alphabet, so a Z-A or A-Z enumerator may encrypt real data before reaching it. Pair each realistic name with a _AAAA_-prefixed and ~zzzz_-suffixed twin so a canary is always the first AND last file touched in each directory.
- Canaries clustered in one path: placing them only on user Desktops misses share roots and backup volumes. Seed every network-share root, Documents folder, and backup staging dir ransomware enumerates first.
- Only watching
on_modified: encrypt-and-rename ransomware writes Passwords.xlsx.locked and unlinks the original, firing on_moved/on_deleted. Confirm the handler covers created/modified/moved/deleted, not just modify.
- No process attribution / too slow: without
psutil capturing the offending PID, the alert can't drive isolation. Verify time-to-alert and that the process info is populated.
- Verification: programmatically modify, rename, and delete each canary and confirm alerts land on every channel (email, Slack, syslog) with correct before/after SHA-256 hashes; exclude backup/AV processes so they don't generate false hits.
Prerequisites
- Python 3.8+ with pip
- watchdog library (pip install watchdog)
- Write access to directories where canary files will be placed
- SMTP server credentials or Slack webhook URL for alerting
- Administrative access for placing canaries in system directories
Workflow
Step 1: Generate Canary Files
Create decoy files with realistic names and content that attract ransomware scanners. Files should have names like Passwords.xlsx, Financial_Report_2026.docx, backup_credentials.csv and contain plausible-looking but fake data. Place them in directories ransomware typically targets first: user desktops, Documents folders, network share roots, and backup paths.
Step 2: Deploy Filesystem Monitor
Use Python's watchdog library with a custom FileSystemEventHandler that watches canary file paths. The handler triggers on on_modified, on_deleted, on_moved, and on_created events for canary files. Any legitimate user or process should never touch these files, so any interaction is a high-confidence indicator of ransomware or unauthorized access.
Step 3: Configure Alert Pipeline
Wire the filesystem monitor to multiple alert channels: email via SMTP, Slack webhook POST, syslog forwarding to SIEM, and local log file. Include the triggering event type, file path, timestamp, and process information (when available) in alert payloads.
Step 4: Validate and Test
Simulate ransomware behavior by programmatically modifying, renaming, and deleting canary files to verify the detection pipeline fires correctly. Measure time-to-alert and validate alert delivery across all configured channels.
Key Concepts
| Term |
Definition |
| Canary File |
A decoy file placed in a monitored directory that triggers an alert when accessed, modified, or deleted |
| Watchdog |
Python library that monitors filesystem events using OS-native APIs (inotify on Linux, FSEvents on macOS, ReadDirectoryChangesW on Windows) |
| Honey File |
Synonym for canary file; a fake document designed to attract and detect malicious activity |
| Entropy Check |
Measuring randomness in file content to detect encryption (ransomware produces high-entropy output) |
Tools & Systems
- watchdog: Python filesystem monitoring library using OS-native event APIs
- smtplib: Python standard library for SMTP email alerting
- requests: HTTP library for Slack webhook integration
- hashlib: SHA-256 hashing for canary file integrity verification
- psutil: Process information gathering when canary file access is detected
Output Format
RANSOMWARE CANARY ALERT
========================
Timestamp: 2026-03-11T14:23:07Z
Event: FILE_MODIFIED
Canary File: /srv/shares/finance/Passwords.xlsx
Directory: /srv/shares/finance
SHA-256 Before: a3f2...8b4c
SHA-256 After: 7e91...2d3f
Alert Channels: [email, slack, syslog]
Action: Investigate immediately - potential ransomware activity
1---2name: deploying-ransomware-canary-files3description: Deploys and monitors ransomware canary files across critical directories using Python's watchdog library for real-time filesystem event detection. Places strategically named decoy files that mimic high-value targets (financial records, credentials, database exports) in locations ransomware typically enumerates first. Monitors for any read, modify, rename, or delete operations on canary files and triggers immediate alerts via email, Slack webhook, or syslog when interaction is detected, providing early warning before full encryption begins.4license: Apache-2.05---6# Deploying Ransomware Canary Files78## When to Use910- Deploying proactive ransomware detection on file servers, NAS devices, or endpoint systems11- Building an early-warning system that detects ransomware before it encrypts business-critical data12- Supplementing EDR solutions with lightweight canary file monitoring on systems where agents cannot be deployed13- Testing ransomware incident response procedures by simulating canary file triggers14- Monitoring shared drives, home directories, and backup volumes for unauthorized file operations1516**Do not use** as a replacement for endpoint protection, backup strategy, or network segmentation. Canary files are a detection layer, not a prevention mechanism.1718## Common Misconfigurations & Verification1920- **Decoy names that sort late:** `Financial_Report_2026.docx` sorts mid-alphabet, so a Z-A or A-Z enumerator may encrypt real data before reaching it. Pair each realistic name with a `_AAAA_`-prefixed and `~zzzz_`-suffixed twin so a canary is always the first AND last file touched in each directory.21- **Canaries clustered in one path:** placing them only on user Desktops misses share roots and backup volumes. Seed every network-share root, Documents folder, and backup staging dir ransomware enumerates first.22- **Only watching `on_modified`:** encrypt-and-rename ransomware writes `Passwords.xlsx.locked` and unlinks the original, firing `on_moved`/`on_deleted`. Confirm the handler covers created/modified/moved/deleted, not just modify.23- **No process attribution / too slow:** without `psutil` capturing the offending PID, the alert can't drive isolation. Verify time-to-alert and that the process info is populated.24- **Verification:** programmatically modify, rename, and delete each canary and confirm alerts land on every channel (email, Slack, syslog) with correct before/after SHA-256 hashes; exclude backup/AV processes so they don't generate false hits.2526## Prerequisites2728- Python 3.8+ with pip29- watchdog library (pip install watchdog)30- Write access to directories where canary files will be placed31- SMTP server credentials or Slack webhook URL for alerting32- Administrative access for placing canaries in system directories3334## Workflow3536### Step 1: Generate Canary Files3738Create decoy files with realistic names and content that attract ransomware scanners. Files should have names like `Passwords.xlsx`, `Financial_Report_2026.docx`, `backup_credentials.csv` and contain plausible-looking but fake data. Place them in directories ransomware typically targets first: user desktops, Documents folders, network share roots, and backup paths.3940### Step 2: Deploy Filesystem Monitor4142Use Python's watchdog library with a custom `FileSystemEventHandler` that watches canary file paths. The handler triggers on `on_modified`, `on_deleted`, `on_moved`, and `on_created` events for canary files. Any legitimate user or process should never touch these files, so any interaction is a high-confidence indicator of ransomware or unauthorized access.4344### Step 3: Configure Alert Pipeline4546Wire the filesystem monitor to multiple alert channels: email via SMTP, Slack webhook POST, syslog forwarding to SIEM, and local log file. Include the triggering event type, file path, timestamp, and process information (when available) in alert payloads.4748### Step 4: Validate and Test4950Simulate ransomware behavior by programmatically modifying, renaming, and deleting canary files to verify the detection pipeline fires correctly. Measure time-to-alert and validate alert delivery across all configured channels.5152## Key Concepts5354| Term | Definition |55|------|------------|56| **Canary File** | A decoy file placed in a monitored directory that triggers an alert when accessed, modified, or deleted |57| **Watchdog** | Python library that monitors filesystem events using OS-native APIs (inotify on Linux, FSEvents on macOS, ReadDirectoryChangesW on Windows) |58| **Honey File** | Synonym for canary file; a fake document designed to attract and detect malicious activity |59| **Entropy Check** | Measuring randomness in file content to detect encryption (ransomware produces high-entropy output) |6061## Tools & Systems6263- **watchdog**: Python filesystem monitoring library using OS-native event APIs64- **smtplib**: Python standard library for SMTP email alerting65- **requests**: HTTP library for Slack webhook integration66- **hashlib**: SHA-256 hashing for canary file integrity verification67- **psutil**: Process information gathering when canary file access is detected6869## Output Format7071```72RANSOMWARE CANARY ALERT73========================74Timestamp: 2026-03-11T14:23:07Z75Event: FILE_MODIFIED76Canary File: /srv/shares/finance/Passwords.xlsx77Directory: /srv/shares/finance78SHA-256 Before: a3f2...8b4c79SHA-256 After: 7e91...2d3f80Alert Channels: [email, slack, syslog]81Action: Investigate immediately - potential ransomware activity82```