
Malware Analysis Methodology
- 24 installs
- 1.6k repo stars
- Updated July 19, 2026
- wgpsec/aboutsecurity
Helps with ai & agent building tasks during AI-assisted development.
About
malware-analysis-methodology is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted coding.
- malware-analysis-methodology
- AI & Agent Building
- AI-coding skill
Malware Analysis Methodology by the numbers
- 24 all-time installs (skills.sh)
- +2 installs in the week ending Jul 27, 2026 (Skillselion tracking)
- Ranked #9,876 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/wgpsec/aboutsecurity --skill malware-analysis-methodologyAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 24 |
|---|---|
| repo stars | ★ 1.6k |
| Last updated | July 19, 2026 |
| Repository | wgpsec/aboutsecurity ↗ |
What it does
Helps with ai & agent building tasks during AI-assisted development.
Files
恶意软件分析方法论
红队价值:理解样本如何被分析 → 知道哪些特征会暴露 → 改进免杀和 OPSEC
⛔ 深入参考
- PE/ELF 静态分析详细命令与脚本 → references/static-analysis.md
- 动态分析与沙箱对抗 → references/dynamic-analysis.md
---
Phase 0: 样本处理与安全准备
⛔ NEVER 在非隔离环境执行样本!
# 计算哈希
sha256sum sample.bin
md5sum sample.bin
# 基础识别
file sample.bin
strings -n 6 sample.bin | head -50
# 检查是否加壳
upx -t sample.bin # UPX
die sample.bin # Detect It Easy决策:
样本类型?
├─ PE (Windows) → Phase 1A
├─ ELF (Linux) → Phase 1B
├─ Mach-O (macOS) → Phase 1C
├─ Shellcode/内存 dump → Phase 2(直接动态分析)
└─ 脚本(PS1/VBS/JS/Python)→ 直接静态阅读代码Phase 1A: PE 静态分析
# PE 头信息
python3 -c "
import pefile
pe = pefile.PE('sample.exe')
print(f'Compiled: {pe.FILE_HEADER.TimeDateStamp}')
print(f'Sections: {len(pe.sections)}')
for s in pe.sections:
print(f' {s.Name.decode().strip(chr(0)):8} Entropy:{s.get_entropy():.2f} VSize:{s.Misc_VirtualSize}')
print(f'Imports: {len(pe.DIRECTORY_ENTRY_IMPORT)}')
for entry in pe.DIRECTORY_ENTRY_IMPORT:
print(f' {entry.dll.decode()}')
"关键 Import 特征映射:
| Import API | 功能推断 |
|---|---|
| VirtualAlloc + WriteProcessMemory | 进程注入 |
| CreateRemoteThread | 远程线程注入 |
| WinHttpOpen / InternetOpenA | 网络通信/C2 |
| CryptEncrypt / BCryptEncrypt | 加密(可能是勒索软件) |
| RegSetValueEx + RunKey | 持久化 |
| NtQueryInformationProcess | 反调试 |
| IsDebuggerPresent | 反调试 |
| GetTickCount / QueryPerformanceCounter | 沙箱检测 |
Phase 1B: ELF 静态分析
readelf -h sample # ELF 头
readelf -S sample # 节表
readelf -d sample # 动态链接
nm sample 2>/dev/null # 符号表(未 strip 时)
# 高熵节 = 可能加密/压缩
python3 -c "
from elftools.elf.elffile import ELFFile
import math
from collections import Counter
with open('sample','rb') as f:
elf = ELFFile(f)
for s in elf.iter_sections():
data = s.data()
if len(data) > 100:
entropy = -sum((c/len(data))*math.log2(c/len(data)) for c in Counter(data).values())
if entropy > 7.0:
print(f'[!] 高熵: {s.name} entropy={entropy:.2f}')
"Phase 2: 动态分析决策
目标:观察样本运行时行为
├─ 有沙箱环境 → 直接投递(AnyRun/Cuckoo/CAPE)
├─ 本地 VM → strace/procmon + 网络抓包
└─ 仅有样本无法执行 → 纯静态(Ghidra/IDA)Windows 动态分析:
1. Procmon 过滤进程名 → 文件/注册表/网络操作
2. Wireshark/fakenet → C2 通信
3. API Monitor → 关键 API 调用序列Linux 动态分析:
strace -f -e trace=network,process,file -o trace.log ./sample
ltrace -f -o ltrace.log ./sample
# 另一终端监控
ss -tlnp # 监听端口
ss -tnp # 外连Phase 3: IOC 提取清单
⛔ 必须提取以下所有类型 IOC:
- [ ] 文件哈希(MD5 + SHA256)
- [ ] 网络指标(IP/域名/URL/URI 路径)
- [ ] 文件系统指标(创建/修改的文件路径)
- [ ] 注册表指标(Windows)
- [ ] 进程指标(进程名、命令行、父子关系)
- [ ] 持久化机制(启动项/计划任务/服务/cron)
- [ ] MITRE ATT&CK TTP 映射
Phase 4: 红队反思(OPSEC 审查)
分析完成后,从红队视角反思:
该样本暴露了哪些特征?
├─ 静态特征 → 特定字符串/Import/节名/编译时间
├─ 行为特征 → 进程注入方式/持久化手法/C2 模式
├─ 网络特征 → User-Agent/URI 模式/心跳间隔
└─ 内存特征 → 未加密字符串/固定 XOR key/特征字节序列→ 用于改进自身工具的免杀设计
工具速查
| 用途 | 工具 |
|---|---|
| PE 分析 | pefile, pestudio, CFF Explorer |
| ELF 分析 | readelf, pyelftools, radare2 |
| 反编译 | Ghidra, IDA Pro, Binary Ninja |
| 字符串提取 | FLOSS (FireEye), strings |
| 沙箱 | AnyRun, CAPE, Cuckoo |
| 网络 | Wireshark, FakeNet-NG |
| YARA | yara-python, yarGen |
动态分析与沙箱对抗参考
Windows 动态分析
Procmon 过滤器配置
关键过滤器设置:
1. Process Name → is → sample.exe(只看目标进程)
2. 加入子进程: Tools → Process Tree → 右键包含子进程
重点关注操作:
├─ RegSetValue → 持久化(Run/RunOnce/Services)
├─ CreateFile → 释放文件
├─ Process Create → 子进程链
├─ TCP Connect → C2 通信
└─ WriteFile to \Windows\ or \System32\ → 投放FakeNet-NG 网络模拟
# 模拟 DNS + HTTP + HTTPS 响应,让恶意软件以为网络正常
fakenet -c fakenet.cfg
# 自定义响应规则
# 所有 DNS → 解析到本地
# 所有 HTTP → 返回 200 OK
# 记录所有请求 → 提取 C2 地址/URIAPI Monitor 关键 API 组
监控分组(按攻击阶段):
进程注入链:
├─ OpenProcess → 打开目标进程
├─ VirtualAllocEx → 在目标分配内存
├─ WriteProcessMemory → 写入 shellcode
└─ CreateRemoteThread / NtCreateThreadEx → 执行
凭据窃取:
├─ OpenProcessToken → 获取令牌
├─ DuplicateToken → 复制特权令牌
├─ LsaCallAuthenticationPackage → LSASS 交互
└─ CredRead / CredEnumerate → 凭据库
持久化:
├─ RegSetValueEx (Run键)
├─ CreateService / StartService
├─ CopyFile → 复制自身到持久位置
└─ TaskSchedulerCreate → 计划任务Linux 动态分析
strace 高级用法
# 完整跟踪(含子进程、网络、文件操作)
strace -f -e trace=network,process,file,desc \
-e signal=none \
-y -yy \
-o full_trace.log \
./sample
# 关键参数:
# -f: 跟随 fork/clone
# -y: 显示 fd 对应的文件路径
# -yy: 显示 socket 地址详情
# -e trace=network: 只看网络调用(快速定位 C2)
# 快速定位 C2 连接
grep -E "connect|sendto|recvfrom" full_trace.log
# 定位文件释放
grep -E "openat.*O_CREAT|rename|symlink|chmod" full_trace.log
# 定位进程行为
grep -E "execve|clone|fork|kill" full_trace.logDocker 隔离执行
# 在 Docker 中执行样本(最小权限)
docker run --rm -it \
--network=none \
--cap-drop=ALL \
--security-opt=no-new-privileges \
-v $(pwd)/sample:/sample:ro \
ubuntu:22.04 bash
# 内部安装分析工具
apt update && apt install -y strace ltrace
chmod +x /sample && strace -f /sample沙箱对抗(从分析者视角理解防御)
常见沙箱如何检测恶意行为
| 沙箱 | 检测方式 | 恶意软件逃逸点 |
|---|---|---|
| Cuckoo/CAPE | API Hook (cuckoomon) | Hook 覆盖不全的 syscall |
| AnyRun | 用户交互模拟 + 进程监控 | 需要多次特定交互 |
| Joe Sandbox | 行为签名 + 网络特征 | 延迟执行/环境条件 |
| Windows Sandbox | Hyper-V 隔离 | Guardrails(域名/用户) |
| VirusTotal | 多引擎静态 + 动态 | 加密 payload + 条件触发 |
绕过 Cuckoo 的已知方式
1. cuckoomon hook 基于 DLL 注入 → 直接 syscall 绕过
2. 检测 agent.py 进程 → 发现即退出
3. 超过默认分析时间(2-5min) → Sleep 超时
4. 检测结果目录 /tmp/.cuckoo* → 文件存在即退出
5. 内存中搜索 "cuckoo" 字符串 → hook DLL 特征绕过 AnyRun 的已知方式
1. 需要非直线鼠标路径(贝塞尔曲线检测)
2. 需要键盘输入(不只是鼠标点击)
3. 30秒内无操作 = 超时
4. 付费版有更长分析时间 → 延迟 10min+ 才有效自动化行为分析脚本
#!/usr/bin/env python3
"""解析 Cuckoo/CAPE JSON 报告,提取关键行为"""
import json
import sys
def parse_cuckoo_report(report_path):
with open(report_path) as f:
report = json.load(f)
results = {
'network': [],
'files_created': [],
'registry_modified': [],
'processes_created': [],
'signatures_matched': []
}
# 网络行为
network = report.get('network', {})
for dns in network.get('dns', []):
results['network'].append(f"DNS: {dns.get('request')} -> {dns.get('answers', [])}")
for http in network.get('http', []):
results['network'].append(f"HTTP: {http.get('method')} {http.get('uri')}")
for conn in network.get('tcp', []) + network.get('udp', []):
results['network'].append(f"CONN: {conn.get('dst')}:{conn.get('dport')}")
# 文件操作
for f in report.get('behavior', {}).get('summary', {}).get('files', []):
results['files_created'].append(f)
# 进程树
for proc in report.get('behavior', {}).get('processes', []):
results['processes_created'].append(
f"PID:{proc.get('pid')} PPID:{proc.get('ppid')} CMD:{proc.get('command_line')}"
)
# 签名匹配
for sig in report.get('signatures', []):
results['signatures_matched'].append(
f"[{sig.get('severity')}] {sig.get('description')}"
)
return resultsPE/ELF 静态分析详细参考
PE 分析完整流程
1. 节表分析 — 异常指标
| 指标 | 含义 |
|---|---|
节名 .UPX0/.UPX1 | UPX 加壳 |
节名 .VMP0/.VMP1 | VMProtect |
节名 .themida | Themida 壳 |
入口点不在 .text 节 | 可能加壳/注入 |
.text 节 RWX 权限 | 自修改代码 |
| 节 RawSize = 0 但 VirtualSize 大 | 运行时解包 |
| 多个高熵(>7.0)节 | 加密数据/壳 |
2. Import Hash (Imphash) 聚类
import pefile
pe = pefile.PE("sample.exe")
imphash = pe.get_imphash()
print(f"Imphash: {imphash}")
# 相同 imphash → 相同编译器/框架/同一家族变种3. Rich Header 分析
# Rich Header 包含编译环境信息
rich = pe.parse_rich_header()
if rich:
for entry in rich.get('values', []):
comp_id = entry >> 16
build = entry & 0xFFFF
print(f"CompID: {comp_id} Build: {build}")
# 同一开发者/编译环境 → Rich Hash 相同4. 自动化 PE 分析脚本
#!/usr/bin/env python3
"""PE 样本快速分析报告生成器"""
import pefile
import hashlib
import math
from collections import Counter
from datetime import datetime
def analyze_pe(filepath):
with open(filepath, 'rb') as f:
data = f.read()
pe = pefile.PE(data=data)
report = {}
# 哈希
report['md5'] = hashlib.md5(data).hexdigest()
report['sha256'] = hashlib.sha256(data).hexdigest()
report['imphash'] = pe.get_imphash()
# 编译时间
ts = pe.FILE_HEADER.TimeDateStamp
report['compile_time'] = datetime.utcfromtimestamp(ts).isoformat()
# 节分析
report['sections'] = []
for s in pe.sections:
name = s.Name.decode(errors='replace').strip('\x00')
entropy = s.get_entropy()
report['sections'].append({
'name': name,
'entropy': round(entropy, 2),
'virtual_size': s.Misc_VirtualSize,
'raw_size': s.SizeOfRawData,
'characteristics': hex(s.Characteristics),
'suspicious': entropy > 7.0 or s.SizeOfRawData == 0
})
# 可疑 Import
suspicious_apis = {
'VirtualAlloc', 'VirtualAllocEx', 'WriteProcessMemory',
'CreateRemoteThread', 'NtCreateThreadEx', 'RtlCreateUserThread',
'IsDebuggerPresent', 'CheckRemoteDebuggerPresent',
'NtQueryInformationProcess', 'GetTickCount', 'QueryPerformanceCounter',
'WinHttpOpen', 'InternetOpenA', 'URLDownloadToFile',
'CryptEncrypt', 'BCryptEncrypt', 'CryptDecrypt',
'RegSetValueEx', 'CreateService', 'OpenProcess'
}
report['imports'] = {}
report['suspicious_imports'] = []
if hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):
for entry in pe.DIRECTORY_ENTRY_IMPORT:
dll = entry.dll.decode()
funcs = [imp.name.decode() for imp in entry.imports if imp.name]
report['imports'][dll] = funcs
for f in funcs:
if f in suspicious_apis:
report['suspicious_imports'].append(f"{dll}:{f}")
return report
if __name__ == '__main__':
import sys, json
r = analyze_pe(sys.argv[1])
print(json.dumps(r, indent=2))ELF 分析完整流程
1. ELF 类型判断
# 动态链接 vs 静态链接
file sample
# "dynamically linked" → 有外部依赖
# "statically linked" → IoT 恶意软件常见(跨系统兼容)
# 架构判断
readelf -h sample | grep Machine
# EM_X86_64, EM_ARM, EM_MIPS → 不同目标平台2. 关键函数导入映射
| 函数 | 功能推断 |
|---|---|
socket + connect | C2 通信 |
fork + execve | 子进程执行 |
ptrace(PTRACE_TRACEME) | 反调试 |
inotify_add_watch | 文件监控 |
dlopen + dlsym | 动态加载(反静态分析) |
unlink | 自删除 |
mount + chroot | 容器逃逸可能 |
init_module / finit_module | Rootkit 内核模块加载 |
3. ELF 自动化分析
#!/usr/bin/env python3
"""ELF 样本快速分析"""
from elftools.elf.elffile import ELFFile
from elftools.elf.dynamic import DynamicSection
import hashlib, math, sys
from collections import Counter
def analyze_elf(filepath):
with open(filepath, 'rb') as f:
data = f.read()
f.seek(0)
elf = ELFFile(f)
report = {
'sha256': hashlib.sha256(data).hexdigest(),
'class': f"{elf.elfclass}-bit",
'arch': elf.header.e_machine,
'type': elf.header.e_type,
'entry': hex(elf.header.e_entry),
'stripped': elf.get_section_by_name('.symtab') is None,
}
# 节熵分析
report['high_entropy_sections'] = []
for section in elf.iter_sections():
sdata = section.data()
if len(sdata) > 100:
entropy = -sum((c/len(sdata))*math.log2(c/len(sdata))
for c in Counter(sdata).values())
if entropy > 7.0:
report['high_entropy_sections'].append({
'name': section.name,
'entropy': round(entropy, 2),
'size': len(sdata)
})
# 动态库依赖
report['libraries'] = []
for section in elf.iter_sections():
if isinstance(section, DynamicSection):
for tag in section.iter_tags():
if tag.entry.d_tag == 'DT_NEEDED':
report['libraries'].append(tag.needed)
return report4. 常见 Linux 恶意软件家族特征
| 家族 | 特征 |
|---|---|
| Mirai | 字符串 /bin/busybox,telnet 凭据列表,DDoS attack 函数 |
| XorDDoS | 文件名 .IptabLes/.IptabLex,XOR 加密通信 |
| Gafgyt | 字符串 SCANNER/TELNET/JAWS,UDP flood |
| Cryptominer | stratum+tcp://,钱包地址格式 |
| Tsunami/Kaiten | IRC 协议通信,PRIVMSG/JOIN 字符串 |
| LD_PRELOAD Rootkit | Hook readdir/fopen,写入 /etc/ld.so.preload |
Related skills
AI & Agent Buildingagents