关于 deploying-decoy-files-for-ransomware-detection
用于在终端和文件共享中部署监控诱饵文件以检测勒索软件活动的安全技能,介绍文件选址、文件系统监控、告警路由和受控验证,并说明诱饵不能替代预防措施。
主要功能
- 01规划诱饵文件放置位置
- 02创建逼真的诱饵文件
- 03监控文件更改与删除
- 04将告警发送至响应系统
- 05通过受控测试验证检测
适用场景
- 01为文件共享增加勒索软件告警
- 02测试 SOC 或 SIEM 告警路由
- 03通过安全的诱饵变更检查响应操作
- 04监控高价值目录
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill deploying-decoy-files-for-ransomware-detection安装后在 Claude Code 中输入/deploying-decoy-files-for-ransomware-detection确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEreferences/api-reference.mdscripts/agent.py详细介绍
部署诱饵文件以检测勒索软件
适用场景
- 在文件服务器或终端上设置勒索软件早期预警检测
- 通过基于欺骗的检测层补充 EDR/AV,以捕获未知勒索软件变种
- 创建高保真度的勒索软件告警,误报率极低(合法用户没有理由触碰诱饵文件)
- 通过验证金丝雀文件修改是否能触发预期告警流水线,来测试勒索软件响应流程
- 使用可指示未授权加密活动的绊线文件保护高价值文件共享(财务、人力资源、法务)
请勿将诱饵文件作为唯一的勒索软件防御手段。它们是检测机制,而非预防机制,应作为备份、EDR 和访问控制的补充。
前置条件
- Python 3.8+ 及
watchdog库,用于跨平台文件系统监控 - 对目标文件共享或终端的管理员访问权限,以便放置金丝雀文件
- 文件完整性监控(FIM)工具或 SIEM 集成,用于告警路由
- 了解目标目录结构,以便将金丝雀文件放置在高价值位置
- Windows:NTFS 更改日志或 ReadDirectoryChangesW API 访问权限
- Linux:内核支持 inotify(现代内核中为标准配置)
工作流
步骤 1:设计金丝雀文件策略
规划文件放置位置以实现最大检测覆盖:
Canary File Placement Strategy:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Naming Convention:
- Use names that sort FIRST and LAST alphabetically in each directory
- Ransomware typically enumerates directories A-Z or Z-A
- Examples: _AAAA_budget_2024.docx, ~zzzz_report_final.xlsx
Placement Locations:
- Root of every file share (\\server\share\_AAAA_canary.docx)
- Desktop, Documents, Downloads on each endpoint
- Department-specific shares (Finance, HR, Legal)
- Backup staging directories
- Home directories of high-privilege accounts
File Types:
- .docx, .xlsx, .pdf (most targeted by ransomware)
- .sql, .bak (database files, high value)
- Mix of file types to detect ransomware that targets specific extensions
步骤 2:生成逼真的金丝雀文件
创建具有逼真内容和元数据的诱饵文件:
import os
import time
def create_canary_docx(filepath, content="Q4 Financial Summary - Confidential"):
"""Create a realistic .docx canary file using python-docx."""
from docx import Document
doc = Document()
doc.add_heading("Financial Report - CONFIDENTIAL", level=1)
doc.add_paragraph(content)
doc.add_paragraph(f"Generated: {time.strftime('%Y-%m-%d')}")
doc.save(filepath)
def create_canary_txt(filepath):
"""Create a simple text canary with known content for hash verification."""
content = "CANARY_TOKEN_DO_NOT_MODIFY\n"
content += f"Created: {time.strftime('%Y-%m-%dT%H:%M:%S')}\n"
content += "This file is monitored for unauthorized changes.\n"
with open(filepath, "w") as f:
f.write(content)
步骤 3:部署文件系统监视器
监控金丝雀文件的任何修改、重命名或删除:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class CanaryHandler(FileSystemEventHandler):
def __init__(self, canary_paths, alert_callback):
self.canary_paths = set(canary_paths)
self.alert_callback = alert_callback
def on_modified(self, event):
if event.src_path in self.canary_paths:
self.alert_callback("MODIFIED", event.src_path)
def on_deleted(self, event):
if event.src_path in self.canary_paths:
self.alert_callback("DELETED", event.src_path)
def on_moved(self, event):
if event.src_path in self.canary_paths:
self.alert_callback("RENAMED", event.src_path)
步骤 4:配置告警与响应
定义金丝雀文件被触发时的自动化响应:
Alert Response Matrix:
━━━━━━━━━━━━━━━━━━━━━
Event: Canary MODIFIED
→ Severity: CRITICAL
→ Action: Alert SOC, identify modifying process (PID), isolate endpoint
Event: Canary DELETED
→ Severity: HIGH
→ Action: Alert SOC, check for ransomware note in same directory
Event: Canary RENAMED (new extension added)
→ Severity: CRITICAL
→ Action: Alert SOC, check extension against known ransomware extensions
→ Automated: Kill modifying process, disable network interface
Event: Multiple canaries triggered within 60 seconds
→ Severity: EMERGENCY
→ Action: Network-wide isolation, activate incident response plan
步骤 5:验证检测覆盖范围
测试金丝雀文件能否检测到实际的勒索软件行为:
# Simulate ransomware encryption (safe test - modifies canary content)
echo "ENCRYPTED_BY_TEST" > /path/to/canary/_AAAA_budget.docx
# Simulate ransomware rename (adds extension)
mv /path/to/canary/report.xlsx /path/to/canary/report.xlsx.locked
# Verify alerts were generated in SIEM/alerting system
验证
- 使用存储的哈希基线确认所有金丝雀文件均存在且未被修改
- 验证修改任何金丝雀文件都能在预期时间内(30 秒以内)生成告警
- 通过受控修改测试告警到 SOC/SIEM 的路由是否正常工作
- 验证自动化响应操作(终止进程、网络隔离)是否正确执行
- 检查金丝雀文件能否在正常的备份和恢复操作后保留
- 确保合法用户和进程被排除在误报告警之外(备份 Agent、AV 扫描)
关键概念
| 术语 | 定义 |
|---|---|
| 金丝雀文件 | 放置在受监控目录中的诱饵文件,任何访问或修改都会触发告警,作为未授权活动的绊线 |
| 蜜标 | 更广泛的欺骗工件类别(文件、凭证、数据库记录),设计为在被访问时发出告警 |
| 文件完整性监控 | 持续监控文件属性(哈希、大小、权限、时间戳)以检测未授权更改 |
| ReadDirectoryChangesW | 用于监控目录中文件系统更改的 Windows API;watchdog 库在 Windows 上使用该 API |
| inotify | 用于监控文件系统事件的 Linux 内核子系统;提供文件更改的近乎即时通知 |
工具与系统
- watchdog (Python):跨平台文件系统事件监控库,支持 Windows、Linux 和 macOS
- Canarytokens (Thinkst):免费托管服务,用于生成各种类型的金丝雀令牌,包括文件、URL 和 DNS 令牌
- OSSEC/Wazuh:开源 HIDS,内置文件完整性监控和告警功能
- Elastic Endpoint:内部使用金丝雀文件进行勒索软件防护和密钥捕获
- Sysmon:Windows 系统监视器,记录文件创建事件(事件 ID 11)以用于金丝雀文件监控
评论
支持 Markdown