Malware Analysis
Malware Reverse Engineering — The Art of Unpacking the Beast
Malware reverse engineering (MRE) is the forensic dissection of malicious binaries to uncover what they do, how they do it, and how to stop (or repurpose) them. From ransomware unpacking to APT loader tracing, this is where binary analysis meets threat intelligence.
This guide covers static and dynamic analysis, behavior mapping, anti-analysis evasion, and memory forensics — built for both CTF reverse challenges and real-world malware teardown.
I. 🧩 Core Malware Concepts
Dropper
Initial loader delivering payloads.
Payload
Actual malicious code (stealer, RAT, ransomware).
Persistence
Mechanisms ensuring malware re-executes after reboot.
C2 (Command & Control)
Remote infrastructure controlling malware.
Packing / Obfuscation
Techniques hiding or encrypting code.
Injection
Injecting payloads into legitimate processes (e.g., explorer.exe).
Sandbox Evasion
Detecting or escaping automated analysis.
II. ⚙️ Analysis Environment Setup
🧠 Golden Rule: Never analyze on your main OS.
⚙️ 1. Safe VM Setup
Host OS: Linux or Windows with isolation.
VM: Windows 10/11 + Snapshots.
Disable networking, or use INetSim for fake internet simulation.
⚙️ 2. Essential Tools
Static
Ghidra, IDA, DIE, PEiD
Dynamic
x64dbg, Process Monitor, Procmon, Process Hacker
Memory
Volatility3, Rekall
Network
Wireshark, Fakenet-NG, INetSim
Strings/Entropy
FLOSS, binwalk, Detect-It-Easy
Behavior
Any.Run, CAPEv2, Cuckoo Sandbox
III. ⚙️ Static Analysis — Pre-Execution Dissection
🧠 1. Identify File Type
file sample.exe
pefile sample.exeCheck if PE, ELF, or Mach-O.
⚙️ 2. Check Packing / Encryption
Detect-It-Easy sample.exeor
upx -t sample.exeIf UPX packed:
upx -d sample.exe🧩 3. Extract Strings
floss sample.exe > strings.txt
grep -E "http|cmd|powershell|key|flag" strings.txt⚙️ 4. Check Imports / APIs
peframe sample.exeor manually:
objdump -p sample.exe | grep -i importLook for suspicious APIs:
CreateRemoteThread
VirtualAllocEx
InternetConnect
WriteProcessMemory🧠 5. Analyze Sections
readelf -S malwareSuspicious indicators:
Unusual entropy in
.textCode in
.dataor.rdataOverwritten headers
⚙️ 6. Use Ghidra / IDA
Follow logic flow:
WinMain(),_start, ormain()API imports:
LoadLibraryA,GetProcAddressHardcoded strings: URLs, registry keys, file paths
Look for decryption or unpacking routines (loops or XORs)
IV. ⚙️ Dynamic Analysis — Behavior in Action
🧩 1. Run Under Monitor
procmon.exeTrack:
File system modifications
Registry writes
Process creation
Network connections
⚙️ 2. Check Network Behavior
fakenet-ng
wiresharkMonitor:
HTTP POST to unknown IPs
DNS requests to suspicious domains
Encrypted outbound traffic
🧠 3. API Call Tracing
API Monitor
Process Hacker
x64dbgWatch for:
CreateProcess(spawning payload)RegSetValueEx(persistence)OpenProcess+WriteProcessMemory(injection)
⚙️ 4. Debug Step-by-Step
x64dbg sample.exeBreakpoints:
CreateProcessAWinExecInternetConnectWriteFile
Step through to watch decryption and unpacking routines.
V. 💣 Unpacking Malware
🧩 1. Detect the Packer
UPX → simple unpack
Themida / VMProtect → advanced
Custom XOR → manual reversing
⚙️ 2. Dump Unpacked Memory
x64dbg → Dump memory → Rebuild PE with Scylla💣 3. Automate with UnpacMe / CAPE
Upload → auto-unpack → retrieve clean binary.
VI. ⚙️ Malware Behavior Mapping
🧠 1. File System Indicators
%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\%TEMP%\random.exeC:\Users\<user>\AppData\Roaming\
⚙️ 2. Registry Persistence
reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Run🧩 3. Scheduled Tasks
schtasks /query /fo LIST /vVII. ⚙️ Code Injection & Process Hollowing
Classic Injection
Inject shellcode into remote process
OpenProcess, WriteProcessMemory, CreateRemoteThread
Process Hollowing
Replace memory of a legitimate process
NtUnmapViewOfSection, ZwWriteVirtualMemory
Reflective Loading
Load DLL from memory
LoadLibrary, VirtualAlloc
APC Injection
Queue APCs in target thread
QueueUserAPC
Use x64dbg or Procmon to visualize injected threads and memory regions.
VIII. 🧠 Network & C2 Analysis
⚙️ 1. Capture Communication
wireshark -i 1 -f "tcp port 80 or 443"Look for:
POST requests with encoded data
Domains resembling legit names (e.g.
micros0ft-update.net)
⚙️ 2. Fake C2 Interaction
Use INetSim to simulate network services:
inetsim --service http --service dnsObserve malware’s connection attempts.
IX. ⚙️ Memory Forensics
🧠 1. Capture RAM
winpmem.exe --output mem.raw⚙️ 2. Analyze with Volatility
volatility3 -f mem.raw windows.pslist
volatility3 -f mem.raw windows.malfind
volatility3 -f mem.raw windows.cmdlineUse malfind to detect injected code and hidden modules.
X. ⚙️ Deobfuscation & Decryption
🧠 1. Identify XOR / RC4 Loops
Look for patterns like:
xor eax, 0x13
add edi, 1or
for (i=0;i<len;i++) buf[i]^=key;⚙️ 2. Recreate Algorithm
Use Python to decrypt:
data = [0x45, 0x47, 0x50]
key = 0x13
print(''.join([chr(b ^ key) for b in data]))💣 3. Dynamic Dump Decrypted Data
Hook memory using:
frida-trace -i "VirtualAlloc" -i "WriteFile" sample.exeXI. ⚙️ Common Malware Techniques
Process Hollowing
Inject payload into legitimate process
Persistence via Registry
Run malware on boot
Keylogging
Capture keystrokes via GetAsyncKeyState
Credential Dumping
Access lsass.exe memory
Screen Capture
Using BitBlt and CreateCompatibleBitmap
Exfiltration
Sending stolen data via HTTP/DNS
C2 Obfuscation
Encrypting communications (base64, XOR)
XII. ⚙️ Evasion & Anti-Analysis Tricks
Anti-VM
Checks for VMware registry keys
Patch or emulate registry
Anti-Debug
Calls to IsDebuggerPresent
Patch to return false
Sleep Delays
Long Sleep() calls
Hook and skip
Environment Checks
Looking for process names like procmon.exe
Rename tools
Encrypted APIs
Dynamic import resolution
Break at LoadLibraryA
XIII. ⚙️ Behavioral Sandboxing
🧠 1. CAPEv2 Sandbox
Automatically:
Unpacks
Monitors API calls
Generates YARA signatures
Produces network PCAPs
⚙️ 2. Any.Run (Interactive)
Upload sample → run → interact → export behavior trace.
XIV. ⚙️ YARA & Signature Creation
Create custom detection rules:
rule EvilMalware {
strings:
$s1 = "VirtualAllocEx"
$s2 = "cmd.exe /c"
$s3 = "POST /data"
condition:
all of them
}Scan:
yara -r EvilMalware.yar samples/XV. ⚙️ Incident Response Integration
Memory Dump
Extract injected payloads
Disk Image
Locate persistence
PCAP
Analyze exfiltration
Registry Hive
Startup entries
Logs
Process creation timestamps
Integrate with ELK/Splunk or MISP for threat intel correlation.
XVI. ⚔️ Pro Tips & Operator Tricks
✅ Run in Layers: Start static → trace behavior → dump memory → rebuild PE → analyze logic.
✅ Snapshots Are Life: Revert VM after each execution to reset artifacts.
✅ Frida = Power: Hook live API calls to dump decrypted payloads mid-runtime.
✅ Network Sim = Gold: Fake all internet services with INetSim — you’ll see what domains it tries to reach.
✅ Look for Sleep Skips:
Replace Sleep(600000) with Sleep(0) to save time.
✅ Automate Your Analysis: Use CAPEv2 to generate reports + YARA rules automatically.
✅ Check For Hidden DLLs:
Injected or reflective DLLs won’t show up in imports — check malfind.
XVII. ⚙️ Quick Reference Table
Identify Malware
Detect-It-Easy
Detect packers, compiler
Extract Strings
floss sample.exe
Decode obfuscated strings
Monitor Behavior
procmon, fakenet-ng
File/network trace
Disassemble
ghidra, ida
Inspect logic flow
Dump Memory
x64dbg + Scylla
Dump unpacked code
Analyze RAM
volatility3
Extract hidden processes
Detect C2
wireshark
Inspect network traffic
Sandbox
cape, any.run
Automated behavioral analysis
Create YARA
yara EvilMalware.yar samples/
Detection rule matching
Last updated
Was this helpful?