Execution from Unusual Directory - Command Line
Identifies process execution from suspicious default Windows directories. This may be abused by adversaries to hide malware in trusted paths.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2020/10/30"
3integration = ["endpoint", "windows", "system", "m365_defender", "sentinel_one_cloud_funnel"]
4maturity = "production"
5updated_date = "2026/05/04"
6
7[transform]
8[[transform.osquery]]
9label = "Osquery - Retrieve DNS Cache"
10query = "SELECT * FROM dns_cache"
11
12[[transform.osquery]]
13label = "Osquery - Retrieve All Services"
14query = "SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services"
15
16[[transform.osquery]]
17label = "Osquery - Retrieve Services Running on User Accounts"
18query = """
19SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services WHERE
20NOT (user_account LIKE '%LocalSystem' OR user_account LIKE '%LocalService' OR user_account LIKE '%NetworkService' OR
21user_account == null)
22"""
23
24[[transform.osquery]]
25label = "Osquery - Retrieve Service Unsigned Executables with Virustotal Link"
26query = """
27SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, name, description, start_type, status, pid,
28services.path FROM services JOIN authenticode ON services.path = authenticode.path OR services.module_path =
29authenticode.path JOIN hash ON services.path = hash.path WHERE authenticode.result != 'trusted'
30"""
31
32
33[rule]
34author = ["Elastic"]
35description = """
36Identifies process execution from suspicious default Windows directories. This may be abused by adversaries to hide
37malware in trusted paths.
38"""
39from = "now-9m"
40index = [
41 "endgame-*",
42 "logs-endpoint.events.process-*",
43 "logs-m365_defender.event-*",
44 "logs-sentinel_one_cloud_funnel.*",
45 "logs-system.security*",
46 "logs-windows.forwarded*",
47 "logs-windows.sysmon_operational-*",
48 "winlogbeat-*",
49]
50language = "eql"
51license = "Elastic License v2"
52name = "Execution from Unusual Directory - Command Line"
53note = """## Triage and analysis
54
55### Investigating Execution from Unusual Directory - Command Line
56
57This rule looks for the execution of scripts from unusual directories. Attackers can use system or application paths to hide malware and make the execution less suspicious.
58
59> **Note**:
60> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/current/invest-guide-run-osquery.html) introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
61
62#### Possible investigation steps
63
64- 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.
65- Investigate other alerts associated with the user/host during the past 48 hours.
66- Examine the command line to determine which commands or scripts were executed.
67- Examine the host for derived artifacts that indicate suspicious activities:
68 - Analyze the script using a private sandboxed analysis system.
69 - Observe and collect information about the following activities in both the sandbox and the alert subject host:
70 - Attempts to contact external domains and addresses.
71 - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
72 - Examine the DNS cache for suspicious or anomalous entries.
73 - $osquery_0
74 - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
75 - Examine the host services for suspicious or anomalous entries.
76 - $osquery_1
77 - $osquery_2
78 - $osquery_3
79 - Retrieve the files' SHA-256 hash values using the PowerShell `Get-FileHash` cmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
80- Investigate potentially compromised accounts. Analysts can do this by searching for login events (for example, 4624) to the target host after the registry modification.
81
82### False positive analysis
83
84- If this activity is expected and noisy in your environment, consider adding exceptions — preferably with a combination of parent process executable and command line conditions.
85
86### Related rules
87
88- Process Execution from an Unusual Directory - ebfe1448-7fac-4d59-acea-181bd89b1f7f
89
90### Response and remediation
91
92- Initiate the incident response process based on the outcome of the triage.
93- Isolate the involved host to prevent further post-compromise behavior.
94- If the triage identified malware, search the environment for additional compromised hosts.
95 - Implement temporary network rules, procedures, and segmentation to contain the malware.
96 - Stop suspicious processes.
97 - Immediately block the identified indicators of compromise (IoCs).
98 - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
99- Remove and block malicious artifacts identified during triage.
100- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
101- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
102- 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).
103"""
104
105setup = """## Setup
106
107This 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.
108
109Setup instructions: https://ela.st/install-elastic-defend
110
111### Additional data sources
112
113This rule also supports the following third-party data sources. For setup instructions, refer to the links below:
114
115- [Microsoft Defender XDR](https://ela.st/m365-defender)
116- [SentinelOne Cloud Funnel](https://ela.st/sentinel-one-cloud-funnel)
117- [Sysmon Event ID 1 - Process Creation](https://ela.st/sysmon-event-1-setup)
118- [Windows Process Creation Logs](https://ela.st/audit-process-creation)
119"""
120
121references = [
122 "https://www.elastic.co/security-labs/elastic-protects-against-data-wiper-malware-targeting-ukraine-hermeticwiper",
123 "https://www.elastic.co/security-labs/hunting-for-lateral-movement-using-event-query-language",
124]
125risk_score = 47
126rule_id = "cff92c41-2225-4763-b4ce-6f71e5bda5e6"
127severity = "medium"
128tags = [
129 "Domain: Endpoint",
130 "OS: Windows",
131 "Use Case: Threat Detection",
132 "Tactic: Execution",
133 "Tactic: Defense Evasion",
134 "Resources: Investigation Guide",
135 "Data Source: Elastic Endgame",
136 "Data Source: Elastic Defend",
137 "Data Source: Windows Security Event Logs",
138 "Data Source: Microsoft Defender XDR",
139 "Data Source: Sysmon",
140 "Data Source: SentinelOne",
141]
142timestamp_override = "event.ingested"
143type = "eql"
144
145query = '''
146process where host.os.type == "windows" and event.type == "start" and
147 process.name : ("wscript.exe",
148 "cscript.exe",
149 "rundll32.exe",
150 "regsvr32.exe",
151 "cmstp.exe",
152 "RegAsm.exe",
153 "installutil.exe",
154 "mshta.exe",
155 "RegSvcs.exe",
156 "powershell.exe",
157 "pwsh.exe",
158 "cmd.exe") and
159
160 /* add suspicious execution paths here */
161 process.args : ("C:\\PerfLogs\\*",
162 "C:\\Users\\Public\\*",
163 "C:\\Windows\\Tasks\\*",
164 "C:\\Intel\\*",
165 "C:\\AMD\\Temp\\*",
166 "C:\\Windows\\AppReadiness\\*",
167 "C:\\Windows\\ServiceState\\*",
168 "C:\\Windows\\security\\*",
169 "C:\\Windows\\IdentityCRL\\*",
170 "C:\\Windows\\Branding\\*",
171 "C:\\Windows\\csc\\*",
172 "C:\\Windows\\DigitalLocker\\*",
173 "C:\\Windows\\en-US\\*",
174 "C:\\Windows\\wlansvc\\*",
175 "C:\\Windows\\Prefetch\\*",
176 "C:\\Windows\\Fonts\\*",
177 "C:\\Windows\\diagnostics\\*",
178 "C:\\Windows\\TAPI\\*",
179 "C:\\Windows\\INF\\*",
180 "C:\\Windows\\System32\\Speech\\*",
181 "C:\\windows\\tracing\\*",
182 "c:\\windows\\IME\\*",
183 "c:\\Windows\\Performance\\*",
184 "c:\\windows\\intel\\*",
185 "c:\\windows\\ms\\*",
186 "C:\\Windows\\dot3svc\\*",
187 "C:\\Windows\\panther\\*",
188 "C:\\Windows\\RemotePackages\\*",
189 "C:\\Windows\\OCR\\*",
190 "C:\\Windows\\appcompat\\*",
191 "C:\\Windows\\apppatch\\*",
192 "C:\\Windows\\addins\\*",
193 "C:\\Windows\\Setup\\*",
194 "C:\\Windows\\Help\\*",
195 "C:\\Windows\\SKB\\*",
196 "C:\\Windows\\Vss\\*",
197 "C:\\Windows\\servicing\\*",
198 "C:\\Windows\\CbsTemp\\*",
199 "C:\\Windows\\Logs\\*",
200 "C:\\Windows\\WaaS\\*",
201 "C:\\Windows\\twain_32\\*",
202 "C:\\Windows\\ShellExperiences\\*",
203 "C:\\Windows\\ShellComponents\\*",
204 "C:\\Windows\\PLA\\*",
205 "C:\\Windows\\Migration\\*",
206 "C:\\Windows\\debug\\*",
207 "C:\\Windows\\Cursors\\*",
208 "C:\\Windows\\Containers\\*",
209 "C:\\Windows\\Boot\\*",
210 "C:\\Windows\\bcastdvr\\*",
211 "C:\\Windows\\TextInput\\*",
212 "C:\\Windows\\security\\*",
213 "C:\\Windows\\schemas\\*",
214 "C:\\Windows\\SchCache\\*",
215 "C:\\Windows\\Resources\\*",
216 "C:\\Windows\\rescache\\*",
217 "C:\\Windows\\Provisioning\\*",
218 "C:\\Windows\\PrintDialog\\*",
219 "C:\\Windows\\PolicyDefinitions\\*",
220 "C:\\Windows\\media\\*",
221 "C:\\Windows\\Globalization\\*",
222 "C:\\Windows\\L2Schemas\\*",
223 "C:\\Windows\\LiveKernelReports\\*",
224 "C:\\Windows\\ModemLogs\\*",
225 "C:\\Windows\\ImmersiveControlPanel\\*",
226 "C:\\$Recycle.Bin\\*") and
227
228 /* noisy FP patterns */
229
230 not process.parent.executable : ("C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\*\\igfxCUIService*.exe",
231 "C:\\Windows\\System32\\spacedeskService.exe",
232 "C:\\Program Files\\Dell\\SupportAssistAgent\\SRE\\SRE.exe") and
233 not (process.name : "rundll32.exe" and
234 process.args : ("uxtheme.dll,#64",
235 "PRINTUI.DLL,PrintUIEntry",
236 "?:\\Windows\\System32\\FirewallControlPanel.dll,ShowNotificationDialog",
237 "?:\\WINDOWS\\system32\\Speech\\SpeechUX\\sapi.cpl",
238 "?:\\Windows\\system32\\shell32.dll,OpenAs_RunDLL")) and
239
240 not (process.name : "cscript.exe" and process.args : "?:\\WINDOWS\\system32\\calluxxprovider.vbs") and
241
242 not (process.name : "cmd.exe" and process.args : "?:\\WINDOWS\\system32\\powercfg.exe" and process.args : "?:\\WINDOWS\\inf\\PowerPlan.log") and
243
244 not (process.name : "regsvr32.exe" and process.args : "?:\\Windows\\Help\\OEM\\scripts\\checkmui.dll") and
245
246 not (process.name : "cmd.exe" and
247 process.parent.executable : ("?:\\Windows\\System32\\oobe\\windeploy.exe",
248 "?:\\Program Files (x86)\\ossec-agent\\wazuh-agent.exe",
249 "?:\\Windows\\System32\\igfxCUIService.exe",
250 "?:\\Windows\\Temp\\IE*.tmp\\IE*-support\\ienrcore.exe"))
251'''
252
253
254[[rule.threat]]
255framework = "MITRE ATT&CK"
256
257[[rule.threat.technique]]
258id = "T1059"
259name = "Command and Scripting Interpreter"
260reference = "https://attack.mitre.org/techniques/T1059/"
261
262[[rule.threat.technique.subtechnique]]
263id = "T1059.001"
264name = "PowerShell"
265reference = "https://attack.mitre.org/techniques/T1059/001/"
266
267[[rule.threat.technique.subtechnique]]
268id = "T1059.003"
269name = "Windows Command Shell"
270reference = "https://attack.mitre.org/techniques/T1059/003/"
271
272[rule.threat.tactic]
273id = "TA0002"
274name = "Execution"
275reference = "https://attack.mitre.org/tactics/TA0002/"
276
277[[rule.threat]]
278framework = "MITRE ATT&CK"
279
280[[rule.threat.technique]]
281id = "T1036"
282name = "Masquerading"
283reference = "https://attack.mitre.org/techniques/T1036/"
284
285[[rule.threat.technique.subtechnique]]
286id = "T1036.005"
287name = "Match Legitimate Resource Name or Location"
288reference = "https://attack.mitre.org/techniques/T1036/005/"
289
290[[rule.threat.technique]]
291id = "T1218"
292name = "System Binary Proxy Execution"
293reference = "https://attack.mitre.org/techniques/T1218/"
294
295[[rule.threat.technique.subtechnique]]
296id = "T1218.003"
297name = "CMSTP"
298reference = "https://attack.mitre.org/techniques/T1218/003/"
299
300[[rule.threat.technique.subtechnique]]
301id = "T1218.004"
302name = "InstallUtil"
303reference = "https://attack.mitre.org/techniques/T1218/004/"
304
305[[rule.threat.technique.subtechnique]]
306id = "T1218.005"
307name = "Mshta"
308reference = "https://attack.mitre.org/techniques/T1218/005/"
309
310[[rule.threat.technique.subtechnique]]
311id = "T1218.009"
312name = "Regsvcs/Regasm"
313reference = "https://attack.mitre.org/techniques/T1218/009/"
314
315[[rule.threat.technique.subtechnique]]
316id = "T1218.010"
317name = "Regsvr32"
318reference = "https://attack.mitre.org/techniques/T1218/010/"
319
320[[rule.threat.technique.subtechnique]]
321id = "T1218.011"
322name = "Rundll32"
323reference = "https://attack.mitre.org/techniques/T1218/011/"
324
325[rule.threat.tactic]
326id = "TA0005"
327name = "Defense Evasion"
328reference = "https://attack.mitre.org/tactics/TA0005/"
Triage and analysis
Investigating Execution from Unusual Directory - Command Line
This rule looks for the execution of scripts from unusual directories. Attackers can use system or application paths to hide malware and make the execution less suspicious.
Note: This investigation guide uses the Osquery Markdown Plugin introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
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 other alerts associated with the user/host during the past 48 hours.
- Examine the command line to determine which commands or scripts were executed.
- Examine the host for derived artifacts that indicate suspicious activities:
- Analyze the script using a private sandboxed analysis system.
- Observe and collect information about the following activities in both the sandbox and the alert subject host:
- Attempts to contact external domains and addresses.
- Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process'
process.entity_id. - Examine the DNS cache for suspicious or anomalous entries.
- $osquery_0
- Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process'
- Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
- Examine the host services for suspicious or anomalous entries.
- $osquery_1
- $osquery_2
- $osquery_3
- Attempts to contact external domains and addresses.
- Retrieve the files' SHA-256 hash values using the PowerShell
Get-FileHashcmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
- Investigate potentially compromised accounts. Analysts can do this by searching for login events (for example, 4624) to the target host after the registry modification.
False positive analysis
- If this activity is expected and noisy in your environment, consider adding exceptions — preferably with a combination of parent process executable and command line conditions.
Related rules
- Process Execution from an Unusual Directory - ebfe1448-7fac-4d59-acea-181bd89b1f7f
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.
- 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
- Clearing Windows Console History
- Disabling Windows Defender Security Settings via PowerShell
- ImageLoad via Windows Update Auto Update Client
- Microsoft Build Engine Started by a System Process
- Suspicious .NET Code Compilation