Process Execution from an Unusual Directory

Identifies process execution from suspicious default Windows directories. This is sometimes done 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/17"
  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 is sometimes done 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 = "Process Execution from an Unusual Directory"
 55note = """## Triage and analysis
 56
 57### Investigating Process Execution from an Unusual Directory
 58
 59This rule identifies processes that are executed from suspicious default Windows directories. Adversaries may abuse this technique by planting malware in trusted paths, making it difficult for security analysts to discern if their activities are malicious or take advantage of exceptions that may apply to these paths.
 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, examining their executable files for prevalence, location, and valid digital signatures.
 67- Investigate any abnormal behavior by the subject process, such as network connections, registry or file modifications, and any spawned child processes.
 68- Examine arguments and working directory to determine the program's source or the nature of the tasks it is performing.
 69- Investigate other alerts associated with the user/host during the past 48 hours.
 70- Inspect the host for suspicious or abnormal behavior in the alert timeframe.
 71- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
 72- Examine the host for derived artifacts that indicate suspicious activities:
 73  - Analyze the process executable using a private sandboxed analysis system.
 74  - Observe and collect information about the following activities in both the sandbox and the alert subject host:
 75    - Attempts to contact external domains and addresses.
 76      - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
 77      - Examine the DNS cache for suspicious or anomalous entries.
 78        - $osquery_0
 79    - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
 80    - Examine the host services for suspicious or anomalous entries.
 81      - $osquery_1
 82      - $osquery_2
 83      - $osquery_3
 84  - 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.
 85
 86### False positive analysis
 87
 88- If this activity is expected and noisy in your environment, consider adding exceptions — preferably with a combination of executable and signature conditions.
 89
 90### Related Rules
 91
 92- Unusual Windows Path Activity - 445a342e-03fb-42d0-8656-0367eb2dead5
 93- Execution from Unusual Directory - Command Line - cff92c41-2225-4763-b4ce-6f71e5bda5e6
 94
 95### Response and Remediation
 96
 97- Initiate the incident response process based on the outcome of the triage.
 98- Isolate the involved host to prevent further post-compromise behavior.
 99- If the triage identified malware, search the environment for additional compromised hosts.
100  - Implement temporary network rules, procedures, and segmentation to contain the malware.
101  - Stop suspicious processes.
102  - Immediately block the identified indicators of compromise (IoCs).
103  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
104- Remove and block malicious artifacts identified during triage.
105- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
106- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
107- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
108- 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).
109"""
110references = [
111"https://www.elastic.co/security-labs/invisible-miners-unveiling-ghostengine", 
112"https://www.elastic.co/security-labs/siestagraph-new-implant-uncovered-in-asean-member-foreign-ministry"
113]
114risk_score = 47
115rule_id = "ebfe1448-7fac-4d59-acea-181bd89b1f7f"
116severity = "medium"
117tags = [
118    "Domain: Endpoint",
119    "OS: Windows",
120    "Use Case: Threat Detection",
121    "Tactic: Defense Evasion",
122    "Data Source: Elastic Endgame",
123    "Data Source: Elastic Defend",
124    "Data Source: System",
125    "Data Source: Microsoft Defender for Endpoint",
126    "Data Source: Sysmon",
127    "Data Source: SentinelOne",
128]
129timestamp_override = "event.ingested"
130type = "eql"
131
132query = '''
133process where host.os.type == "windows" and event.type == "start" and
134  /* add suspicious execution paths here */
135  process.executable : (
136    "?:\\PerfLogs\\*.exe", "?:\\Users\\Public\\*.exe", "?:\\Windows\\Tasks\\*.exe",
137    "?:\\Intel\\*.exe", "?:\\AMD\\Temp\\*.exe", "?:\\Windows\\AppReadiness\\*.exe",
138    "?:\\Windows\\ServiceState\\*.exe", "?:\\Windows\\security\\*.exe", "?:\\Windows\\IdentityCRL\\*.exe",
139    "?:\\Windows\\Branding\\*.exe", "?:\\Windows\\csc\\*.exe", "?:\\Windows\\DigitalLocker\\*.exe",
140    "?:\\Windows\\en-US\\*.exe", "?:\\Windows\\wlansvc\\*.exe", "?:\\Windows\\Prefetch\\*.exe",
141    "?:\\Windows\\Fonts\\*.exe", "?:\\Windows\\diagnostics\\*.exe", "?:\\Windows\\TAPI\\*.exe",
142    "?:\\Windows\\INF\\*.exe", "?:\\Windows\\System32\\Speech\\*.exe", "?:\\windows\\tracing\\*.exe",
143    "?:\\windows\\IME\\*.exe", "?:\\Windows\\Performance\\*.exe", "?:\\windows\\intel\\*.exe",
144    "?:\\windows\\ms\\*.exe", "?:\\Windows\\dot3svc\\*.exe", "?:\\Windows\\panther\\*.exe",
145    "?:\\Windows\\RemotePackages\\*.exe", "?:\\Windows\\OCR\\*.exe", "?:\\Windows\\appcompat\\*.exe",
146    "?:\\Windows\\apppatch\\*.exe", "?:\\Windows\\addins\\*.exe", "?:\\Windows\\Setup\\*.exe",
147    "?:\\Windows\\Help\\*.exe", "?:\\Windows\\SKB\\*.exe", "?:\\Windows\\Vss\\*.exe",
148    "?:\\Windows\\Web\\*.exe", "?:\\Windows\\servicing\\*.exe", "?:\\Windows\\CbsTemp\\*.exe",
149    "?:\\Windows\\Logs\\*.exe", "?:\\Windows\\WaaS\\*.exe", "?:\\Windows\\ShellExperiences\\*.exe",
150    "?:\\Windows\\ShellComponents\\*.exe", "?:\\Windows\\PLA\\*.exe", "?:\\Windows\\Migration\\*.exe",
151    "?:\\Windows\\debug\\*.exe", "?:\\Windows\\Cursors\\*.exe", "?:\\Windows\\Containers\\*.exe",
152    "?:\\Windows\\Boot\\*.exe", "?:\\Windows\\bcastdvr\\*.exe", "?:\\Windows\\assembly\\*.exe",
153    "?:\\Windows\\TextInput\\*.exe", "?:\\Windows\\security\\*.exe", "?:\\Windows\\schemas\\*.exe",
154    "?:\\Windows\\SchCache\\*.exe", "?:\\Windows\\Resources\\*.exe", "?:\\Windows\\rescache\\*.exe",
155    "?:\\Windows\\Provisioning\\*.exe", "?:\\Windows\\PrintDialog\\*.exe", "?:\\Windows\\PolicyDefinitions\\*.exe",
156    "?:\\Windows\\media\\*.exe", "?:\\Windows\\Globalization\\*.exe", "?:\\Windows\\L2Schemas\\*.exe",
157    "?:\\Windows\\LiveKernelReports\\*.exe", "?:\\Windows\\ModemLogs\\*.exe",
158    "?:\\Windows\\ImmersiveControlPanel\\*.exe"
159  ) and
160  
161  not process.name : (
162    "SpeechUXWiz.exe", "SystemSettings.exe", "TrustedInstaller.exe",
163    "PrintDialog.exe", "MpSigStub.exe", "LMS.exe", "mpam-*.exe"
164  ) and
165  not process.executable :
166            ("?:\\Intel\\Wireless\\WUSetupLauncher.exe",
167             "?:\\Intel\\Wireless\\Setup.exe",
168             "?:\\Intel\\Move Mouse.exe",
169             "?:\\windows\\Panther\\DiagTrackRunner.exe",
170             "?:\\Windows\\servicing\\GC64\\tzupd.exe",
171             "?:\\Users\\Public\\res\\RemoteLite.exe",
172             "?:\\Users\\Public\\IBM\\ClientSolutions\\*.exe",
173             "?:\\Users\\Public\\Documents\\syspin.exe",
174             "?:\\Users\\Public\\res\\FileWatcher.exe")
175'''
176
177
178[[rule.threat]]
179framework = "MITRE ATT&CK"
180[[rule.threat.technique]]
181id = "T1036"
182name = "Masquerading"
183reference = "https://attack.mitre.org/techniques/T1036/"
184[[rule.threat.technique.subtechnique]]
185id = "T1036.005"
186name = "Match Legitimate Name or Location"
187reference = "https://attack.mitre.org/techniques/T1036/005/"
188
189
190
191[rule.threat.tactic]
192id = "TA0005"
193name = "Defense Evasion"
194reference = "https://attack.mitre.org/tactics/TA0005/"

Triage and analysis

Investigating Process Execution from an Unusual Directory

This rule identifies processes that are executed from suspicious default Windows directories. Adversaries may abuse this technique by planting malware in trusted paths, making it difficult for security analysts to discern if their activities are malicious or take advantage of exceptions that may apply to these paths.

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, examining their executable files for prevalence, location, and valid digital signatures.
  • Investigate any abnormal behavior by the subject process, such as network connections, registry or file modifications, and any spawned child processes.
  • Examine arguments and working directory to determine the program's source or the nature of the tasks it is performing.
  • Investigate other alerts associated with the user/host during the past 48 hours.
  • Inspect the host for suspicious or abnormal behavior in the alert timeframe.
  • Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
  • Examine the host for derived artifacts that indicate suspicious activities:
    • Analyze the process executable 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.

False positive analysis

  • If this activity is expected and noisy in your environment, consider adding exceptions — preferably with a combination of executable and signature conditions.
  • Unusual Windows Path Activity - 445a342e-03fb-42d0-8656-0367eb2dead5
  • Execution from Unusual Directory - Command Line - cff92c41-2225-4763-b4ce-6f71e5bda5e6

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.
  • Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
  • 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