malware-analysis-methodology
恶意软件分析方法论。当需要分析可疑二进制文件(PE/ELF/Mach-O)、内存 dump 中的恶意代码、或已知恶意软件家族样本时使用。覆盖静态分析、动态分析、代码逆向、IOC 提取全流程。红队视角:理解检测面以改进免杀
How do I install this agent skill?
npx skills add https://github.com/wgpsec/aboutsecurity --skill malware-analysis-methodologyIs this agent skill safe to install?
- Gen Agent Trust Hubpass
The skill provides a methodology and tools for malware analysis, including scripts to analyze PE and ELF files. While it promotes safe practices like environment isolation, it possesses a risk profile associated with processing untrusted binary data which could potentially influence agent behavior.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
恶意软件分析方法论
红队价值:理解样本如何被分析 → 知道哪些特征会暴露 → 改进免杀和 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 |
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/wgpsec/aboutsecurity/malware-analysis-methodology">View malware-analysis-methodology on skillZs</a>