关于 analyzing-malware-behavior-with-cuckoo-sandbox
这是一项使用 Cuckoo Sandbox 运行可疑文件并检查其运行行为的分析技能,面向恶意软件分析人员。它指导追踪进程、网络活动、文件与注册表变化、行为特征及捕获的内存。
主要功能
- 01提交样本并监控执行
- 02追踪进程活动和 API 调用
- 03查看 DNS 与网络流量
- 04检查文件和注册表变更
- 05检查行为特征
- 06分析捕获的内存
适用场景
- 01观察加壳样本解包及载荷投递
- 02追踪持久化机制和命令控制活动
- 03规范批量样本分析流程
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill analyzing-malware-behavior-with-cuckoo-sandbox安装后在 Claude Code 中输入/analyzing-malware-behavior-with-cuckoo-sandbox确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEreferences/api-reference.mdscripts/agent.py详细介绍
使用 Cuckoo Sandbox 分析恶意软件行为
适用场景
- 可疑样本通过了静态分析分诊,需要在受控环境中进行行为观察
- 需要捕获恶意软件执行期间的网络流量、文件投放、注册表修改和 API 调用
- 确定完整的感染链,包括下载第二阶段载荷和持久化机制
- 根据观察到的运行时活动生成行为特征和 YARA 规则
- 对需要一致报告的大批量恶意软件样本进行自动化分析
不要使用此方法分析可能通过网络共享传播的已知勒索软件变种,尤其是在沙箱配置不当时;请先确认网络隔离。
前提条件
- 在专用分析服务器上安装 Cuckoo Sandbox 3.x(推荐 Ubuntu 22.04)
- 配置来宾虚拟机,并创建 Windows 10/11 快照(已安装 Cuckoo 代理,并在干净状态下创建快照)
- 将 VirtualBox、KVM 或 VMware 配置为 Cuckoo 虚拟化后端
- 使用 InetSim 或 FakeNet-NG 模拟互联网服务的隔离网络
- 集成 Suricata 或 Snort,以便在分析期间进行网络级特征匹配
- 为 PCAP 捕获文件和内存转储预留足够的磁盘空间(建议至少 500 GB)
工作流
步骤 1:向 Cuckoo 提交样本
提交恶意软件样本以进行自动化分析:
# Submit via command line
cuckoo submit /path/to/suspect.exe
# Submit with specific analysis timeout (300 seconds)
cuckoo submit --timeout 300 /path/to/suspect.exe
# Submit with specific VM and analysis package
cuckoo submit --machine win10_x64 --package exe --timeout 300 /path/to/suspect.exe
# Submit via REST API
curl -F "[email protected]" -F "timeout=300" -F "machine=win10_x64" \
http://localhost:8090/tasks/create/file
# Submit URL for analysis
curl -F "url=http://malicious-site.com/payload" -F "timeout=300" \
http://localhost:8090/tasks/create/url
# Check task status
curl http://localhost:8090/tasks/view/1 | jq '.task.status'
步骤 2:实时监控执行情况
跟踪分析进度并观察实时行为:
# Watch Cuckoo analysis log
tail -f /opt/cuckoo/log/cuckoo.log
# Monitor analysis task status
cuckoo status
# Access Cuckoo web interface for live screenshots and process tree
# Navigate to http://localhost:8080/analysis/<task_id>/
执行期间需要关注的关键行为事件:
- 进程创建链(父子关系)
- 尝试连接外部 IP 的网络连接
- 在临时目录或系统文件夹中投放的文件
- 对 Run 键或服务项的注册表修改
- 与加密(CryptEncrypt)、注入(WriteProcessMemory)或规避相关的 API 调用
步骤 3:分析进程活动
查看 Cuckoo 报告中的进程树和 API 调用跟踪:
# Parse Cuckoo JSON report programmatically
import json
with open("/opt/cuckoo/storage/analyses/1/reports/report.json") as f:
report = json.load(f)
# Process tree analysis
for process in report["behavior"]["processes"]:
pid = process["pid"]
ppid = process["ppid"]
name = process["process_name"]
print(f"PID: {pid} PPID: {ppid} Name: {name}")
# Extract suspicious API calls
for call in process["calls"]:
api = call["api"]
if api in ["CreateRemoteThread", "VirtualAllocEx", "WriteProcessMemory",
"NtCreateThreadEx", "RegSetValueExA", "URLDownloadToFileA"]:
args = {arg["name"]: arg["value"] for arg in call["arguments"]}
print(f" [!] {api}({args})")
步骤 4:检查网络活动
检查网络连接、DNS 查询和 HTTP 请求:
# Network analysis from Cuckoo report
network = report["network"]
# DNS resolutions
print("DNS Queries:")
for dns in network.get("dns", []):
print(f" {dns['request']} -> {dns.get('answers', [])}")
# HTTP requests
print("\nHTTP Requests:")
for http in network.get("http", []):
print(f" {http['method']} {http['uri']} (Host: {http['host']})")
if http.get("body"):
print(f" Body: {http['body'][:200]}")
# TCP connections
print("\nTCP Connections:")
for tcp in network.get("tcp", []):
print(f" {tcp['src']}:{tcp['sport']} -> {tcp['dst']}:{tcp['dport']}")
# Extract PCAP for deeper Wireshark analysis
# PCAP location: /opt/cuckoo/storage/analyses/1/dump.pcap
步骤 5:检查文件系统和注册表更改
记录持久化机制和投放的文件:
# File operations
print("Files Created/Modified:")
for f in report["behavior"].get("summary", {}).get("files", []):
print(f" {f}")
# Dropped files with hashes
print("\nDropped Files:")
for dropped in report.get("dropped", []):
print(f" Path: {dropped['filepath']}")
print(f" SHA-256: {dropped['sha256']}")
print(f" Size: {dropped['size']} bytes")
print(f" Type: {dropped['type']}")
# Registry modifications
print("\nRegistry Keys Modified:")
for key in report["behavior"].get("summary", {}).get("keys", []):
print(f" {key}")
步骤 6:查看特征和评分
检查 Cuckoo 的行为特征和威胁评分:
# Behavioral signatures triggered
print("Triggered Signatures:")
for sig in report.get("signatures", []):
severity = sig["severity"]
name = sig["name"]
description = sig["description"]
marker = "[!]" if severity >= 3 else "[*]"
print(f" {marker} [{severity}/5] {name}: {description}")
for mark in sig.get("marks", []):
if mark.get("call"):
print(f" API: {mark['call']['api']}")
if mark.get("ioc"):
print(f" IOC: {mark['ioc']}")
# Overall score
score = report.get("info", {}).get("score", 0)
print(f"\nOverall Threat Score: {score}/10")
步骤 7:提取内存转储中的工件
分析执行期间捕获的完整内存转储:
# Memory dump is saved at:
# /opt/cuckoo/storage/analyses/1/memory.dmp
# Use Volatility to analyze the memory dump
vol3 -f /opt/cuckoo/storage/analyses/1/memory.dmp windows.pslist
vol3 -f /opt/cuckoo/storage/analyses/1/memory.dmp windows.malfind
vol3 -f /opt/cuckoo/storage/analyses/1/memory.dmp windows.netscan
核心概念
| 术语 | 定义 |
|---|---|
| 动态分析 | 在受控环境中执行恶意软件,以观察其运行时行为,包括系统调用、网络活动和文件操作 |
| 沙箱规避 | 恶意软件用于检测虚拟机或沙箱环境并改变行为以逃避分析的技术(休眠计时器、虚拟机检查、用户交互检查) |
| API 挂钩 | Cuckoo 拦截恶意软件发出的 Windows API 调用并记录函数名称、参数和返回值的方法 |
| InetSim | 互联网服务模拟工具,可在隔离分析网络中响应恶意软件的网络请求(HTTP、DNS、SMTP) |
| 进程注入 | 恶意软件将代码注入合法进程的技术;可通过监控 VirtualAllocEx 和 WriteProcessMemory API 调用序列检测 |
| 行为特征 | 基于规则的检测,通过匹配特定的 API 调用、文件操作或网络活动序列来识别已知恶意软件行为 |
| 分析包 | Cuckoo 模块,用于定义如何在来宾虚拟机中执行特定文件类型(exe、dll、pdf、doc),以正确捕获其行为 |
工具与系统
- Cuckoo Sandbox:开源的自动化恶意软件分析系统,可提供行为报告、网络捕获数据和内存转储
- InetSim:互联网服务模拟套件,可为隔离的恶意软件分析网络提供伪造的 HTTP、DNS、SMTP 和其他服务
- FakeNet-NG:FLARE 团队的网络模拟工具,可拦截并重定向所有网络流量以供分析
- Suricata:与 Cuckoo 集成的网络 IDS/IPS,可基于特征码实时检测恶意网络流量
- Volatility:内存取证框架,用于分析 Cuckoo 分析过程中捕获的内存转储
常见场景
场景:分析多阶段下载器
背景:静态分析发现一个经过加壳的可执行文件,其导入项极少且熵值很高。需要在沙箱中执行样本,以观察其解包、载荷投放和 C2 建立过程。
方法:
- 将样本提交给 Cuckoo,并延长超时时间(600 秒),以捕获延迟触发的行为
- 检查进程树中的子进程创建情况(下载器生成载荷进程)
- 在 %TEMP%、%APPDATA% 或系统目录中查找投放的文件
- 提取投放的文件并计算哈希值,以便单独分析
- 对照网络连接,识别初次执行后联系的 C2 基础设施
- 检查注册表修改中是否存在持久化机制(Run 键、计划任务、服务)
- 将行为特征与已知恶意软件家族进行比对
注意事项:
- 分析超时时间不足,导致沙箱在第二阶段载荷执行前终止
- 未配置 InetSim 响应 DNS 和 HTTP 请求,导致恶意软件无法通过 C2 签到继续运行
- 忽略沙箱规避检测;如果样本立即退出,可能是检测到了虚拟环境
- 未单独分析投放的文件;相比最终载荷,初始下载器可能不那么值得关注
输出格式
DYNAMIC ANALYSIS REPORT - CUCKOO SANDBOX
==========================================
Task ID: 1547
Sample: suspect.exe (SHA-256: e3b0c44298fc1c149afbf4c8996fb924...)
Analysis Time: 300 seconds
VM: win10_x64 (Windows 10 21H2)
Score: 8.5/10
PROCESS TREE
suspect.exe (PID: 2184)
└── cmd.exe (PID: 3456)
└── powershell.exe (PID: 4012)
└── svchost_fake.exe (PID: 4568)
FILE SYSTEM ACTIVITY
[CREATED] C:\Users\Admin\AppData\Local\Temp\payload.dll
[CREATED] C:\Windows\System32\svchost_fake.exe
[MODIFIED] C:\Windows\System32\drivers\etc\hosts
REGISTRY MODIFICATIONS
[SET] HKCU\Software\Microsoft\Windows\CurrentVersion\Run\WindowsUpdate = "C:\Windows\System32\svchost_fake.exe"
[SET] HKLM\SYSTEM\CurrentControlSet\Services\FakeService\ImagePath = "C:\Windows\System32\svchost_fake.exe"
NETWORK ACTIVITY
DNS: update.malicious[.]com -> 185.220.101.42
HTTP: POST hxxps://185.220.101[.]42/gate.php (beacon)
TCP: 10.0.2.15:49152 -> 185.220.101.42:443 (237 connections)
BEHAVIORAL SIGNATURES
[!] [4/5] injection_createremotethread: Injects code into remote process
[!] [4/5] persistence_autorun: Modifies Run registry key for persistence
[!] [3/5] network_cnc_http: Performs HTTP C2 communication
[*] [2/5] antiav_detectfile: Checks for antivirus product files
DROPPED FILES
payload.dll SHA-256: abc123... Size: 98304 Type: PE32 DLL
svchost_fake.exe SHA-256: def456... Size: 184320 Type: PE32 EXE
评论
支持 Markdown