Malware and network analysis techniques for CTF challenges. Use when analyzing obfuscated scripts, malicious packages, custom protocols, or C2 traffic.
Malware and network analysis techniques for CTF challenges. Use when analyzing obfuscated scripts, malicious packages, custom protocols, or C2 traffic.
Look for C2 communication patterns on unusual ports (e.g., port 21 not for FTP).
Hex-Encoded Payloads
Convert hex to bytes, try common transformations: subtract 1, XOR with key
JavaScript Deobfuscation
// Replace eval with console.logeval = console.log;
// Then run the obfuscated code// Common patternsunescape() // URL decodingString.fromCharCode() // Char codesatob() // Base64
using AsmResolver.DotNet;
var module = ModuleDefinition.FromFile("malware.dll");
foreach (var type in module.GetAllTypes()) {
foreach (var method in type.Methods) {
// Analyze method body
}
}
AES-CBC in Malware
Common key derivation:
MD5/SHA256 of hardcoded string
Derived from timestamp or PID
Password-based (PBKDF2)
Analysis approach:
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
import hashlib
# Common pattern: key = MD5(password)
password = b"hardcoded_password"
key = hashlib.md5(password).digest()
# IV often first 16 bytes of ciphertext
iv = ciphertext[:16]
ct = ciphertext[16:]
cipher = AES.new(key, AES.MODE_CBC, iv)
plaintext = unpad(cipher.decrypt(ct), 16)
Password Rotation in C2
Pattern: C2 uses rotating passwords based on time/sequence
Pattern (Stomaker): Malware uses Telegram bot to exfiltrate stolen data.
Recover exfiltrated data via bot token:
# If you have the bot API token from malware source:import requests
TOKEN = "bot_token_here"# Get updates (message history)
r = requests.get(f"https://api.telegram.org/bot{TOKEN}/getUpdates")
# Download files sent to bot
file_id = "..."
r = requests.get(f"https://api.telegram.org/bot{TOKEN}/getFile?file_id={file_id}")
file_path = r.json()['result']['file_path']
requests.get(f"https://api.telegram.org/file/bot{TOKEN}/{file_path}")
RC4-Encrypted WebSocket C2 Traffic
Pattern (Tampered Seal): Malware uses WSS over non-standard port with RC4 encryption.
Decryption workflow:
Identify C2 port from malware source (not standard 443)
Remap port with tcprewrite so Wireshark decodes TLS
Add RSA key for TLS decryption → reveals WebSocket frames
Find RC4 key hardcoded in malware binary
Decrypt each WebSocket payload with RC4 via CyberChef