使用Cuckoo Sandbox分析恶意软件行为 是做什么的?
何时使用
- 可疑样本通过了静态分析筛选,需要在受控环境中进行行为观察
- 你需要捕获恶意软件执行时的网络流量、文件掉落、注册表修改和API调用
- 需要确定完整的感染链,包括第二阶段payload下载和持久化机制
- 基于观察到的运行时行为生成行为签名和YARA规则
- 需要一致报告的批量恶意软件样本自动化分析
请勿使用 当样本是已知的勒索软件变种,可能通过网络共享在配置不当的沙箱中传播时;请先验证网络隔离。
先决条件
- 在专用分析服务器上安装Cuckoo Sandbox 3.x(推荐Ubuntu 22.04)
- 配置Windows 10/11快照的客户机VM(已安装Cuckoo agent,在干净状态下拍摄快照)
- 配置VirtualBox、KVM或VMware作为Cuckoo虚拟化后端
- 配置InetSim或FakeNet-NG的隔离网络,用于模拟互联网服务
- 集成Suricata或Snort,在分析期间进行网络级签名匹配
- 足够的磁盘空间用于PCAP捕获和内存转储(建议至少500 GB)
工作流程
步骤 1:提交样本到Cuckoo
提交恶意软件样本进行自动化分析:
# 通过命令行提交
cuckoo submit /path/to/suspect.exe
# 指定分析超时时间(300秒)提交
cuckoo submit --timeout 300 /path/to/suspect.exe
# 指定虚拟机和分析包提交
cuckoo submit --machine win10_x64 --package exe --timeout 300 /path/to/suspect.exe
# 通过REST API提交
curl -F "[email protected]" -F "timeout=300" -F "machine=win10_x64" \
http://localhost:8090/tasks/create/file
# 提交URL进行分析
curl -F "url=http://malicious-site.com/payload" -F "timeout=300" \
http://localhost:8090/tasks/create/url
# 检查任务状态
curl http://localhost:8090/tasks/view/1 | jq '.task.status'
步骤 2:实时监控执行
跟踪分析进度并观察实时行为:
# 查看Cuckoo分析日志
tail -f /opt/cuckoo/log/cuckoo.log
# 监控分析任务状态
cuckoo status
# 访问Cuckoo Web界面查看实时截图和进程树
# 导航到 http://localhost:8080/analysis/<task_id>/
执行过程中需要关注的关键行为事件:
- 进程创建链(父子关系)
- 对外部IP的网络连接尝试
- 临时目录或系统文件夹中的文件掉落
- 对Run键或服务项的注册表修改
- 与加密(CryptEncrypt)、注入(WriteProcessMemory)或规避相关的API调用
步骤 3:分析进程活动
从Cuckoo报告中查看进程树和API调用跟踪:
# 程序化解析Cuckoo JSON报告
import json
with open("/opt/cuckoo/storage/analyses/1/reports/report.json") as f:
report = json.load(f)
# 进程树分析
for process in report["behavior"]["processes"]:
pid = process["pid"]
ppid = process["ppid"]
name = process["process_name"]
print(f"PID: {pid} PPID: {ppid} Name: {name}")
# 提取可疑API调用
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请求:
# 从Cuckoo报告中进行网络分析
network = report["network"]
# DNS解析
print("DNS Queries:")
for dns in network.get("dns", []):
print(f" {dns['request']} -> {dns.get('answers', [])}")
# HTTP请求
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连接
print("\nTCP Connections:")
for tcp in network.get("tcp", []):
print(f" {tcp['src']}:{tcp['sport']} -> {tcp['dst']}:{tcp['dport']}")
# 提取PCAP用于更深入的Wireshark分析
# PCAP路径: /opt/cuckoo/storage/analyses/1/dump.pcap
步骤 5:检查文件系统和注册表更改
记录持久化机制和掉落文件:
# 文件操作
print("Files Created/Modified:")
for f in report["behavior"].get("summary", {}).get("files", []):
print(f" {f}")
# 掉落文件及其哈希值
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']}")
# 注册表修改
print("\nRegistry Keys Modified:")
for key in report["behavior"].get("summary", {}).get("keys", []):
print(f" {key}")
步骤 6:查看签名和评分
检查Cuckoo的行为签名和威胁评分:
# 触发的行为签名
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']}")
# 总体评分
score = report.get("info", {}).get("score", 0)
print(f"\nOverall Threat Score: {score}/10")
步骤 7:提取内存转储工件
分析执行期间捕获的完整内存转储:
# 内存转储保存在:
# /opt/cuckoo/storage/analyses/1/memory.dmp
# 使用Volatility分析内存转储
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
关键概念
| 术语 | 定义 |
|---|---|
| 动态分析 | 在受控环境中执行恶意软件以观察其运行时行为,包括系统调用、网络活动和文件操作 |
| 沙箱规避 | 恶意软件用于检测虚拟/沙箱环境并改变行为以逃避分析的技术(睡眠计时器、VM检查、用户交互检查) |
| API挂钩 | Cuckoo截获恶意软件所作出的Windows API调用的方法,用于记录函数名、参数和返回值 |
| InetSim | 互联网服务模拟工具,在隔离的分析网络中响应恶意软件的网络请求(HTTP、DNS、SMTP) |
| 进程注入 | 恶意软件将代码注入合法进程的技术;通过监控VirtualAllocEx和WriteProcessMemory API序列来检测 |
| 行为签名 | 基于规则的检测,将特定API调用序列、文件操作或网络活动与已知恶意软件行为匹配 |
| 分析包 | Cuckoo模块,定义如何在客户机VM中执行特定文件类型(exe、dll、pdf、doc)以正确捕获行为 |
工具与系统
- Cuckoo Sandbox:开源自动化恶意软件分析系统,提供行为报告、网络捕获和内存转储
- InetSim:互联网服务模拟套件,为隔离的恶意软件分析网络提供虚假的HTTP、DNS、SMTP等服务
- FakeNet-NG:FLARE团队的网络模拟工具,拦截并重定向所有网络流量以供分析
- Suricata:网络IDS/IPS,集成Cuckoo用于对恶意网络流量进行实时基于签名的检测
- Volatility:内存取证框架,用于分析Cuckoo分析期间捕获的内存转储
常见场景
场景:分析多阶段释放器
上下文:静态分析显示一个打包的可执行文件,导入少且熵值高。该样本需要在沙箱中执行以观察解包、payload交付和C2建立过程。
方法:
- 提交样本到Cuckoo,设置较长超时(600秒)以捕获慢速行为
- 查看进程树中的子进程创建(释放器生成payload进程)
- 识别在%TEMP%、%APPDATA%或系统目录中掉落的文件
- 提取掉落文件并计算哈希值以供单独分析
- 映射网络连接以识别初始执行后联系的C2基础设施
- 在注册表修改中检查持久化机制(Run键、计划任务、服务)
- 将行为签名与已知恶意软件家族进行比较
陷阱:
- 使用不足的分析超时,导致沙箱在第二阶段payload执行前终止
- 未配置InetSim响应DNS和HTTP请求,阻止恶意软件在C2签入后继续执行
- 忽略沙箱规避检测;如果样本立即退出,可能正在检测虚拟环境
- 未单独分析掉落文件;初始释放器可能不如最终payload有趣
输出格式
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