Windows Script Executing PowerShell
Identifies a PowerShell process launched by either cscript.exe or wscript.exe. Observing Windows scripting processes executing a PowerShell script, may be indicative of malicious activity.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2020/02/18"
3integration = ["endpoint", "windows", "m365_defender", "sentinel_one_cloud_funnel"]
4maturity = "production"
5updated_date = "2026/09/18"
6
7[rule]
8author = ["Elastic"]
9description = """
10Identifies a PowerShell process launched by either cscript.exe or wscript.exe. Observing Windows scripting processes
11executing a PowerShell script, may be indicative of malicious activity.
12"""
13from = "now-9m"
14index = [
15 "winlogbeat-*",
16 "logs-endpoint.events.process-*",
17 "logs-windows.sysmon_operational-*",
18 "endgame-*",
19 "logs-m365_defender.event-*",
20 "logs-sentinel_one_cloud_funnel.*",
21]
22language = "eql"
23license = "Elastic License v2"
24name = "Windows Script Executing PowerShell"
25note = """## Triage and analysis
26
27### Investigating Windows Script Executing PowerShell
28
29The Windows Script Host (WSH) is an Windows automation technology, which is ideal for non-interactive scripting needs, such as logon scripting, administrative scripting, and machine automation.
30
31Attackers commonly use WSH scripts as their initial access method, acting like droppers for second stage payloads, but can also use them to download tools and utilities needed to accomplish their goals.
32
33This rule looks for the spawn of the `powershell.exe` process with `cscript.exe` or `wscript.exe` as its parent process.
34
35#### Possible investigation steps
36
37- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
38- Investigate commands executed by the spawned PowerShell process.
39- If unsigned files are found on the process tree, retrieve them and determine if they are malicious:
40 - Use a private sandboxed malware analysis system to perform analysis.
41 - Observe and collect information about the following activities:
42 - Attempts to contact external domains and addresses.
43 - File and registry access, modification, and creation activities.
44 - Service creation and launch activities.
45 - Scheduled task creation.
46 - Use the PowerShell Get-FileHash cmdlet to get the files' SHA-256 hash values.
47 - Search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
48- Determine how the script file was delivered (email attachment, dropped by other processes, etc.).
49- Investigate other alerts associated with the user/host during the past 48 hours.
50
51### False positive analysis
52
53- The usage of these script engines by regular users is unlikely. In the case of authorized benign true positives (B-TPs), exceptions can be added.
54
55### Response and remediation
56
57- Initiate the incident response process based on the outcome of the triage.
58- Isolate the involved host to prevent further post-compromise behavior.
59- If the triage identified malware, search the environment for additional compromised hosts.
60 - Implement temporary network rules, procedures, and segmentation to contain the malware.
61 - Stop suspicious processes.
62 - Immediately block the identified indicators of compromise (IoCs).
63 - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
64- Remove and block malicious artifacts identified during triage.
65- If the malicious file was delivered via phishing:
66 - Block the email sender from sending future emails.
67 - Block the malicious web pages.
68 - Remove emails from the sender from mailboxes.
69 - Consider improvements to the security awareness program.
70- Reimage the host operating system and restore compromised files to clean versions.
71- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
72- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
73- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
74"""
75
76setup = """## Setup
77
78This rule is designed for data generated by [Elastic Defend](https://www.elastic.co/security/endpoint-security), which provides native endpoint detection and response, along with event enrichments designed to work with our detection rules.
79
80Setup instructions: https://ela.st/install-elastic-defend
81
82### Additional data sources
83
84This rule also supports the following third-party data sources. For setup instructions, refer to the links below:
85
86- [Microsoft Defender XDR](https://ela.st/m365-defender)
87- [SentinelOne Cloud Funnel](https://ela.st/sentinel-one-cloud-funnel)
88- [Sysmon Event ID 1 - Process Creation](https://ela.st/sysmon-event-1-setup)
89"""
90
91references = ["https://www.elastic.co/security-labs/operation-bleeding-bear"]
92risk_score = 21
93rule_id = "f545ff26-3c94-4fd0-bd33-3c7f95a3a0fc"
94severity = "low"
95tags = [
96 "Domain: Endpoint",
97 "OS: Windows",
98 "Use Case: Threat Detection",
99 "Tactic: Initial Access",
100 "Tactic: Execution",
101 "Resources: Investigation Guide",
102 "Data Source: Elastic Endgame",
103 "Data Source: Elastic Defend",
104 "Data Source: Sysmon",
105 "Data Source: Microsoft Defender XDR",
106 "Data Source: SentinelOne",
107 "Noise: High",
108 "Performance: Normal",
109 "Profile: Aggressive",
110 "Rule Type: Event Correlation (EQL)",
111 "Platform: Windows",
112]
113timestamp_override = "event.ingested"
114type = "eql"
115
116query = '''
117process where host.os.type == "windows" and event.type == "start" and
118 process.parent.name : ("cscript.exe", "wscript.exe") and process.name : "powershell.exe" and
119 not (
120 process.parent.name : "wscript.exe" and
121 process.parent.args : "?:\\ProgramData\\intune-drive-mapping-generator\\IntuneDriveMapping-VBSHelper.vbs" and
122 process.parent.args : "?:\\ProgramData\\intune-drive-mapping-generator\\DriveMapping.ps1"
123 )
124'''
125
126
127[[rule.threat]]
128framework = "MITRE ATT&CK"
129
130[[rule.threat.technique]]
131id = "T1566"
132name = "Phishing"
133reference = "https://attack.mitre.org/techniques/T1566/"
134
135[[rule.threat.technique.subtechnique]]
136id = "T1566.001"
137name = "Spearphishing Attachment"
138reference = "https://attack.mitre.org/techniques/T1566/001/"
139
140[rule.threat.tactic]
141id = "TA0001"
142name = "Initial Access"
143reference = "https://attack.mitre.org/tactics/TA0001/"
144
145[[rule.threat]]
146framework = "MITRE ATT&CK"
147
148[[rule.threat.technique]]
149id = "T1059"
150name = "Command and Scripting Interpreter"
151reference = "https://attack.mitre.org/techniques/T1059/"
152
153[[rule.threat.technique.subtechnique]]
154id = "T1059.001"
155name = "PowerShell"
156reference = "https://attack.mitre.org/techniques/T1059/001/"
157
158[[rule.threat.technique.subtechnique]]
159id = "T1059.005"
160name = "Visual Basic"
161reference = "https://attack.mitre.org/techniques/T1059/005/"
162
163[[rule.threat.technique.subtechnique]]
164id = "T1059.007"
165name = "JavaScript"
166reference = "https://attack.mitre.org/techniques/T1059/007/"
167
168[rule.threat.tactic]
169id = "TA0002"
170name = "Execution"
171reference = "https://attack.mitre.org/tactics/TA0002/"
Triage and analysis
Investigating Windows Script Executing PowerShell
The Windows Script Host (WSH) is an Windows automation technology, which is ideal for non-interactive scripting needs, such as logon scripting, administrative scripting, and machine automation.
Attackers commonly use WSH scripts as their initial access method, acting like droppers for second stage payloads, but can also use them to download tools and utilities needed to accomplish their goals.
This rule looks for the spawn of the powershell.exe process with cscript.exe or wscript.exe as its parent process.
Possible investigation steps
- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
- Investigate commands executed by the spawned PowerShell process.
- If unsigned files are found on the process tree, retrieve them and determine if they are malicious:
- Use a private sandboxed malware analysis system to perform analysis.
- Observe and collect information about the following activities:
- Attempts to contact external domains and addresses.
- File and registry access, modification, and creation activities.
- Service creation and launch activities.
- Scheduled task creation.
- Observe and collect information about the following activities:
- Use the PowerShell Get-FileHash cmdlet to get the files' SHA-256 hash values.
- Search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
- Use a private sandboxed malware analysis system to perform analysis.
- Determine how the script file was delivered (email attachment, dropped by other processes, etc.).
- Investigate other alerts associated with the user/host during the past 48 hours.
False positive analysis
- The usage of these script engines by regular users is unlikely. In the case of authorized benign true positives (B-TPs), exceptions can be added.
Response and remediation
- Initiate the incident response process based on the outcome of the triage.
- Isolate the involved host to prevent further post-compromise behavior.
- If the triage identified malware, search the environment for additional compromised hosts.
- Implement temporary network rules, procedures, and segmentation to contain the malware.
- Stop suspicious processes.
- Immediately block the identified indicators of compromise (IoCs).
- Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
- Remove and block malicious artifacts identified during triage.
- If the malicious file was delivered via phishing:
- Block the email sender from sending future emails.
- Block the malicious web pages.
- Remove emails from the sender from mailboxes.
- Consider improvements to the security awareness program.
- Reimage the host operating system and restore compromised files to clean versions.
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
References
Related rules
- Execution via GitHub Actions Runner
- Disabling Windows Defender Security Settings via PowerShell
- Enumeration Command Spawned via WMIPrvSE
- Potential DLL Side-Loading via Trusted Microsoft Programs
- Suspicious Cmd Execution via WMI