↳ GitHub sourceAnalytics ruleMedium
PowerShell Encoded Command Execution (Living off the Land)
Description
Detects PowerShell or pwsh.exe launched with encoded command flags
(-EncodedCommand, -enc, -ec, -enco). Attackers encode commands in Base64
to obfuscate malicious payloads and bypass script-based controls.
Risk is elevated when a download cradle pattern is also detected.
Tune AllowlistedParents for known-safe management tools such as SCCM.
- Rule type
- Scheduled
- Version
- 1.0.4
- Declared status
- Available
- Query frequency
- 1h
- Query period
- 1h
- Trigger
- gt 0
Declared MITRE coverage
Declared sources
Metadata from the source file. No dependencies inferred from KQL.
Connectors
Data types
KQL query
Original query, unchanged.
let Lookback = 1h;
let EncodedFlagRegex = @'(?i)(^|\s)-(encodedcommand|enc|ec|enco)\b';
let AllowlistedParents = dynamic([
"SqlServer.exe", "ManagementStudio.exe", "devenv.exe",
"ccmexec.exe", "SMSAgent.exe"
]);
let DownloadCradlePatterns = dynamic([
"Net.WebClient", "WebRequest", "DownloadString", "DownloadFile",
"IEX", "Invoke-Expression", "Invoke-RestMethod", "Start-BitsTransfer"
]);
let MDE_Results =
DeviceProcessEvents
| where Timestamp >= ago(Lookback)
| where FileName in~ ("powershell.exe", "pwsh.exe")
| where ProcessCommandLine matches regex EncodedFlagRegex
| where not(InitiatingProcessFileName has_any (AllowlistedParents))
| extend
HasDownloadCradle = ProcessCommandLine has_any (DownloadCradlePatterns),
AccountName = InitiatingProcessAccountName,
AccountDomain = InitiatingProcessAccountDomain,
HostName = DeviceName,
EventTime = Timestamp
| project EventTime, HostName, AccountName, AccountDomain,
ProcessCommandLine, InitiatingProcessFileName, HasDownloadCradle;
let SecEvent_Results =
SecurityEvent
| where TimeGenerated >= ago(Lookback)
| where EventID == 4688
| where NewProcessName endswith "\\powershell.exe"
or NewProcessName endswith "\\pwsh.exe"
| where CommandLine matches regex EncodedFlagRegex
| where not(ParentProcessName has_any (AllowlistedParents))
| extend
HasDownloadCradle = CommandLine has_any (DownloadCradlePatterns),
AccountName = SubjectUserName,
AccountDomain = SubjectDomainName,
HostName = Computer,
EventTime = TimeGenerated,
ProcessCommandLine = CommandLine,
InitiatingProcessFileName = ParentProcessName
| project EventTime, HostName, AccountName, AccountDomain,
ProcessCommandLine, InitiatingProcessFileName, HasDownloadCradle;
union MDE_Results, SecEvent_Results
| extend RiskScore = iif(HasDownloadCradle, 2, 1)
| sort by RiskScore desc, EventTime desc
Declared entities
Related content
Links established from declared identifiers and solution manifests.
Source provenance
GitHubDisplayed values come from files in Azure/Azure-Sentinel. They describe the published template, not your workspace configuration.
- Commit
9800e51↗- Source identifier
7b2f4d1a-9c3e-4f72-8b1d-3e6a9f2c4b8d
GSTEP / CATALOG TRACKING
Added to catalog : 16 Sept 2026 · 05:49 UTC
Last change observed : 16 Sept 2026 · 05:49 UTC