Detect Polymorphic Code in Splunk
Adversaries use polymorphic (also called metamorphic or mutating) code to evade signature-based defenses by altering the malware's runtime footprint on each execution. The code mutates into a different version while preserving its original functionality — defeating hash-based and pattern-based detection. Mutation engines perform operations like instruction substitution, code transposition, dead code insertion, register reassignment, and encryption key rotation. BendyBear (attributed to APT41/Winnti) is a documented example. Polymorphic code is often combined with other techniques: software packing, command obfuscation, and encrypted/encoded payloads to create layered evasion. Detection must rely on behavioral indicators rather than static signatures.
MITRE ATT&CK
- Tactic
- Defense Evasion
- Technique
- T1027 Obfuscated Files or Information
- Sub-technique
- T1027.014 Polymorphic Code
- Canonical reference
- https://attack.mitre.org/techniques/T1027/014/
SPL Detection Query
index=windows (sourcetype="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" OR sourcetype="WinEventLog:Microsoft-Windows-Sysmon/Operational")
| eval EventCode=coalesce(EventCode, event_id)
| search EventCode IN (1, 7, 11)
| eval detection_type=case(
EventCode=11 AND match(lower(TargetFilename), "\.(exe|dll|scr)$") AND match(lower(TargetFilename), "\\(temp|appdata|programdata|public)\\") AND match(lower(Image), "(powershell|cmd|wscript|cscript|mshta)\.exe"), "pe_staged_by_interpreter",
EventCode=1 AND match(lower(Image), "powershell\.exe") AND match(CommandLine, "(?i)(WriteAllBytes|Set-Content.*\.exe|VirtualAlloc|VirtualProtect|WriteProcessMemory)"), "memory_manipulation_api",
EventCode=1 AND match(lower(Image), "cmd\.exe") AND match(CommandLine, "(?i)copy.*\.exe.*&&.*start"), "binary_copy_execute",
EventCode=7 AND NOT match(lower(ImageLoaded), "(windows|program files|system32|syswow64)") AND match(lower(ImageLoaded), "\\(temp|appdata|programdata|public)\\"), "unsigned_dll_load_from_staging",
true(), null()
)
| search detection_type=*
| eval risk_score=case(
detection_type="memory_manipulation_api", 85,
detection_type="binary_copy_execute", 70,
detection_type="pe_staged_by_interpreter", 65,
detection_type="unsigned_dll_load_from_staging", 75,
true(), 50
)
| table _time, Computer, detection_type, risk_score, Image, CommandLine, TargetFilename, ImageLoaded, ParentImage
| sort -risk_score EventCode 7 (ImageLoad) for unsigned DLLs loaded from temp/appdata staging directories is a strong indicator of polymorphic loaders that drop and load modified DLL variants. EventCode 1 with PowerShell WriteAllBytes or VirtualAlloc suggests in-memory binary manipulation. Detection confidence is low-medium due to legitimate use; behavioral context from surrounding events is essential.
Other platforms for T1027.014
Testing Methodology
Validate this detection against 4 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1Self-Modifying Binary Simulation (PowerShell WriteAllBytes)
Expected signal: Sysmon EventCode 11 (FileCreate) for svchost32.exe written to %TEMP%\polytest. EventCode 1 (ProcessCreate) for powershell.exe with 'WriteAllBytes' in CommandLine. PowerShell Script Block Log EventCode 4104 will capture the full script.
- Test 2High-Entropy Binary Drop to AppData (Simulated Mutated Payload)
Expected signal: Sysmon EventCode 11 for explorer32.exe creation in %APPDATA%\Microsoft\Windows\Themes by powershell.exe. The file will have high entropy due to GZip compression.
- Test 3Binary Copy-Then-Execute Pattern (Mutation Simulation)
Expected signal: Sysmon EventCode 11 (FileCreate) for variant_001.exe and variant_002.exe in %TEMP%. EventCode 1 for cmd.exe with 'copy' and '&&' pattern in CommandLine.
- Test 4Unsigned DLL Load from AppData (Polymorphic DLL Variant)
Expected signal: Sysmon EventCode 11 for theme32.dll written to %APPDATA% by powershell.exe. EventCode 7 (ImageLoad) for rundll32.exe loading the DLL from a non-Windows/Program Files path. EventCode 1 for rundll32.exe process.
References (5)
- https://attack.mitre.org/techniques/T1027/014
- https://unit42.paloaltonetworks.com/bendybear/
- https://www.blackberry.com/us/en/solutions/endpoint-security/ransomware-protection/polymorphic-malware
- https://www.sentinelone.com/cybersecurity-101/threat-intelligence/what-is-polymorphic-malware
- https://medium.com/@shellseekerscyber/explainer-packed-malware-16f09cc75035
Unlock Pro Content
Get the full detection package for T1027.014 including response playbook, investigation guide, and atomic red team tests.