mcpField
M
malware-analysis-methodology

malware-analysis-methodology

github.com/wgpsecSecurity1.8k44 installsUpdated 4d ago
Repository

About malware-analysis-methodology

A malware analysis methodology for security analysts, organized around safe sample handling, static and dynamic analysis, IOC extraction, and OPSEC review. It covers sample types including PE and ELF.

Key features

  1. 01Safe handling and sample classification
  2. 02PE and ELF static analysis
  3. 03Windows and Linux dynamic analysis
  4. 04IOC extraction checklist
  5. 05Red-team OPSEC review

Use cases

  1. 01Plan a malware sample analysis
  2. 02Extract IOCs from runtime behavior
  3. 03Review static and behavioral indicators exposed by a sample

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/wgpsec/aboutsecurity --skill malware-analysis-methodology

After installing, type/malware-analysis-methodologyin Claude Code to confirm it loaded.

Bundled filesreferences/dynamic-analysis.mdreferences/static-analysis.md

Details

From the project README

恶意软件分析方法论

红队价值:理解样本如何被分析 → 知道哪些特征会暴露 → 改进免杀和 OPSEC

⛔ 深入参考


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
YARAyara-python, yarGen

Comments

Markdown supported