ctf-malware

$npx mdskill add wgpsec/AboutSecurity/ctf-malware

Analyze malware samples and reverse-engineer C2 traffic.

  • Decodes obfuscated scripts, PE binaries, and encrypted protocols.
  • Uses IDA, Ghidra, Frida, x64dbg, Wireshark, and Vol3.
  • Selects analysis paths via a decision tree for malware types.
  • Outputs actionable findings on reverse-engineering and traffic patterns.
SKILL.md
.github/skills/ctf-malwareView on GitHub ↗
---
name: ctf-malware
description: "CTF 恶意软件分析技术。当遇到混淆脚本分析、C2 流量还原、PE/.NET 恶意样本逆向、自定义加密协议解析、YARA 规则编写、Shellcode 分析等 CTF 恶意软件分析类挑战时使用。覆盖静态分析(IDA/Ghidra)、动态调试(Frida/x64dbg)、流量分析(Wireshark)、内存取证等"
metadata:
  tags: "ctf,malware,恶意软件,c2,pe,dotnet,yara,shellcode,混淆,流量分析"
  category: "ctf"
---

# CTF 恶意软件分析

## 深入参考

以下参考资料**按需加载**,根据识别出的具体方向选择对应文件:

- 脚本反混淆与动态分析(JS/PowerShell/YARA/Shellcode/内存取证) → [references/scripts-and-obfuscation.md](references/scripts-and-obfuscation.md)
- C2 流量与自定义协议(RC4 WebSocket/DNS C2/AES-CBC/Telegram Bot) → [references/c2-and-protocols.md](references/c2-and-protocols.md)
- PE/.NET 分析(peframe/dnSpy/LimeRAT/PyInstaller+PyArmor) → [references/pe-and-dotnet.md](references/pe-and-dotnet.md)

---

## 分类决策树

```
恶意软件分析题?
├─ 脚本类
│  ├─ JS → eval 替换为 console.log → 解码 unescape/atob
│  ├─ PowerShell → -enc base64解码 → IEX 替换为输出
│  ├─ Bash → eval 替换为 echo → base64/hex 提取
│  └─ Debian包 → ar -x → 检查 postinst 脚本
├─ 二进制类
│  ├─ PE → peframe/pestudio 快速分类 → [references/pe-and-dotnet.md](references/pe-and-dotnet.md)
│  ├─ .NET → dnSpy 反编译 → AsmResolver 编程分析
│  ├─ PyInstaller → pyinstxtractor 提取 → PyArmor 脱壳
│  └─ 查加密常量: AES S-box(0x637c777b) / ChaCha20 / TEA(0x9E3779B9) / RC4
├─ 流量分析
│  ├─ PCAP → tshark 提取流 → 识别 C2 模式
│  ├─ 自定义加密 → 找密钥 → 按时间序拼接解密
│  ├─ DNS C2 → 域名编码 / DGA 模式
│  └─ RC4 WebSocket → tcprewrite 重映射端口 → 找RC4密钥
├─ 反分析检测
│  ├─ VM检测 → CPUID/MAC/注册表/磁盘大小
│  ├─ 调试器 → PEB/时间检测/API哈希
│  └─ 进程注入 → hollowing/APC/CreateRemoteThread
└─ 内存取证 → vol3 malfind + YARA 扫描
```

## 快速分析命令

```bash
# 文件快速分类
file malware && strings -n 8 malware | head -50

# 提取网络指标
strings malware | grep -E '[0-9]{1,3}(\.[0-9]{1,3}){3}'

# PCAP 流量分析
tshark -r capture.pcap -Y "tcp.stream eq 0" -T fields -e tcp.payload

# PE 分析
peframe malware.exe

# 内存取证
vol3 -f memory.dmp windows.malfind
vol3 -f memory.dmp windows.pstree
```

## 加密算法识别

| 特征 | 算法 |
|------|------|
| S-box `0x637c777b` | AES |
| `expand 32-byte k` | ChaCha20 |
| `0x9E3779B9` | TEA/XTEA |
| 256字节 S-box 顺序初始化 | RC4 |
| MD5/SHA256(硬编码字符串) | AES-CBC 密钥派生 |

## YARA 速查

```yara
rule XOR_Loop { strings: $xor = { 31 ?? 80 ?? ?? 4? 75 } condition: $xor }
```

## 反混淆技巧

| 语言 | 方法 |
|------|------|
| JavaScript | `eval` → `console.log` |
| PowerShell | `-enc` base64解码 / `IEX` → 输出 |
| Bash | `eval` → `echo` |
| 垃圾代码 | 过滤 NOP/push-pop/死写 → 提取真实 call |

## Shellcode 分析

```bash
objdump -b binary -m i386:x86-64 -D shellcode.bin  # 反汇编
# Unicorn 模拟执行 / Capstone 编程反汇编
```

## PowerShell 混淆
- 多层嵌套编码,需递归解码(可能多层混淆)

## C2 流量分析
- DNS C2:检查子域名(subdomain)、qname 查询域名中的编码数据
More from wgpsec/AboutSecurity