T1027.014 Google Chronicle · YARA-L

Detect Polymorphic Code in Google Chronicle

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/

YARA-L Detection Query

Google Chronicle (YARA-L)
yaral
rule t1027_014_polymorphic_code_behavioral {
  meta:
    author = "Argus Detection Engineering"
    description = "Detects behavioral indicators of polymorphic/metamorphic code: self-modifying binaries, mutation engine TTPs, and high-entropy executable staging"
    mitre_attack_tactic = "Defense Evasion"
    mitre_attack_technique = "T1027.014"
    severity = "HIGH"
    priority = "HIGH"

  events:
    // Pattern 1: Script interpreter staging a PE in a user-writable directory
    (
      $e1.metadata.event_type = "FILE_CREATION"
      $e1.principal.process.file.full_path = /(?i)(powershell|cmd|wscript|cscript|mshta)\.exe$/
      $e1.target.file.full_path = /(?i)\.(exe|dll|scr)$/
      $e1.target.file.full_path = /(?i)\\(temp|appdata|programdata|public)\\/
      $e1.principal.hostname = $hostname
    )
    OR
    // Pattern 2: Memory manipulation APIs in PowerShell command line
    (
      $e1.metadata.event_type = "PROCESS_LAUNCH"
      $e1.principal.process.file.full_path = /(?i)powershell\.exe$/
      $e1.target.process.command_line = /(?i)(WriteAllBytes|WriteProcessMemory|VirtualAlloc|VirtualProtect|NtWriteVirtualMemory)/
      $e1.principal.hostname = $hostname
    )
    OR
    // Pattern 3: cmd.exe binary copy-and-execute chain
    (
      $e1.metadata.event_type = "PROCESS_LAUNCH"
      $e1.principal.process.file.full_path = /(?i)cmd\.exe$/
      $e1.target.process.command_line = /(?i)copy.*\.exe.*&&.*start/
      $e1.principal.hostname = $hostname
    )
    OR
    // Pattern 4: Self-modifying binary (executable writes sibling PE to same directory)
    (
      $e1.metadata.event_type = "FILE_MODIFICATION"
      $e1.target.file.full_path = /(?i)\.(exe|dll|scr|bin)$/
      $e1.target.file.full_path = /(?i)\\(temp|appdata|programdata|public)\\/
      $e1.principal.process.file.full_path != /(?i)(setup|installer|update)\.exe$/
      $e1.principal.hostname = $hostname
    )

  condition:
    $e1
high severity medium confidence

Chronicle YARA-L 2.0 rule detecting T1027.014 Polymorphic Code behavioral patterns using UDM events. Covers script-host PE staging, PowerShell memory API calls, cmd.exe copy-execute chains, and self-modifying binary drops in staging directories.

Data Sources

Chronicle UDMWindows Sysmon via Chronicle forwarderMicrosoft Defender for Endpoint via Chronicle

Required Tables

UDM Events - FILE_CREATIONUDM Events - FILE_MODIFICATIONUDM Events - PROCESS_LAUNCH

False Positives & Tuning

  • Electron application auto-updaters (VS Code, Slack, Teams) that write new app.exe to AppData and relaunch
  • Antivirus or EDR products that use VirtualAlloc/VirtualProtect internally for legitimate memory scanning hooks
  • CI/CD agents (GitHub Actions runner, GitLab runner) on Windows build nodes that compile and stage executables in temp paths
Download portable Sigma rule (.yml)

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Unlock Pro Content

Get the full detection package for T1027.014 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections