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"]
4maturity = "production"
5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
6min_stack_version = "8.3.0"
7updated_date = "2023/06/22"
8
9[transform]
10[[transform.osquery]]
11label = "Osquery - Retrieve DNS Cache"
12query = "SELECT * FROM dns_cache"
13
14[[transform.osquery]]
15label = "Osquery - Retrieve All Services"
16query = "SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services"
17
18[[transform.osquery]]
19label = "Osquery - Retrieve Services Running on User Accounts"
20query = """
21SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services WHERE
22NOT (user_account LIKE '%LocalSystem' OR user_account LIKE '%LocalService' OR user_account LIKE '%NetworkService' OR
23user_account == null)
24"""
25
26[[transform.osquery]]
27label = "Osquery - Retrieve Service Unsigned Executables with Virustotal Link"
28query = """
29SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, name, description, start_type, status, pid,
30services.path FROM services JOIN authenticode ON services.path = authenticode.path OR services.module_path =
31authenticode.path JOIN hash ON services.path = hash.path WHERE authenticode.result != 'trusted'
32"""
33
34
35[rule]
36author = ["Elastic"]
37description = """
38Identifies process execution from suspicious default Windows directories. This may be abused by adversaries to hide
39malware in trusted paths.
40"""
41from = "now-9m"
42index = ["winlogbeat-*", "logs-endpoint.events.*", "logs-windows.*", "endgame-*"]
43language = "eql"
44license = "Elastic License v2"
45name = "Execution from Unusual Directory - Command Line"
46note = """## Triage and analysis
47
48### Investigating Execution from Unusual Directory - Command Line
49
50This 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.
51
52> **Note**:
53> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/master/invest-guide-run-osquery.html) introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
54
55#### Possible investigation steps
56
57- 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.
58- Investigate other alerts associated with the user/host during the past 48 hours.
59- Examine the command line to determine which commands or scripts were executed.
60- Examine the host for derived artifacts that indicate suspicious activities:
61 - Analyze the script using a private sandboxed analysis system.
62 - Observe and collect information about the following activities in both the sandbox and the alert subject host:
63 - Attempts to contact external domains and addresses.
64 - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
65 - Examine the DNS cache for suspicious or anomalous entries.
66 - $osquery_0
67 - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
68 - Examine the host services for suspicious or anomalous entries.
69 - $osquery_1
70 - $osquery_2
71 - $osquery_3
72 - 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.
73- Investigate potentially compromised accounts. Analysts can do this by searching for login events (for example, 4624) to the target host after the registry modification.
74
75### False positive analysis
76
77- 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.
78
79### Related rules
80
81- Process Execution from an Unusual Directory - ebfe1448-7fac-4d59-acea-181bd89b1f7f
82
83### Response and remediation
84
85- Initiate the incident response process based on the outcome of the triage.
86- Isolate the involved host to prevent further post-compromise behavior.
87- If the triage identified malware, search the environment for additional compromised hosts.
88 - Implement temporary network rules, procedures, and segmentation to contain the malware.
89 - Stop suspicious processes.
90 - Immediately block the identified indicators of compromise (IoCs).
91 - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
92- Remove and block malicious artifacts identified during triage.
93- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
94- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
95- 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).
96
97## Setup
98
99If enabling an EQL rule on a non-elastic-agent index (such as beats) for versions <8.2, events will not define `event.ingested` and default fallback for EQL rules was not added until 8.2, so you will need to add a custom pipeline to populate `event.ingested` to @timestamp for this rule to work.
100"""
101risk_score = 47
102rule_id = "cff92c41-2225-4763-b4ce-6f71e5bda5e6"
103severity = "medium"
104tags = [
105 "Domain: Endpoint",
106 "OS: Windows",
107 "Use Case: Threat Detection",
108 "Tactic: Execution",
109 "Tactic: Defense Evasion",
110 "Resources: Investigation Guide",
111 "Data Source: Elastic Endgame",
112 "Data Source: Elastic Defend"
113]
114timestamp_override = "event.ingested"
115type = "eql"
116
117query = '''
118process where host.os.type == "windows" and event.type == "start" and
119 process.name : ("wscript.exe",
120 "cscript.exe",
121 "rundll32.exe",
122 "regsvr32.exe",
123 "cmstp.exe",
124 "RegAsm.exe",
125 "installutil.exe",
126 "mshta.exe",
127 "RegSvcs.exe",
128 "powershell.exe",
129 "pwsh.exe",
130 "cmd.exe") and
131
132 /* add suspicious execution paths here */
133 process.args : ("C:\\PerfLogs\\*",
134 "C:\\Users\\Public\\*",
135 "C:\\Windows\\Tasks\\*",
136 "C:\\Intel\\*",
137 "C:\\AMD\\Temp\\*",
138 "C:\\Windows\\AppReadiness\\*",
139 "C:\\Windows\\ServiceState\\*",
140 "C:\\Windows\\security\\*",
141 "C:\\Windows\\IdentityCRL\\*",
142 "C:\\Windows\\Branding\\*",
143 "C:\\Windows\\csc\\*",
144 "C:\\Windows\\DigitalLocker\\*",
145 "C:\\Windows\\en-US\\*",
146 "C:\\Windows\\wlansvc\\*",
147 "C:\\Windows\\Prefetch\\*",
148 "C:\\Windows\\Fonts\\*",
149 "C:\\Windows\\diagnostics\\*",
150 "C:\\Windows\\TAPI\\*",
151 "C:\\Windows\\INF\\*",
152 "C:\\Windows\\System32\\Speech\\*",
153 "C:\\windows\\tracing\\*",
154 "c:\\windows\\IME\\*",
155 "c:\\Windows\\Performance\\*",
156 "c:\\windows\\intel\\*",
157 "c:\\windows\\ms\\*",
158 "C:\\Windows\\dot3svc\\*",
159 "C:\\Windows\\panther\\*",
160 "C:\\Windows\\RemotePackages\\*",
161 "C:\\Windows\\OCR\\*",
162 "C:\\Windows\\appcompat\\*",
163 "C:\\Windows\\apppatch\\*",
164 "C:\\Windows\\addins\\*",
165 "C:\\Windows\\Setup\\*",
166 "C:\\Windows\\Help\\*",
167 "C:\\Windows\\SKB\\*",
168 "C:\\Windows\\Vss\\*",
169 "C:\\Windows\\servicing\\*",
170 "C:\\Windows\\CbsTemp\\*",
171 "C:\\Windows\\Logs\\*",
172 "C:\\Windows\\WaaS\\*",
173 "C:\\Windows\\twain_32\\*",
174 "C:\\Windows\\ShellExperiences\\*",
175 "C:\\Windows\\ShellComponents\\*",
176 "C:\\Windows\\PLA\\*",
177 "C:\\Windows\\Migration\\*",
178 "C:\\Windows\\debug\\*",
179 "C:\\Windows\\Cursors\\*",
180 "C:\\Windows\\Containers\\*",
181 "C:\\Windows\\Boot\\*",
182 "C:\\Windows\\bcastdvr\\*",
183 "C:\\Windows\\TextInput\\*",
184 "C:\\Windows\\security\\*",
185 "C:\\Windows\\schemas\\*",
186 "C:\\Windows\\SchCache\\*",
187 "C:\\Windows\\Resources\\*",
188 "C:\\Windows\\rescache\\*",
189 "C:\\Windows\\Provisioning\\*",
190 "C:\\Windows\\PrintDialog\\*",
191 "C:\\Windows\\PolicyDefinitions\\*",
192 "C:\\Windows\\media\\*",
193 "C:\\Windows\\Globalization\\*",
194 "C:\\Windows\\L2Schemas\\*",
195 "C:\\Windows\\LiveKernelReports\\*",
196 "C:\\Windows\\ModemLogs\\*",
197 "C:\\Windows\\ImmersiveControlPanel\\*",
198 "C:\\$Recycle.Bin\\*") and
199
200 /* noisy FP patterns */
201
202 not process.parent.executable : ("C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\*\\igfxCUIService*.exe",
203 "C:\\Windows\\System32\\spacedeskService.exe",
204 "C:\\Program Files\\Dell\\SupportAssistAgent\\SRE\\SRE.exe") and
205 not (process.name : "rundll32.exe" and
206 process.args : ("uxtheme.dll,#64",
207 "PRINTUI.DLL,PrintUIEntry",
208 "?:\\Windows\\System32\\FirewallControlPanel.dll,ShowNotificationDialog",
209 "?:\\WINDOWS\\system32\\Speech\\SpeechUX\\sapi.cpl",
210 "?:\\Windows\\system32\\shell32.dll,OpenAs_RunDLL")) and
211
212 not (process.name : "cscript.exe" and process.args : "?:\\WINDOWS\\system32\\calluxxprovider.vbs") and
213
214 not (process.name : "cmd.exe" and process.args : "?:\\WINDOWS\\system32\\powercfg.exe" and process.args : "?:\\WINDOWS\\inf\\PowerPlan.log") and
215
216 not (process.name : "regsvr32.exe" and process.args : "?:\\Windows\\Help\\OEM\\scripts\\checkmui.dll") and
217
218 not (process.name : "cmd.exe" and
219 process.parent.executable : ("?:\\Windows\\System32\\oobe\\windeploy.exe",
220 "?:\\Program Files (x86)\\ossec-agent\\wazuh-agent.exe",
221 "?:\\Windows\\System32\\igfxCUIService.exe",
222 "?:\\Windows\\Temp\\IE*.tmp\\IE*-support\\ienrcore.exe"))
223'''
224
225
226[[rule.threat]]
227framework = "MITRE ATT&CK"
228[[rule.threat.technique]]
229id = "T1059"
230name = "Command and Scripting Interpreter"
231reference = "https://attack.mitre.org/techniques/T1059/"
232[[rule.threat.technique.subtechnique]]
233id = "T1059.003"
234name = "Windows Command Shell"
235reference = "https://attack.mitre.org/techniques/T1059/003/"
236
237
238
239[rule.threat.tactic]
240id = "TA0002"
241name = "Execution"
242reference = "https://attack.mitre.org/tactics/TA0002/"
243[[rule.threat]]
244framework = "MITRE ATT&CK"
245[[rule.threat.technique]]
246id = "T1036"
247name = "Masquerading"
248reference = "https://attack.mitre.org/techniques/T1036/"
249[[rule.threat.technique.subtechnique]]
250id = "T1036.005"
251name = "Match Legitimate Name or Location"
252reference = "https://attack.mitre.org/techniques/T1036/005/"
253
254
255
256[rule.threat.tactic]
257id = "TA0005"
258name = "Defense Evasion"
259reference = "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-FileHash
cmdlet 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).
Setup
If enabling an EQL rule on a non-elastic-agent index (such as beats) for versions <8.2, events will not define event.ingested
and default fallback for EQL rules was not added until 8.2, so you will need to add a custom pipeline to populate event.ingested
to @timestamp for this rule to work.
Related rules
- Adding Hidden File Attribute via Attrib
- Clearing Windows Console History
- Clearing Windows Event Logs
- Code Signing Policy Modification Through Built-in tools
- Code Signing Policy Modification Through Registry