Detect Compile After Delivery in Sumo Logic CSE
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/
Sumo Detection Query
_sourceCategory=*windows*sysmon* OR _sourceCategory=*endpoint*
| where EventID = "1"
| parse field=Image "*\\*" as image_dir, image_file nodrop
| where image_file in ("csc.exe", "vbc.exe", "ilasm.exe", "msbuild.exe", "jsc.exe", "cl.exe", "gcc", "g++", "rc.exe", "mc.exe")
| eval cmdline_lower = toLowerCase(CommandLine)
| eval source_from_temp = if(cmdline_lower matches ".*\\\\(temp|appdata|downloads|desktop)\\\\.*", 1, 0)
| eval parent_suspicious = if(toLowerCase(ParentImage) matches ".*(powershell|wscript|cscript|mshta|cmd\.exe|python).*", 1, 0)
| eval no_dev_env = if(!(cmdline_lower matches ".*(visual studio|devenv|vstudio|winsxs).*"), 1, 0)
| eval suspicion_score = source_from_temp + parent_suspicious + no_dev_env
| where suspicion_score >= 2
| eval compiler_type = if(image_file = "msbuild.exe", "MSBuild",
if(image_file in ("csc.exe", "vbc.exe", "jsc.exe", "ilasm.exe"), "DotNet",
if(image_file in ("gcc", "g++", "cl.exe"), "NativeCompiler", "Other")))
| fields _messageTime, Computer, User, image_file, CommandLine, ParentImage, ParentCommandLine, suspicion_score, compiler_type
| sort - _messageTime Sumo Logic CSE query detecting compile-after-delivery by identifying compiler binaries (csc.exe, vbc.exe, ilasm.exe, msbuild.exe, gcc, cl.exe) executing with suspicious parent processes and source files from user-writable locations. Uses suspicion scoring. Maps to T1027.004.
Data Sources
Required Tables
False Positives & Tuning
- Automated software packaging pipelines where csc.exe or msbuild.exe are invoked by cmd.exe from AppData local paths during per-user MSI installations
- Chocolatey, WinGet, or Scoop package managers that compile source packages during installation, often spawned from PowerShell under user AppData
- Game modding tools or creative software that bundle lightweight .NET compilers and invoke csc.exe from user home directories as part of scripting workflows
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.
- 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.
- 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.
- 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.
- 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.
References (5)
- https://attack.mitre.org/techniques/T1027/004/
- https://www.clearskysec.com/wp-content/uploads/2018/11/MuddyWater-Operations-in-Lebanon-and-Oman.pdf
- https://www.attackiq.com/2023/03/16/hiding-in-plain-sight/
- https://blog.trendmicro.com/trendlabs-security-intelligence/windows-app-runs-on-mac-downloads-info-stealer-and-adware/
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1027.004/T1027.004.md
Unlock Pro Content
Get the full detection package for T1027.004 including response playbook, investigation guide, and atomic red team tests.