3 minmedium
Malware development trick 68: Module overloading. Simple C example
Module overloading overwrites a mapped legitimate DLL's memory with a complete replacement PE payload, executing custom code under a trusted backing file identity to evade memory integrity checks. The technique maps WsmSvc.dll as SEC_IMAGE, then overwrites its in-memory contents with a custom DLL payload. Relocations and imports are manually resolved before calling the payload entry point. The backing file remains WsmSvc.dll while executed code belongs to the replacement PE, creating a mismatch between mapped-file identity and actual memory contents.
Sens:LowConf:highAnalyzed:2026-11-05Z.ai
Authors: cocomelonc
Source:Malpedia
Improve this report
Send corrections, useful missing information, or quality feedback. It is private and will not appear as a comment.
Detection / HunterZ.ai
Immediate Actions
- Monitor for VirtualProtect calls changing SEC_IMAGE regions to PAGE_READWRITE
- Hunt for processes where mapped file name disagrees with in-memory PE headers
Key Takeaways
- Carrier DLL is WsmSvc.dll from System32, chosen for sufficient SizeOfImage capacity
- Payload is a custom x64 DLL compiled with MinGW-w64 using -nostdlib and direct DllMain entry
- MEM_IMAGE type persists after copy-on-write makes pages private to the process
- GetMappedFileNameW still reports the carrier file despite replaced PE contents in memory
- Technique rejects payloads needing TLS, delay imports, CLR, load config, or exception tables
Attack Chain
- Preparation: PoC binary hack.exe reads payload DLL meow.dll from disk into heap buffer
- Mapping: Creates SEC_IMAGE mapping of System32\WsmSvc.dll as carrier without calling its DllMain
- Overwriting: Makes carrier view writable, copies payload PE headers and sections over carrier memory
- Resolution: Applies base relocations and resolves imports via LoadLibraryA and GetProcAddress
- Execution: Calls payload entry point; GetMappedFileNameW still reports WsmSvc.dll as backing file
Affected Systems
- Windows x64 systems
Detection Engineering Assessment
Hunting Hypotheses
| Hypothesis | Telemetry | Stage | FP Risk |
|---|---|---|---|
| VirtualProtect changing SEC_IMAGE mapped regions to PAGE_READWRITE followed by memcpy into that region (T1055.002) | Sysmon Event ID 8 | Defense Evasion | Medium — normal loader applies relocations to image pages |
| GetMappedFileNameW reporting a backing file whose PE headers differ from bytes at the mapped address (T1027) | EDR memory scan results | Execution | Low — rare in normal operations |
| LoadLibraryA calls outside normal loader context resolving imports for a manually mapped PE region (T1574) | EDR API call telemetry | Execution | Low — legitimate loaders use internal mechanisms |
Required Log Sources
- Sysmon Event ID 8
- Sysmon Event ID 10
- Sysmon Event ID 1
- EDR API call telemetry
- EDR memory scan results
Control Gaps
- MEM_IMAGE type does not verify memory contents match backing file
- Backing file signature does not authenticate modified in-memory contents
- GetMappedFileNameW reports carrier identity even after full PE replacement
Recommendations
Infrastructure Hardening
- Enable EDR memory integrity scanning if supported
- Deploy memory-to-file content comparison for image-mapped regions
User Protection
- Ensure EDR covers MapViewOfFile and VirtualProtect API call telemetry
- Block execution from image regions with modified backing file content
MITRE ATT&CK Mapping
MITRE ATT&CK Mapping6 techniques
Tactic
Execution
Tactic
Privilege Escalation