Hacktricks-skills crypto-malware-analysis
How to identify cryptographic and compression algorithms in malware binaries, recognize packing techniques, and unpack obfuscated executables. Use this skill whenever analyzing malware that contains encrypted sections, compressed code, or packed binaries. Trigger when the user mentions crypto, encryption, compression, packing, obfuscation, RC4, AES, or any binary analysis involving cryptographic detection. Also use when investigating suspicious executables with unusual section characteristics or when static analysis seems misleading.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/crypto/crypto-in-malware/crypto-in-malware/SKILL.MDCrypto in Malware Analysis
This skill helps you identify cryptographic and compression algorithms in malware binaries and recognize packing techniques during reverse engineering.
When to Use This Skill
Use this skill when:
- You're analyzing a binary and suspect encryption or compression
- You see unusual patterns in assembly (lots of XORs, shifts, rotates)
- Static analysis seems misleading or incomplete
- You need to identify packing algorithms
- You're investigating obfuscated malware
- You encounter Windows crypto API calls
Identifying Cryptographic/Compression Algorithms
Technique-First Heuristics
Look for these patterns in assembly code:
-
Shift/Rotate Heavy Code: Lots of shifts, rotates, XORs, and 32-bit arithmetic in tight loops often indicate cryptographic operations
-
Lookup Tables: Check
section or runtime-generated tables for S-boxes or other crypto tables.data -
RC4 Indicators: Repeating loops of 256 iterations (0x100) strongly suggest RC4
Windows Crypto/Compression APIs
CryptDeriveKey / CryptCreateHash
When you see these API calls, examine the second parameter - it's an
ALG_ID that identifies the algorithm:
- Check the ALG_ID value against Microsoft's documentation
- Common values indicate specific algorithms (DES, RC4, SHA, MD5, etc.)
- Reference: https://learn.microsoft.com/en-us/windows/win32/seccrypto/alg-id
RtlCompressBuffer / RtlDecompressBuffer
These calls indicate built-in Windows compression:
- LZNT1
- XPRESS
- Other Windows compression formats
Constants and Tables Fingerprinting
You can often identify algorithms by searching for constants or table values:
- Extract the first dword of suspicious tables
- Search online for known crypto constants
- Compare against known algorithms like AES tables
Example: AES has well-known S-box and inverse S-box tables that can be fingerprinted.
RC4 Recognition Checklist
RC4 is commonly used in malware and has distinctive patterns:
- Two loops of 256 iterations (initialization + Key Scheduling Algorithm)
- PRGA loop that uses modulo 256 operations
- XOR keystream with data in the final loop
Look for this pattern:
Loop 1: 256 iterations (init) Loop 2: 256 iterations (KSA) Loop 3: PRGA with % 256 and XOR
Unpacking Binaries
Understanding Packers
Packers transform binaries to mislead static analysis by:
- Adding junk code
- Encrypting sections
- Performing runtime unpacking
Your goal: Catch the moment the binary:
- Allocates/decrypts real code in memory
- Marks it executable
- Jumps into the unpacked code
Identifying Packed Binaries
Look for these indicators:
- Lack of strings or only packer-specific strings
- Many strings without cross-references (common in commercial packers)
- Use packer-ID tools:
- PEiD
- Exeinfo PE
Unpacking Strategy
Follow this approach:
-
Start from the bottom and work upward - unpackers often jump late in execution
-
Look for jump patterns:
patternsJMP/CALL reg- Stack tricks like
push addr; retn
-
Set breakpoints on memory operations:
- watch for code allocationVirtualAlloc
- watch for permission changes to RWXVirtualProtect- Track RWX regions that appear during execution
-
Watch for string explosion - a sudden appearance of many strings after a jump often indicates you've reached unpacked code
-
Dump and fix:
- Dump the memory at the right moment
- Fix headers with tools like PE-bear
- Verify the dumped binary runs correctly
Analysis Workflow
When approaching a potentially packed/encrypted binary:
-
Initial reconnaissance
- Run PEiD/Exeinfo PE to check for known packers
- Look at section characteristics (entropy, permissions)
- Check for unusual import tables
-
Static analysis
- Look for crypto API calls
- Search for known constants/tables
- Identify suspicious loop patterns
-
Dynamic analysis
- Set breakpoints on VirtualAlloc/VirtualProtect
- Watch for RWX memory regions
- Monitor for string appearance
-
Unpacking
- Dump memory at the right moment
- Fix headers
- Verify functionality
Common Pitfalls
- Don't trust static analysis alone on packed binaries
- Don't assume all encryption is malicious (legitimate software uses it too)
- Don't forget to check for anti-debugging techniques
- Don't skip the header fixing step after dumping
Tools to Have Ready
- Packer identification: PEiD, Exeinfo PE
- Memory dumping: Scylla, x64dbg with plugins
- Header fixing: PE-bear, CFF Explorer
- Disassembly: IDA Pro, Ghidra, x64dbg
- Dynamic analysis: x64dbg, WinDbg