T1027.004 Splunk · SPL

Detect Compile After Delivery in Splunk

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/

SPL Detection Query

Splunk (SPL)
spl
index=wineventlog sourcetype="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" EventCode=1
  (Image="*\\csc.exe" OR Image="*\\vbc.exe" OR Image="*\\ilasm.exe" OR Image="*\\msbuild.exe"
   OR Image="*\\jsc.exe" OR Image="*\\cl.exe")
| eval cmdline=lower(CommandLine)
| eval SourceFromTemp=if(match(cmdline, "(\\\\temp\\\\|\\\\appdata\\\\|\\\\downloads\\\\|\\\\users\\\\[^\\\\]+\\\\desktop)"), 1, 0)
| eval ParentSuspicious=if(match(lower(ParentImage), "(powershell|wscript|cscript|mshta|cmd)"), 1, 0)
| eval NoVisualStudio=if(NOT match(cmdline, "(visual studio|devenv|vstudio)"), 1, 0)
| eval SuspicionScore=SourceFromTemp + ParentSuspicious + NoVisualStudio
| where SuspicionScore >= 2
| table _time, host, User, Image, CommandLine, ParentImage, ParentCommandLine, SuspicionScore
| sort - _time
high severity high confidence

Detects .NET and native compiler execution with a composite suspicion scoring system. Assigns points for: source file in user-writable temp/download paths, suspicious parent process (scripting engine), and invocation outside Visual Studio context. A score of 2+ indicates likely malicious compile-after-delivery activity. MuddyWater's technique of having cmd.exe spawn csc.exe to compile downloaded C# source scores 3 on this scale.

Data Sources

Process: Process CreationCommand: Command ExecutionSysmon Event ID 1

Required Sourcetypes

XmlWinEventLog:Microsoft-Windows-Sysmon/Operational

False Positives & Tuning

  • Developers who use PowerShell scripts to drive compilation workflows will trigger the ParentSuspicious flag
  • Automated testing pipelines that run compilers from scripting contexts as part of CI build processes
  • MSBuild project files that reference source in non-standard locations for modular build systems
  • Software deployment scripts that compile helper utilities on first run in temp directories
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