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