T1027.004

Compile After Delivery

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.

Microsoft Sentinel / Defender
kusto
let CompilerPaths = dynamic([
  "csc.exe", "vbc.exe", "jsc.exe", "ilasm.exe", "msbuild.exe",
  "gcc", "g++", "cl.exe", "rc.exe", "mc.exe"
]);
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName in~ (CompilerPaths)
| where FolderPath has_any (
    "\\Windows\\Microsoft.NET\\",
    "\\Microsoft Visual Studio\\",
    "\\MinGW\\",
    "\\Temp\\",
    "\\AppData\\"
)
| where ProcessCommandLine !contains "\\Windows\\WinSxS\\"
    and ProcessCommandLine !contains "Visual Studio"
    and ProcessCommandLine !contains "msbuild /t:Build"
| extend IsCSC = FileName =~ "csc.exe"
| extend IsMSBuild = FileName =~ "msbuild.exe"
| extend SourceFromTemp = ProcessCommandLine has_any ("\\Temp\\", "\\AppData\\", "\\Users\\", "\\Downloads\\")
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
         InitiatingProcessFileName, InitiatingProcessCommandLine,
         IsCSC, IsMSBuild, SourceFromTemp
| sort by Timestamp desc
high severity high confidence

Data Sources

Process: Process Creation Command: Command Execution Microsoft Defender for Endpoint

Required Tables

DeviceProcessEvents

False Positives

  • Legitimate software development activity on developer workstations where devs compile projects in user home directories
  • MSBuild invocations by Visual Studio or CI/CD build agents that legitimately compile in workspace directories
  • Package managers and build tools (NuGet, npm, Cargo) that invoke compilers as part of dependency compilation
  • System administration scripts that use csc.exe to compile small C# utilities for automation tasks

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