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 = "2025/03/20"
  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"""
104references = [
105    "https://www.elastic.co/security-labs/elastic-protects-against-data-wiper-malware-targeting-ukraine-hermeticwiper",
106    "https://www.elastic.co/security-labs/hunting-for-lateral-movement-using-event-query-language",
107]
108risk_score = 47
109rule_id = "cff92c41-2225-4763-b4ce-6f71e5bda5e6"
110severity = "medium"
111tags = [
112    "Domain: Endpoint",
113    "OS: Windows",
114    "Use Case: Threat Detection",
115    "Tactic: Execution",
116    "Tactic: Defense Evasion",
117    "Resources: Investigation Guide",
118    "Data Source: Elastic Endgame",
119    "Data Source: Elastic Defend",
120    "Data Source: Windows Security Event Logs",
121    "Data Source: Microsoft Defender for Endpoint",
122    "Data Source: Sysmon",
123    "Data Source: SentinelOne",
124]
125timestamp_override = "event.ingested"
126type = "eql"
127
128query = '''
129process where host.os.type == "windows" and event.type == "start" and
130  process.name : ("wscript.exe",
131                  "cscript.exe",
132                  "rundll32.exe",
133                  "regsvr32.exe",
134                  "cmstp.exe",
135                  "RegAsm.exe",
136                  "installutil.exe",
137                  "mshta.exe",
138                  "RegSvcs.exe",
139                  "powershell.exe",
140                  "pwsh.exe",
141                  "cmd.exe") and
142
143  /* add suspicious execution paths here */
144  process.args : ("C:\\PerfLogs\\*",
145                  "C:\\Users\\Public\\*",
146                  "C:\\Windows\\Tasks\\*",
147                  "C:\\Intel\\*",
148                  "C:\\AMD\\Temp\\*",
149                  "C:\\Windows\\AppReadiness\\*",
150                  "C:\\Windows\\ServiceState\\*",
151                  "C:\\Windows\\security\\*",
152                  "C:\\Windows\\IdentityCRL\\*",
153                  "C:\\Windows\\Branding\\*",
154                  "C:\\Windows\\csc\\*",
155                  "C:\\Windows\\DigitalLocker\\*",
156                  "C:\\Windows\\en-US\\*",
157                  "C:\\Windows\\wlansvc\\*",
158                  "C:\\Windows\\Prefetch\\*",
159                  "C:\\Windows\\Fonts\\*",
160                  "C:\\Windows\\diagnostics\\*",
161                  "C:\\Windows\\TAPI\\*",
162                  "C:\\Windows\\INF\\*",
163                  "C:\\Windows\\System32\\Speech\\*",
164                  "C:\\windows\\tracing\\*",
165                  "c:\\windows\\IME\\*",
166                  "c:\\Windows\\Performance\\*",
167                  "c:\\windows\\intel\\*",
168                  "c:\\windows\\ms\\*",
169                  "C:\\Windows\\dot3svc\\*",
170                  "C:\\Windows\\panther\\*",
171                  "C:\\Windows\\RemotePackages\\*",
172                  "C:\\Windows\\OCR\\*",
173                  "C:\\Windows\\appcompat\\*",
174                  "C:\\Windows\\apppatch\\*",
175                  "C:\\Windows\\addins\\*",
176                  "C:\\Windows\\Setup\\*",
177                  "C:\\Windows\\Help\\*",
178                  "C:\\Windows\\SKB\\*",
179                  "C:\\Windows\\Vss\\*",
180                  "C:\\Windows\\servicing\\*",
181                  "C:\\Windows\\CbsTemp\\*",
182                  "C:\\Windows\\Logs\\*",
183                  "C:\\Windows\\WaaS\\*",
184                  "C:\\Windows\\twain_32\\*",
185                  "C:\\Windows\\ShellExperiences\\*",
186                  "C:\\Windows\\ShellComponents\\*",
187                  "C:\\Windows\\PLA\\*",
188                  "C:\\Windows\\Migration\\*",
189                  "C:\\Windows\\debug\\*",
190                  "C:\\Windows\\Cursors\\*",
191                  "C:\\Windows\\Containers\\*",
192                  "C:\\Windows\\Boot\\*",
193                  "C:\\Windows\\bcastdvr\\*",
194                  "C:\\Windows\\TextInput\\*",
195                  "C:\\Windows\\security\\*",
196                  "C:\\Windows\\schemas\\*",
197                  "C:\\Windows\\SchCache\\*",
198                  "C:\\Windows\\Resources\\*",
199                  "C:\\Windows\\rescache\\*",
200                  "C:\\Windows\\Provisioning\\*",
201                  "C:\\Windows\\PrintDialog\\*",
202                  "C:\\Windows\\PolicyDefinitions\\*",
203                  "C:\\Windows\\media\\*",
204                  "C:\\Windows\\Globalization\\*",
205                  "C:\\Windows\\L2Schemas\\*",
206                  "C:\\Windows\\LiveKernelReports\\*",
207                  "C:\\Windows\\ModemLogs\\*",
208                  "C:\\Windows\\ImmersiveControlPanel\\*",
209                  "C:\\$Recycle.Bin\\*") and
210
211  /* noisy FP patterns */
212
213  not process.parent.executable : ("C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\*\\igfxCUIService*.exe",
214                                   "C:\\Windows\\System32\\spacedeskService.exe",
215                                   "C:\\Program Files\\Dell\\SupportAssistAgent\\SRE\\SRE.exe") and
216  not (process.name : "rundll32.exe" and
217       process.args : ("uxtheme.dll,#64",
218                       "PRINTUI.DLL,PrintUIEntry",
219                       "?:\\Windows\\System32\\FirewallControlPanel.dll,ShowNotificationDialog",
220                       "?:\\WINDOWS\\system32\\Speech\\SpeechUX\\sapi.cpl",
221                       "?:\\Windows\\system32\\shell32.dll,OpenAs_RunDLL")) and
222
223  not (process.name : "cscript.exe" and process.args : "?:\\WINDOWS\\system32\\calluxxprovider.vbs") and
224
225  not (process.name : "cmd.exe" and process.args : "?:\\WINDOWS\\system32\\powercfg.exe" and process.args : "?:\\WINDOWS\\inf\\PowerPlan.log") and
226
227  not (process.name : "regsvr32.exe" and process.args : "?:\\Windows\\Help\\OEM\\scripts\\checkmui.dll") and
228
229  not (process.name : "cmd.exe" and
230       process.parent.executable : ("?:\\Windows\\System32\\oobe\\windeploy.exe",
231                                    "?:\\Program Files (x86)\\ossec-agent\\wazuh-agent.exe",
232                                    "?:\\Windows\\System32\\igfxCUIService.exe",
233                                    "?:\\Windows\\Temp\\IE*.tmp\\IE*-support\\ienrcore.exe"))
234'''
235
236
237[[rule.threat]]
238framework = "MITRE ATT&CK"
239[[rule.threat.technique]]
240id = "T1059"
241name = "Command and Scripting Interpreter"
242reference = "https://attack.mitre.org/techniques/T1059/"
243[[rule.threat.technique.subtechnique]]
244id = "T1059.003"
245name = "Windows Command Shell"
246reference = "https://attack.mitre.org/techniques/T1059/003/"
247
248
249
250[rule.threat.tactic]
251id = "TA0002"
252name = "Execution"
253reference = "https://attack.mitre.org/tactics/TA0002/"
254[[rule.threat]]
255framework = "MITRE ATT&CK"
256[[rule.threat.technique]]
257id = "T1036"
258name = "Masquerading"
259reference = "https://attack.mitre.org/techniques/T1036/"
260[[rule.threat.technique.subtechnique]]
261id = "T1036.005"
262name = "Match Legitimate Name or Location"
263reference = "https://attack.mitre.org/techniques/T1036/005/"
264
265
266
267[rule.threat.tactic]
268id = "TA0005"
269name = "Defense Evasion"
270reference = "https://attack.mitre.org/tactics/TA0005/"
...
toml

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.

  • 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.
  • 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
  • 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