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"]
4maturity = "production"
5updated_date = "2024/08/07"
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 "winlogbeat-*",
42 "logs-endpoint.events.process-*",
43 "logs-windows.*",
44 "endgame-*",
45 "logs-system.security*",
46]
47language = "eql"
48license = "Elastic License v2"
49name = "Execution from Unusual Directory - Command Line"
50note = """## Triage and analysis
51
52### Investigating Execution from Unusual Directory - Command Line
53
54This 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.
55
56> **Note**:
57> 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.
58
59#### Possible investigation steps
60
61- 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.
62- Investigate other alerts associated with the user/host during the past 48 hours.
63- Examine the command line to determine which commands or scripts were executed.
64- Examine the host for derived artifacts that indicate suspicious activities:
65 - Analyze the script using a private sandboxed analysis system.
66 - Observe and collect information about the following activities in both the sandbox and the alert subject host:
67 - Attempts to contact external domains and addresses.
68 - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
69 - Examine the DNS cache for suspicious or anomalous entries.
70 - $osquery_0
71 - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
72 - Examine the host services for suspicious or anomalous entries.
73 - $osquery_1
74 - $osquery_2
75 - $osquery_3
76 - 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.
77- Investigate potentially compromised accounts. Analysts can do this by searching for login events (for example, 4624) to the target host after the registry modification.
78
79### False positive analysis
80
81- 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.
82
83### Related rules
84
85- Process Execution from an Unusual Directory - ebfe1448-7fac-4d59-acea-181bd89b1f7f
86
87### Response and remediation
88
89- Initiate the incident response process based on the outcome of the triage.
90- Isolate the involved host to prevent further post-compromise behavior.
91- If the triage identified malware, search the environment for additional compromised hosts.
92 - Implement temporary network rules, procedures, and segmentation to contain the malware.
93 - Stop suspicious processes.
94 - Immediately block the identified indicators of compromise (IoCs).
95 - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
96- Remove and block malicious artifacts identified during triage.
97- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
98- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
99- 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).
100"""
101risk_score = 47
102rule_id = "cff92c41-2225-4763-b4ce-6f71e5bda5e6"
103setup = """## Setup
104
105If enabling an EQL rule on a non-elastic-agent index (such as beats) for versions <8.2,
106events will not define `event.ingested` and default fallback for EQL rules was not added until version 8.2.
107Hence for this rule to work effectively, users will need to add a custom ingest pipeline to populate
108`event.ingested` to @timestamp.
109For more details on adding a custom ingest pipeline refer - https://www.elastic.co/guide/en/fleet/current/data-streams-pipeline-tutorial.html
110"""
111severity = "medium"
112tags = [
113 "Domain: Endpoint",
114 "OS: Windows",
115 "Use Case: Threat Detection",
116 "Tactic: Execution",
117 "Tactic: Defense Evasion",
118 "Resources: Investigation Guide",
119 "Data Source: Elastic Endgame",
120 "Data Source: Elastic Defend",
121 "Data Source: System",
122]
123timestamp_override = "event.ingested"
124type = "eql"
125
126query = '''
127process where host.os.type == "windows" and event.type == "start" and
128 process.name : ("wscript.exe",
129 "cscript.exe",
130 "rundll32.exe",
131 "regsvr32.exe",
132 "cmstp.exe",
133 "RegAsm.exe",
134 "installutil.exe",
135 "mshta.exe",
136 "RegSvcs.exe",
137 "powershell.exe",
138 "pwsh.exe",
139 "cmd.exe") and
140
141 /* add suspicious execution paths here */
142 process.args : ("C:\\PerfLogs\\*",
143 "C:\\Users\\Public\\*",
144 "C:\\Windows\\Tasks\\*",
145 "C:\\Intel\\*",
146 "C:\\AMD\\Temp\\*",
147 "C:\\Windows\\AppReadiness\\*",
148 "C:\\Windows\\ServiceState\\*",
149 "C:\\Windows\\security\\*",
150 "C:\\Windows\\IdentityCRL\\*",
151 "C:\\Windows\\Branding\\*",
152 "C:\\Windows\\csc\\*",
153 "C:\\Windows\\DigitalLocker\\*",
154 "C:\\Windows\\en-US\\*",
155 "C:\\Windows\\wlansvc\\*",
156 "C:\\Windows\\Prefetch\\*",
157 "C:\\Windows\\Fonts\\*",
158 "C:\\Windows\\diagnostics\\*",
159 "C:\\Windows\\TAPI\\*",
160 "C:\\Windows\\INF\\*",
161 "C:\\Windows\\System32\\Speech\\*",
162 "C:\\windows\\tracing\\*",
163 "c:\\windows\\IME\\*",
164 "c:\\Windows\\Performance\\*",
165 "c:\\windows\\intel\\*",
166 "c:\\windows\\ms\\*",
167 "C:\\Windows\\dot3svc\\*",
168 "C:\\Windows\\panther\\*",
169 "C:\\Windows\\RemotePackages\\*",
170 "C:\\Windows\\OCR\\*",
171 "C:\\Windows\\appcompat\\*",
172 "C:\\Windows\\apppatch\\*",
173 "C:\\Windows\\addins\\*",
174 "C:\\Windows\\Setup\\*",
175 "C:\\Windows\\Help\\*",
176 "C:\\Windows\\SKB\\*",
177 "C:\\Windows\\Vss\\*",
178 "C:\\Windows\\servicing\\*",
179 "C:\\Windows\\CbsTemp\\*",
180 "C:\\Windows\\Logs\\*",
181 "C:\\Windows\\WaaS\\*",
182 "C:\\Windows\\twain_32\\*",
183 "C:\\Windows\\ShellExperiences\\*",
184 "C:\\Windows\\ShellComponents\\*",
185 "C:\\Windows\\PLA\\*",
186 "C:\\Windows\\Migration\\*",
187 "C:\\Windows\\debug\\*",
188 "C:\\Windows\\Cursors\\*",
189 "C:\\Windows\\Containers\\*",
190 "C:\\Windows\\Boot\\*",
191 "C:\\Windows\\bcastdvr\\*",
192 "C:\\Windows\\TextInput\\*",
193 "C:\\Windows\\security\\*",
194 "C:\\Windows\\schemas\\*",
195 "C:\\Windows\\SchCache\\*",
196 "C:\\Windows\\Resources\\*",
197 "C:\\Windows\\rescache\\*",
198 "C:\\Windows\\Provisioning\\*",
199 "C:\\Windows\\PrintDialog\\*",
200 "C:\\Windows\\PolicyDefinitions\\*",
201 "C:\\Windows\\media\\*",
202 "C:\\Windows\\Globalization\\*",
203 "C:\\Windows\\L2Schemas\\*",
204 "C:\\Windows\\LiveKernelReports\\*",
205 "C:\\Windows\\ModemLogs\\*",
206 "C:\\Windows\\ImmersiveControlPanel\\*",
207 "C:\\$Recycle.Bin\\*") and
208
209 /* noisy FP patterns */
210
211 not process.parent.executable : ("C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\*\\igfxCUIService*.exe",
212 "C:\\Windows\\System32\\spacedeskService.exe",
213 "C:\\Program Files\\Dell\\SupportAssistAgent\\SRE\\SRE.exe") and
214 not (process.name : "rundll32.exe" and
215 process.args : ("uxtheme.dll,#64",
216 "PRINTUI.DLL,PrintUIEntry",
217 "?:\\Windows\\System32\\FirewallControlPanel.dll,ShowNotificationDialog",
218 "?:\\WINDOWS\\system32\\Speech\\SpeechUX\\sapi.cpl",
219 "?:\\Windows\\system32\\shell32.dll,OpenAs_RunDLL")) and
220
221 not (process.name : "cscript.exe" and process.args : "?:\\WINDOWS\\system32\\calluxxprovider.vbs") and
222
223 not (process.name : "cmd.exe" and process.args : "?:\\WINDOWS\\system32\\powercfg.exe" and process.args : "?:\\WINDOWS\\inf\\PowerPlan.log") and
224
225 not (process.name : "regsvr32.exe" and process.args : "?:\\Windows\\Help\\OEM\\scripts\\checkmui.dll") and
226
227 not (process.name : "cmd.exe" and
228 process.parent.executable : ("?:\\Windows\\System32\\oobe\\windeploy.exe",
229 "?:\\Program Files (x86)\\ossec-agent\\wazuh-agent.exe",
230 "?:\\Windows\\System32\\igfxCUIService.exe",
231 "?:\\Windows\\Temp\\IE*.tmp\\IE*-support\\ienrcore.exe"))
232'''
233
234
235[[rule.threat]]
236framework = "MITRE ATT&CK"
237[[rule.threat.technique]]
238id = "T1059"
239name = "Command and Scripting Interpreter"
240reference = "https://attack.mitre.org/techniques/T1059/"
241[[rule.threat.technique.subtechnique]]
242id = "T1059.003"
243name = "Windows Command Shell"
244reference = "https://attack.mitre.org/techniques/T1059/003/"
245
246
247
248[rule.threat.tactic]
249id = "TA0002"
250name = "Execution"
251reference = "https://attack.mitre.org/tactics/TA0002/"
252[[rule.threat]]
253framework = "MITRE ATT&CK"
254[[rule.threat.technique]]
255id = "T1036"
256name = "Masquerading"
257reference = "https://attack.mitre.org/techniques/T1036/"
258[[rule.threat.technique.subtechnique]]
259id = "T1036.005"
260name = "Match Legitimate Name or Location"
261reference = "https://attack.mitre.org/techniques/T1036/005/"
262
263
264
265[rule.threat.tactic]
266id = "TA0005"
267name = "Defense Evasion"
268reference = "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).
Related rules
- Clearing Windows Console History
- Disabling Windows Defender Security Settings via PowerShell
- Microsoft Build Engine Started by an Office Application
- Service Control Spawned via Script Interpreter
- Suspicious MS Office Child Process