Identify Execution of Script From User's Downloads Folder
Introduction
KQL Query:
// Detect Script Execution From User's Downloads Folder
// Detect Script Execution From User's Downloads Folder
DeviceProcessEvents
| where Timestamp > ago(1d) // Limit results to the last 24 hours
| where ActionType == "ProcessCreate" // Focus on process creation events
| where ProcessCommandLine has_any ("powershell.exe", "cscript.exe", "wscript.exe", "cmd.exe", "mshta.exe", "rundll32.exe")
or InitiatingProcessCommandLine has_any ("powershell.exe", "cscript.exe", "wscript.exe", "cmd.exe", "mshta.exe", "rundll32.exe")
| where (ProcessCommandLine contains @"C:\Users\" and ProcessCommandLine contains @"\Downloads\")
or (InitiatingProcessCommandLine contains @"C:\Users\" and InitiatingProcessCommandLine contains @"\Downloads\")
| extend UserName = tostring(split(ProcessCommandLine, @"C:\Users\")[1]) // Extract username for context
| extend UserName = iff(isnotempty(UserName), split(UserName, "\\")[0], "") // Extract the username before the first backslash
| extend ScriptPath = iff(ProcessCommandLine contains @"\Downloads\", ProcessCommandLine, InitiatingProcessCommandLine)
| project
Timestamp,
DeviceName,
UserName,
ProcessCommandLine,
InitiatingProcessFileName,
InitiatingProcessCommandLine,
ScriptPath,
ActionType
| sort by Timestamp descExplanation of the Query:
Use Case:
Notes:
Last updated