Query Details
// PowerShell Self-Pwn // https://www.proofpoint.com/us/blog/threat-insight/clipboard-compromise-powershell-self-pwn // The Proofpoint blog outlines a social engineering tactic where threat actors deceive users into copying and pasting malicious PowerShell scripts, causing malware infections. Groups like TA571 use fake error messages to prompt script execution, delivering malware such as DarkGate and NetSupport. Despite needing significant user interaction, the attack's success hinges on sophisticated social engineering. I have developed a custom detection PowerShell Self-Pwn KQL to identify such scenarios and assist SecOps in isolating affected devices. let NaiveUser = IdentityInfo | where isempty(AssignedRoles) // Non Technical Naive Users ;P | summarize arg_max(Timestamp, *) by AccountUpn | distinct AccountUpn; let UserEPPSExec = DeviceEvents | where ActionType == @"GetClipboardData" // Execute PowerShell command from clipboard paste | where InitiatingProcessFileName == @"powershell.exe" | join NaiveUser on $left.InitiatingProcessAccountUpn == $right.AccountUpn | distinct DeviceName; DeviceProcessEvents | where InitiatingProcessFileName has "powershell.exe" and InitiatingProcessCommandLine has "-EncodedCommand" | where AccountName != "system" and AccountName !="local service" and AccountName !="administrator" | where DeviceName has_any(UserEPPSExec) // User execute a encoded powershell command to evade detection //
This KQL (Kusto Query Language) script is designed to detect a specific type of social engineering attack involving PowerShell scripts. Here's a simplified breakdown of what the query does:
Identify Naive Users:
Detect Clipboard-Based PowerShell Execution:
Identify Encoded PowerShell Commands:
Overall, this query helps security operations teams detect and isolate devices where naive users might have been tricked into executing malicious PowerShell scripts, potentially leading to malware infections.

Steven Lim
Released: December 17, 2024
Tables
Keywords
Operators