T1027.004 Google Chronicle · YARA-L

Detect Compile After Delivery in Google Chronicle

Adversaries may attempt to make payloads difficult to discover and analyze by delivering files to victims as uncompiled code. Text-based source code files may subvert analysis and scrutiny from protections targeting executables/binaries. These payloads will need to be compiled before execution; typically via native utilities such as csc.exe (C# compiler), ilasm.exe (.NET assembler), or GCC/MinGW. Source code payloads may also be encrypted or encoded. Threat actors including MuddyWater, Gamaredon Group, Rocke, Cardinal RAT, and DarkWatchman have used this technique to compile malware on victim systems using built-in compiler utilities.

MITRE ATT&CK

Tactic
Defense Evasion
Technique
T1027 Obfuscated Files or Information
Sub-technique
T1027.004 Compile After Delivery
Canonical reference
https://attack.mitre.org/techniques/T1027/004/

YARA-L Detection Query

Google Chronicle (YARA-L)
yaral
rule t1027_004_compile_after_delivery {
  meta:
    author = "Argus Detection Engineering"
    description = "Detects T1027.004 Compile After Delivery - compiler binaries executing with source from user-writable paths, spawned by script interpreters"
    mitre_attack_technique = "T1027.004"
    mitre_attack_tactic = "Defense Evasion"
    severity = "HIGH"
    confidence = "HIGH"
    created = "2026-04-13"
    reference = "https://attack.mitre.org/techniques/T1027/004/"

  events:
    $e.metadata.event_type = "PROCESS_LAUNCH"
    $e.principal.process.file.full_path = /(?i)(csc\.exe|vbc\.exe|ilasm\.exe|msbuild\.exe|jsc\.exe|cl\.exe|rc\.exe|mc\.exe|\bgcc\b|\bg\+\+\b)/
    (
      $e.target.process.command_line = /(?i)(\\temp\\|\\appdata\\|\\downloads\\|\\users\\[^\\]+\\desktop)/
      or $e.target.process.file.full_path = /(?i)(\\temp\\|\\appdata\\|\\downloads\\)/
    )
    not $e.target.process.command_line = /(?i)(\\windows\\winsxs\\|visual studio|devenv|vstudio)/
    $e.principal.process.file.full_path = /(?i)(powershell\.exe|wscript\.exe|cscript\.exe|mshta\.exe|cmd\.exe|wmic\.exe|python\.exe)/
    $hostname = $e.principal.hostname
    $user = $e.principal.user.userid

  match:
    $hostname, $user over 10m

  condition:
    #e >= 1
}
high severity high confidence

Chronicle YARA-L 2.0 rule detecting compile-after-delivery by matching PROCESS_LAUNCH events where a compiler binary is invoked by a script interpreter (PowerShell, WScript, CScript, MSHTA) and the command line references user-writable paths. Maps to T1027.004.

Data Sources

Google Chronicle UDM (Windows Endpoint)Sysmon forwarded via Chronicle ForwarderMicrosoft Defender for Endpoint via Chronicle integration

Required Tables

UDM events (PROCESS_LAUNCH)

False Positives & Tuning

  • Developer workstations with Visual Studio Code remote extensions that invoke csc.exe via integrated terminal (PowerShell parent) with workspace files under user AppData
  • Managed enterprise build agents (Azure Pipelines, Jenkins) running on developer hardware where msbuild is invoked by PowerShell bootstrap scripts
  • Security tooling such as BloodHound, Covenant, or Cobalt Strike simulators used in authorized red team exercises that compile payloads on endpoint
Download portable Sigma rule (.yml)

Other platforms for T1027.004


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 1Compile and Execute C# Payload via csc.exe

    Expected signal: Sysmon Event ID 11: payload.cs created in %TEMP%. Sysmon Event ID 1: csc.exe with /out: argument pointing to %TEMP%. Sysmon Event ID 11: compiled_payload.exe created. Sysmon Event ID 1: compiled_payload.exe execution.

  2. Test 2MSBuild Execution of Inline C# Task (LOLBin Abuse)

    Expected signal: Sysmon Event ID 11: evil.proj created in %TEMP%. Sysmon Event ID 1: MSBuild.exe process creation with %TEMP%\evil.proj argument. The code executes within the MSBuild process itself — no separate child process for the C# code.

  3. Test 3Compile C Source Code with GCC (Linux/macOS)

    Expected signal: Process creation events: gcc with /tmp/payload.c argument, then compiled_payload execution. Syslog/auditd: execve syscalls for gcc and the compiled binary. File creation events for /tmp/payload.c and /tmp/compiled_payload.

  4. Test 4PowerShell Spawning csc.exe to Compile Downloaded Source

    Expected signal: Sysmon Event ID 1: powershell.exe with Set-Content and Start-Process commands. Sysmon Event ID 11: downloaded.cs and output.exe created in %TEMP%. Sysmon Event ID 1: csc.exe with parent PowerShell. Sysmon Event ID 1: output.exe executed.

Unlock Pro Content

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

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections