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.
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 Data Sources
Required Tables
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
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.