↳ Source GitHubRègle analytiqueMedium
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.
- Type de règle
- Scheduled
- Version
- 1.0.4
- Statut déclaré
- Available
- Fréquence
- 1h
- Période analysée
- 1h
- Déclenchement
- gt 0
Couverture MITRE déclarée
Sources déclarées
Métadonnées du fichier source. Aucune dépendance déduite du KQL.
Connecteurs
Types de données
Requête KQL
Requête originale, sans modification.
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
Entités déclarées
Contenus associés
Liens établis à partir des identifiants déclarés et des manifests des solutions.
Traçabilité de la source
GitHubLes valeurs affichées proviennent des fichiers du dépôt Azure/Azure-Sentinel. Elles décrivent le modèle publié, pas la configuration de votre workspace.
- Commit
9800e51↗- Identifiant source
7b2f4d1a-9c3e-4f72-8b1d-3e6a9f2c4b8d
GSTEP / SUIVI DU CATALOGUE
Ajouté au catalogue : 16 sept. 2026 · 05:49 UTC
Dernier changement observé : 16 sept. 2026 · 05:49 UTC