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"
5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
6min_stack_version = "8.3.0"
7updated_date = "2024/03/28"
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.process-*", "logs-windows.*", "endgame-*", "logs-system.security*"]
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"""
97risk_score = 47
98rule_id = "cff92c41-2225-4763-b4ce-6f71e5bda5e6"
99setup = """## Setup
100
101If enabling an EQL rule on a non-elastic-agent index (such as beats) for versions <8.2,
102events will not define `event.ingested` and default fallback for EQL rules was not added until version 8.2.
103Hence for this rule to work effectively, users will need to add a custom ingest pipeline to populate
104`event.ingested` to @timestamp.
105For more details on adding a custom ingest pipeline refer - https://www.elastic.co/guide/en/fleet/current/data-streams-pipeline-tutorial.html
106"""
107severity = "medium"
108tags = [
109 "Domain: Endpoint",
110 "OS: Windows",
111 "Use Case: Threat Detection",
112 "Tactic: Execution",
113 "Tactic: Defense Evasion",
114 "Resources: Investigation Guide",
115 "Data Source: Elastic Endgame",
116 "Data Source: Elastic Defend"
117]
118timestamp_override = "event.ingested"
119type = "eql"
120
121query = '''
122process where host.os.type == "windows" and event.type == "start" and
123 process.name : ("wscript.exe",
124 "cscript.exe",
125 "rundll32.exe",
126 "regsvr32.exe",
127 "cmstp.exe",
128 "RegAsm.exe",
129 "installutil.exe",
130 "mshta.exe",
131 "RegSvcs.exe",
132 "powershell.exe",
133 "pwsh.exe",
134 "cmd.exe") and
135
136 /* add suspicious execution paths here */
137 process.args : ("C:\\PerfLogs\\*",
138 "C:\\Users\\Public\\*",
139 "C:\\Windows\\Tasks\\*",
140 "C:\\Intel\\*",
141 "C:\\AMD\\Temp\\*",
142 "C:\\Windows\\AppReadiness\\*",
143 "C:\\Windows\\ServiceState\\*",
144 "C:\\Windows\\security\\*",
145 "C:\\Windows\\IdentityCRL\\*",
146 "C:\\Windows\\Branding\\*",
147 "C:\\Windows\\csc\\*",
148 "C:\\Windows\\DigitalLocker\\*",
149 "C:\\Windows\\en-US\\*",
150 "C:\\Windows\\wlansvc\\*",
151 "C:\\Windows\\Prefetch\\*",
152 "C:\\Windows\\Fonts\\*",
153 "C:\\Windows\\diagnostics\\*",
154 "C:\\Windows\\TAPI\\*",
155 "C:\\Windows\\INF\\*",
156 "C:\\Windows\\System32\\Speech\\*",
157 "C:\\windows\\tracing\\*",
158 "c:\\windows\\IME\\*",
159 "c:\\Windows\\Performance\\*",
160 "c:\\windows\\intel\\*",
161 "c:\\windows\\ms\\*",
162 "C:\\Windows\\dot3svc\\*",
163 "C:\\Windows\\panther\\*",
164 "C:\\Windows\\RemotePackages\\*",
165 "C:\\Windows\\OCR\\*",
166 "C:\\Windows\\appcompat\\*",
167 "C:\\Windows\\apppatch\\*",
168 "C:\\Windows\\addins\\*",
169 "C:\\Windows\\Setup\\*",
170 "C:\\Windows\\Help\\*",
171 "C:\\Windows\\SKB\\*",
172 "C:\\Windows\\Vss\\*",
173 "C:\\Windows\\servicing\\*",
174 "C:\\Windows\\CbsTemp\\*",
175 "C:\\Windows\\Logs\\*",
176 "C:\\Windows\\WaaS\\*",
177 "C:\\Windows\\twain_32\\*",
178 "C:\\Windows\\ShellExperiences\\*",
179 "C:\\Windows\\ShellComponents\\*",
180 "C:\\Windows\\PLA\\*",
181 "C:\\Windows\\Migration\\*",
182 "C:\\Windows\\debug\\*",
183 "C:\\Windows\\Cursors\\*",
184 "C:\\Windows\\Containers\\*",
185 "C:\\Windows\\Boot\\*",
186 "C:\\Windows\\bcastdvr\\*",
187 "C:\\Windows\\TextInput\\*",
188 "C:\\Windows\\security\\*",
189 "C:\\Windows\\schemas\\*",
190 "C:\\Windows\\SchCache\\*",
191 "C:\\Windows\\Resources\\*",
192 "C:\\Windows\\rescache\\*",
193 "C:\\Windows\\Provisioning\\*",
194 "C:\\Windows\\PrintDialog\\*",
195 "C:\\Windows\\PolicyDefinitions\\*",
196 "C:\\Windows\\media\\*",
197 "C:\\Windows\\Globalization\\*",
198 "C:\\Windows\\L2Schemas\\*",
199 "C:\\Windows\\LiveKernelReports\\*",
200 "C:\\Windows\\ModemLogs\\*",
201 "C:\\Windows\\ImmersiveControlPanel\\*",
202 "C:\\$Recycle.Bin\\*") and
203
204 /* noisy FP patterns */
205
206 not process.parent.executable : ("C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\*\\igfxCUIService*.exe",
207 "C:\\Windows\\System32\\spacedeskService.exe",
208 "C:\\Program Files\\Dell\\SupportAssistAgent\\SRE\\SRE.exe") and
209 not (process.name : "rundll32.exe" and
210 process.args : ("uxtheme.dll,#64",
211 "PRINTUI.DLL,PrintUIEntry",
212 "?:\\Windows\\System32\\FirewallControlPanel.dll,ShowNotificationDialog",
213 "?:\\WINDOWS\\system32\\Speech\\SpeechUX\\sapi.cpl",
214 "?:\\Windows\\system32\\shell32.dll,OpenAs_RunDLL")) and
215
216 not (process.name : "cscript.exe" and process.args : "?:\\WINDOWS\\system32\\calluxxprovider.vbs") and
217
218 not (process.name : "cmd.exe" and process.args : "?:\\WINDOWS\\system32\\powercfg.exe" and process.args : "?:\\WINDOWS\\inf\\PowerPlan.log") and
219
220 not (process.name : "regsvr32.exe" and process.args : "?:\\Windows\\Help\\OEM\\scripts\\checkmui.dll") and
221
222 not (process.name : "cmd.exe" and
223 process.parent.executable : ("?:\\Windows\\System32\\oobe\\windeploy.exe",
224 "?:\\Program Files (x86)\\ossec-agent\\wazuh-agent.exe",
225 "?:\\Windows\\System32\\igfxCUIService.exe",
226 "?:\\Windows\\Temp\\IE*.tmp\\IE*-support\\ienrcore.exe"))
227'''
228
229
230[[rule.threat]]
231framework = "MITRE ATT&CK"
232[[rule.threat.technique]]
233id = "T1059"
234name = "Command and Scripting Interpreter"
235reference = "https://attack.mitre.org/techniques/T1059/"
236[[rule.threat.technique.subtechnique]]
237id = "T1059.003"
238name = "Windows Command Shell"
239reference = "https://attack.mitre.org/techniques/T1059/003/"
240
241
242
243[rule.threat.tactic]
244id = "TA0002"
245name = "Execution"
246reference = "https://attack.mitre.org/tactics/TA0002/"
247[[rule.threat]]
248framework = "MITRE ATT&CK"
249[[rule.threat.technique]]
250id = "T1036"
251name = "Masquerading"
252reference = "https://attack.mitre.org/techniques/T1036/"
253[[rule.threat.technique.subtechnique]]
254id = "T1036.005"
255name = "Match Legitimate Name or Location"
256reference = "https://attack.mitre.org/techniques/T1036/005/"
257
258
259
260[rule.threat.tactic]
261id = "TA0005"
262name = "Defense Evasion"
263reference = "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
- Conhost Spawned By Suspicious Parent Process
- Disabling Windows Defender Security Settings via PowerShell
- Microsoft Build Engine Started by an Office Application
- Microsoft Build Engine Using an Alternate Name