I triaged this pattern hundreds of times. Here's the KQL that actually works (with noise reduction built in)
This content describes a practical detection approach for identifying encoded PowerShell commands using Kusto Query Language (KQL) in Microsoft Sentinel. The detection method incorporates a weighted scoring model that reduces noise by considering multiple indicators beyond the simple presence of encoded commands, such as the parent process, download-related keywords, execution flags, and execution paths. The approach aims to improve alert accuracy and reduce false positives in enterprise environments. It is not a vulnerability or exploit but a detection technique shared on a public forum.
AI Analysis
Technical Summary
The post shares a refined KQL detection pattern for encoded PowerShell commands that incorporates noise reduction through a weighted scoring system. Instead of triggering alerts solely on the presence of the '-enc' flag, the model assigns scores based on contextual indicators like the spawning process (e.g., Office apps or browsers), presence of download cradles (e.g., DownloadString, WebClient), execution from user-writable paths, and execution flags such as hidden window or bypass policy. Alerts are triggered only when the cumulative score exceeds a threshold, significantly reducing false positives from legitimate tools like SCCM or Tanium. The author also provides operational guidance on tuning the detection, building allowlists, and handling PowerShell version 2 blind spots. This is a detection methodology, not a security vulnerability or exploit.
Potential Impact
There is no direct security impact or vulnerability described. The content improves detection capabilities for security operations centers by reducing alert noise and enhancing the identification of potentially malicious encoded PowerShell commands. This can lead to more effective incident response and fewer missed detections due to alert fatigue.
Mitigation Recommendations
This is a detection technique rather than a vulnerability requiring patching. No patch or official fix applies. Security teams are advised to implement and tune the provided KQL detection pattern in their Microsoft Sentinel environments, build allowlists for benign parent processes, adjust alert thresholds based on noise levels, and monitor alerts with the suggested scoring model. No additional remediation is required beyond adopting this improved detection approach.
I triaged this pattern hundreds of times. Here's the KQL that actually works (with noise reduction built in)
Description
This content describes a practical detection approach for identifying encoded PowerShell commands using Kusto Query Language (KQL) in Microsoft Sentinel. The detection method incorporates a weighted scoring model that reduces noise by considering multiple indicators beyond the simple presence of encoded commands, such as the parent process, download-related keywords, execution flags, and execution paths. The approach aims to improve alert accuracy and reduce false positives in enterprise environments. It is not a vulnerability or exploit but a detection technique shared on a public forum.
Reddit Discussion
Most encoded PowerShell detections I see shared online look like this:
SecurityEvent
| where EventID == 4688
| where CommandLine has "-enc"
Deploy that in a real enterprise and you'll get 100-200 hits a day, 95% of which are SCCM, Tanium, or Microsoft's own tooling. Analysts learn to ignore it within two weeks. That's how real detections get missed.
After a decade in SOC operations I built a weighted scoring model for this instead. The encoding flag alone scores zero. It's the combination of indicators that triggers the alert:
**Score modifiers:**
- +30: Office app or browser spawned PowerShell (Word, Excel, Outlook, Chrome, Edge)
- +25: Download cradle keywords in command line (DownloadString, WebClient, IWR, wget)
- +20: Execution from user-writable path (\Temp\, \AppData\, \Downloads\)
- +15: Hidden window flag (-WindowStyle Hidden)
- +15: Execution policy bypass (-ExecutionPolicy Bypass)
- +10: Non-interactive / no-profile flags
A legitimate SCCM script that happens to use -enc scores 0. A phishing-delivered payload that spawns from Outlook with a download cradle and hidden window scores 70. You set the threshold at 30 or 40 and the noise drops dramatically.
**Full production KQL in the article** (too long to paste here in full, but the core structure is):
let BenignParents = dynamic(["taniumclient.exe","ccmexec.exe","devenv.exe","msbuild.exe"]);
let HighRiskParents = dynamic(["winword.exe","excel.exe","outlook.exe","chrome.exe","msedge.exe"]);
let DownloadCradles = dynamic(["downloadstring","webclient","invoke-webrequest","iwr"]);
SecurityEvent
| where EventID == 4688
| where NewProcessName endswith "\\powershell.exe"
| where CommandLine matches regex @'(?i)-e[nN]?[cC]([oO][dD][eE][dD][cC][oO][mM][mM][aA][nN][dD])?[\s:]'
| where not(ParentProcessName has_any (BenignParents))
| extend Score = 0
| extend Score = Score + iff(ParentName in~ (HighRiskParents), 30, 0)
| extend Score = Score + iff(CmdLower has_any (DownloadCradles), 25, 0)
// ... (continues with remaining modifiers)
| extend AlertSeverity = case(Score >= 60, "Critical", Score >= 40, "High", Score >= 20, "Medium", "Low")
| where Score >= 20
**A few things I've learned deploying this:**
Build your BenignParents allowlist before deploying. Run the basic detection against 7 days of logs, export ParentName, add anything appearing 20+ times that's legitimate in your environment.
Start threshold at 30 in noisy environments. Tune down as you build confidence.
Set alert grouping by Computer in Sentinel with a 24h window or you'll get 20 identical incidents instead of one.
PowerShell 2.0 is a blind spot. Add a separate rule for `-version 2` combined with encoding flags — no script block logging at all in v2.
When this fires High or Critical: decode the Base64 first before isolating. You need to know if it's fileless before you pull the network cable.
MITRE: T1059.001 + T1027. When combined with an Office parent, the chain is T1566.001 → T1204.002 → T1059.001 → T1105.
Full article with complete KQL, scoring table, and triage steps: socauthority.com/blog/how-to-detect-powershell-encoded-commands-sentinel-kql/
Happy to answer questions or discuss tuning approaches for specific environments.
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
The post shares a refined KQL detection pattern for encoded PowerShell commands that incorporates noise reduction through a weighted scoring system. Instead of triggering alerts solely on the presence of the '-enc' flag, the model assigns scores based on contextual indicators like the spawning process (e.g., Office apps or browsers), presence of download cradles (e.g., DownloadString, WebClient), execution from user-writable paths, and execution flags such as hidden window or bypass policy. Alerts are triggered only when the cumulative score exceeds a threshold, significantly reducing false positives from legitimate tools like SCCM or Tanium. The author also provides operational guidance on tuning the detection, building allowlists, and handling PowerShell version 2 blind spots. This is a detection methodology, not a security vulnerability or exploit.
Potential Impact
There is no direct security impact or vulnerability described. The content improves detection capabilities for security operations centers by reducing alert noise and enhancing the identification of potentially malicious encoded PowerShell commands. This can lead to more effective incident response and fewer missed detections due to alert fatigue.
Mitigation Recommendations
This is a detection technique rather than a vulnerability requiring patching. No patch or official fix applies. Security teams are advised to implement and tune the provided KQL detection pattern in their Microsoft Sentinel environments, build allowlists for benign parent processes, adjust alert thresholds based on noise levels, and monitor alerts with the suggested scoring model. No additional remediation is required beyond adopting this improved detection approach.
Technical Details
- Source Type
- Subreddit
- blueteamsec+AskNetsec+Information_Security
- Reddit Score
- 0
- Discussion Level
- minimal
- Content Source
- reddit_link_post
- Post Type
- link
- Domain
- null
- Newsworthiness Assessment
- {"score":27,"reasons":["external_link","established_author","very_recent"],"isNewsworthy":true,"foundNewsworthy":[],"foundNonNewsworthy":[]}
- Has External Source
- true
- Trusted Domain
- false
Threat ID: 6a2892e58dd33fbd858e36f5
Added to database: 6/9/2026, 10:25:41 PM
Last enriched: 6/9/2026, 10:25:46 PM
Last updated: 6/10/2026, 4:25:50 AM
Views: 7
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.