Identify Execution of Script From User's Downloads Folder
Introduction
The query filters for common scripting interpreters, such as powershell.exe
, cscript.exe
, wscript.exe
, and others, and checks if the parent process or command line references the C:\Users\<username>\Downloads\
path. This helps identify potential threats where an attacker may have dropped a malicious script in the Downloads folder and attempted to execute it.
KQL Query:
Explanation of the Query:
Filtering Process Creation Events :
The query starts by filtering for
ProcessCreate
events (ActionType == "ProcessCreate"
) within the last 24 hours (Timestamp > ago(1d)
).
Identifying Scripting Interpreters :
It looks for processes commonly used to execute scripts, such as
powershell.exe
,cscript.exe
,wscript.exe
,cmd.exe
,mshta.exe
, andrundll32.exe
. These are checked in both theProcessCommandLine
andInitiatingProcessCommandLine
.
Checking for Downloads Folder Path :
The query checks if the
ProcessCommandLine
orInitiatingProcessCommandLine
contains the stringC:\Users\<username>\Downloads\
. This ensures that the script execution originates from the Downloads folder.
Extracting Contextual Information :
The
UserName
is extracted from theProcessCommandLine
to provide additional context about the affected user.The
ScriptPath
is identified as either theProcessCommandLine
orInitiatingProcessCommandLine
that contains the Downloads folder path.
Projecting Relevant Columns :
The query projects relevant fields, such as
Timestamp
,DeviceName
,UserName
,ProcessName
,ProcessCommandLine
,InitiatingProcessCommandLine
, andScriptPath
for easier analysis.
Sorting Results :
The results are sorted by
Timestamp
in descending order to show the most recent events first.
Use Case:
This query is particularly useful for detecting post-exploitation activities, such as an attacker downloading a malicious script and executing it from the Downloads folder. Security teams can use this query in Microsoft Sentinel or other SIEM platforms to monitor for such behaviour and respond promptly to potential threats.
Notes:
False Positives : Legitimate scripts may also be executed from the Downloads folder. Analysts should review the results to differentiate between benign and malicious activity.
Customisation : The list of scripting interpreters can be expanded based on the organisation's environment and known attack vectors.
Performance : To optimise performance, consider narrowing the time range or filtering by specific devices/users if needed.
Last updated