Response playbooks, investigation guides, and Atomic Red Team tests are Pro-only. Upgrade to unlock the full detection package for T1027.014.
Upgrade to ProDetect Polymorphic Code in Google Chronicle
This detection identifies behaviors associated with polymorphic or metamorphic malware that mutates its code or binary footprint at runtime to evade signature-based defenses. Because the binary hash changes with each execution, detections focus on behavioral indicators rather than static signatures: repeated file writes of executables with changing hashes, use of known mutation/packing engines, self-modifying process memory patterns, abnormal entropy in dropped files, and processes that write then immediately execute new PE files from temporary or user-writable directories. Correlation of these behaviors — especially when combined with Command and Scripting Interpreter activity or injection patterns — provides high-confidence indicators of polymorphic malware activity.
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/
YARA-L Detection Query
rule polymorphic_code_multi_pe_write {
meta:
author = "argus-v1"
description = "Detects polymorphic malware writing multiple uniquely-hashed PE files to writable directories then executing from those paths"
severity = "HIGH"
mitre_attack_technique = "T1027.014"
mitre_attack_tactic = "TA0005"
events:
$write.metadata.event_type = "FILE_CREATION"
$write.target.file.mime_type = "application/x-dosexec"
(
$write.target.file.full_path = /(?i)\\temp\\/ or
$write.target.file.full_path = /(?i)\\appdata\\/ or
$write.target.file.full_path = /(?i)\\programdata\\/ or
$write.target.file.full_path = /(?i)\\users\\public\\/
)
$write.principal.process.file.full_path = $parent_proc
$write.principal.hostname = $host
$write.target.file.sha256 = $hash1
$exec.metadata.event_type = "PROCESS_LAUNCH"
$exec.principal.hostname = $host
(
$exec.target.process.file.full_path = /(?i)\\temp\\/ or
$exec.target.process.file.full_path = /(?i)\\appdata\\/ or
$exec.target.process.file.full_path = /(?i)\\programdata\\/
)
not $exec.target.process.file.full_path = /(?i)(chrome|firefox|msedge|teams|onedrive)\.(exe)$/
match:
$host, $parent_proc over 1h
outcome:
$risk_score = max(75)
$files_written = count($write.target.file.full_path)
$unique_hashes = count_distinct($write.target.file.sha256)
condition:
#write >= 3 and $exec and $unique_hashes >= 3
} Chronicle YARA-L 2.0 rule correlating FILE_CREATION events for PE files in writable directories with PROCESS_LAUNCH from those same directories, requiring at least 3 file write events with distinct SHA256 hashes from the same parent process over a 1-hour window — characteristic of polymorphic malware mutation and re-execution cycles.
Data Sources
Required Tables
False Positives & Tuning
- Legitimate browser update processes excluded by name may still trigger if new browser binaries are not in the exclusion list
- Software development environments writing and executing multiple build artifacts from temp directories
- Virtualization or container management software unpacking runtime components to writable paths
Other platforms for T1027.014
Testing Methodology
Validate this detection against 3 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 1Simulate Polymorphic PE Mutation via XOR Re-encoding
Expected signal: DeviceFileEvents: 5 FileCreated events in %TEMP% with distinct SHA256 hashes, all with InitiatingProcessFileName=powershell.exe. Sysmon EventID 11 entries for each variant_N.bin file.
- Test 2Drop and Execute Multiple Renamed Copies of a Binary (Hash-Change via Append)
Expected signal: DeviceFileEvents: 4 FileCreated events for svc_update_N.exe in %TEMP% with distinct SHA256 hashes. DeviceProcessEvents: 4 ProcessCreate events for svc_update_N.exe running from %TEMP% with parent cmd.exe. Sysmon EventID 11 and 1 for each iteration.
- Test 3BendyBear-Style In-Memory Stub via PowerShell Reflection (Simulation)
Expected signal: DeviceProcessEvents: PowerShell process with unusual memory allocation patterns. If Defender for Endpoint AMSI/behavior monitoring is enabled: alerts on VirtualAlloc+VirtualProtect RW->RX page permission flip from powershell.exe. Process creation event for powershell.exe with -ExecutionPolicy Bypass flag.
References (5)
- https://attack.mitre.org/techniques/T1027/014/
- https://www.sentinelone.com/cybersecurity-101/polymorphic-malware/
- https://unit42.paloaltonetworks.com/bendybear/
- https://www.linkedin.com/pulse/polymorphic-malware-how-it-works-detection-evasion-/
- https://medium.com/@understanding-polymorphic-code-in-malware
Unlock playbooks & atomic tests with Pro
Get the full detection package for T1027.014 — response playbook and atomic red team tests, plus investigation guidance and hunting queries.
df00tech Pro — £29/user/month