Hacktricks-skills malware-api-reference
Reference for Windows APIs commonly used in malware, malware analysis techniques, and detection strategies. Use this skill whenever the user mentions malware analysis, reversing, Windows API calls, process injection, DLL injection, process hollowing, anti-analysis techniques, threat hunting, detection rules, or any security research involving Windows executables. Trigger even if they don't explicitly say "malware" but describe suspicious behavior, API sequences, or need to understand how malware evades detection.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/reversing/common-api-used-in-malware/SKILL.MDMalware API Reference & Analysis Guide
A comprehensive reference for Windows APIs commonly abused by malware, along with analysis techniques and detection strategies.
Quick Reference: Common Malware APIs
Networking APIs
| Raw Sockets | WinAPI Sockets | Purpose |
|---|---|---|
| | Initialize socket communication |
| | Bind to local address |
| | Listen for connections |
| | Accept incoming connections |
| | Connect to remote host |
| | Receive data |
| | Send data |
| | Cleanup socket resources |
Detection tip: Monitor for
WSAStartup() followed by connect() to suspicious IPs/ports, especially from non-browser processes.
Persistence APIs
| Registry | File System | Service Management |
|---|---|---|
| | |
| | |
| | |
| | |
| |
Detection tip: Alert on registry modifications to Run/RunOnce keys, especially from temporary directories.
Encryption APIs (WinCrypt)
- Acquire cryptographic providerCryptAcquireContext()
- Generate encryption keyCryptGenKey()
- Derive key from passwordCryptDeriveKey()
- Decrypt dataCryptDecrypt()
- Release providerCryptReleaseContext()
Detection tip: Ransomware often calls these in sequence. Monitor for rapid encryption of many files.
Anti-Analysis / VM Detection APIs
| API | Purpose |
|---|---|
| Check for debugger |
| Gather system info |
| Check memory (VM indicator) |
| OS version check |
| Enumerate processes |
| Check for files |
Assembly-level checks:
- CPU identificationCPUID()
- Port I/O (often fails in VMs)IN()
Detection tip: Flag processes that query multiple anti-VM APIs early in execution then exit with no observable activity.
Locale/Keyboard-Based Execution Guards
Malware often aborts on certain locales to evade researchers:
- Enumerate installed layoutsGetKeyboardLayout()
- Resolve country/region codesGetLocaleInfoA/W()
/GetSystemDefaultLangID()
- Get language IDsGetUserDefaultLangID()
Common blocked regions: CIS countries (Russia, Ukraine, Belarus, etc.)
Detection tip: Correlate locale API calls with immediate process termination and no network IOCs.
Emulator API Fingerprinting
Malware searches for sandbox/emulator exports:
Defender Virtualization exports:
,MpVmp32EntryMpVmp32FastEnter
,MpCallPreEntryPointCodeMpCallPostEntryPointCode
,MpFinalize
,MpReportEvent*MpSwitchToNextThread*
VFS family:
,VFS_Open
,VFS_ReadVFS_MapViewOfFile
,VFS_UnmapViewOfFileVFS_FindFirstFile/FindNextFile
,VFS_CopyFile
,VFS_DeleteFileVFS_MoveFile
ThrdMgr family:
,ThrdMgr_GetCurrentThreadHandle
,ThrdMgr_SaveTEBThrdMgr_SwitchThreads
Typical evasion: Delay execution 10-30 minutes if emulator detected:
cmd /c timeout /t %RANDOM_IN_[600,1800]% > nul
Stealth & Injection APIs
| API | Purpose |
|---|---|
| Allocate memory (packers) |
| Change memory permissions |
| Read from other processes |
| Write to other processes |
| Native memory write |
| Remote thread creation |
| Unmap memory sections |
| Queue APC to thread |
| Internal process creation |
Detection tip: Alert on
CREATE_SUSPENDED processes that allocate RWX memory before creating GUI/console windows.
Execution APIs
- Create new processCreateProcessA/W()
- Execute via shellShellExecute()
- Execute commandWinExec()
- Resume suspended threadResumeThread()
- Native thread resumeNtResumeThread()
Miscellaneous APIs
| API | Purpose |
|---|---|
| Key logging |
| Key logging |
| Get active window |
| Load DLL |
| Get function address |
| List processes |
| Get device context |
| Screenshot |
| HTTP access |
| Access embedded resources |
Malware Techniques Deep Dive
DLL Injection
Execute arbitrary DLL inside another process:
- Locate target process:
,CreateToolhelp32Snapshot()
,Process32First()Process32Next() - Open process:
,GetModuleHandle()
,GetProcAddress()OpenProcess() - Write DLL path:
,VirtualAllocEx()WriteProcessMemory() - Load DLL:
withCreateRemoteThread()LoadLibrary()
Alternative APIs:
NTCreateThreadEx(), RtlCreateUserThread()
Reflective DLL Injection
Load DLL without normal Windows API calls:
- DLL mapped directly into process memory
- Imports resolved manually
- Relocations fixed in-memory
called directlyDllMain()
Thread Hijacking
- Find target thread:
,CreateToolhelp32Snapshot()
,Thread32First()Thread32Next() - Open thread:
OpenThread() - Suspend thread:
SuspendThread() - Write DLL path:
,VirtualAllocEx()WriteProcessMemory() - Resume with payload:
ResumeThread()
Process Hollowing (RunPE)
Launch legitimate process suspended, replace its memory with malicious PE:
Typical workflow:
- Spawn suspended process:
STARTUPINFOA si = { sizeof(si) }; PROCESS_INFORMATION pi; CreateProcessA("C:\\Windows\\Microsoft.NET\\Framework32\\v4.0.30319\\RegAsm.exe", NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
-
Parse malicious PE headers to get
, sections,SizeOfImageEntryPoint -
Unmap original image:
/NtUnmapViewOfSection()ZwUnmapViewOfSection() -
Allocate new memory:
with RWX permissionsVirtualAllocEx() -
Copy payload:
- headers first, then sectionsWriteProcessMemory() -
Patch thread context:
- setSetThreadContext()
to payload entry pointEIP/RIP -
Resume execution:
ResumeThread()
Common host processes:
(signed .NET Framework binary)RegAsm.exe
(developer tooling)MSBuild.exe
(system utility)rundll32.exe
MSBuild path resolution:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe C:\Windows\System32\MSBuild.exe C:\Windows\SysWOW64\MSBuild.exe
Hooking Techniques
| Type | Description |
|---|---|
| SSDT Hooking | Modify System Service Descriptor Table pointers to kernel functions |
| IRP Hooking | Hook I/O Request Packets for device communication (DKOM) |
| IAT Hooking | Modify Import Address Table to hijack function calls |
| EAT Hooking | Hook Export Address Table from userland |
| Inline Hooks | Modify function code directly (jump at beginning) |
Detection Strategies
Process Hollowing Detection
-
Alert on
processes that:CREATE_SUSPENDED- Never create GUI/console windows
- Allocate RWX memory regions
- Make outbound connections
-
Monitor API sequence:
→NtUnmapViewOfSection
→VirtualAllocExWriteProcessMemory -
Hunt for unusual hosts:
from user-writable pathsMSBuild.exe
without .NET contextRegAsm.exe
parented by short-lived loadersrundll32.exe
-
ATT&CK mapping:
- T1127.001 (Trusted Developer Utilities Proxy Execution: MSBuild)
- T1055.012 (Process Injection: Process Hollowing)
Anti-Analysis Detection
-
Flag processes that:
- Query multiple locale/keyboard APIs early
- Exit with no observable activity
- Call anti-VM APIs (BIOS strings, PnP devices, disk model)
-
Monitor for emulator fingerprints:
- Search for
,MpVmp*
,VFS_*
exportsThrdMgr_* - Detect delayed execution (10-30 minute timeouts)
- Search for
Network-Based Detection
-
TLS pinning indicators:
usage with certificate validationSslStream- Compressed traffic (GZip)
- Chunked responses (~16KB segments)
-
Argument gatekeeping:
- Benign-looking CLI switches (e.g.,
)/i:--type=renderer - Process exits if switch absent
- Benign-looking CLI switches (e.g.,
Analysis Workflow
Static Analysis
- Import analysis: Look for suspicious API combinations
- String extraction: Find URLs, file paths, registry keys
- PE header inspection: Check for packed/obfuscated sections
- Resource section: Look for embedded payloads
Dynamic Analysis
- API monitoring: Track suspicious API sequences
- Memory scanning: Look for injected code, decrypted strings
- Network capture: Monitor C2 communication
- Process tree: Identify parent-child relationships
Memory Forensics
- Scan for RWX regions in suspicious processes
- Look for hollowed processes (mismatched PE headers)
- Identify injected threads (unusual thread start addresses)
- Extract decrypted strings from memory dumps
References
- Unit42 – DarkCloud Stealer Infection Chain
- Check Point – Under the Pure Curtain
- Unit42 – PhantomVAI Loader
- MITRE ATT&CK – T1127.001 MSBuild
- VMDetector – Open-source VM detection
Usage Tips
- For detection rules: Focus on API sequences rather than single calls
- For hunting: Correlate multiple indicators (API calls + network + file system)
- For analysis: Use both static and dynamic methods for comprehensive coverage
- For research: Check references for latest campaign details and TTPs