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

to-top