Remote File Download via Script Interpreter

Identifies built-in Windows script interpreters (cscript.exe or wscript.exe) being used to download an executable file from a remote destination.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/11/29"
  3integration = ["endpoint", "windows"]
  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 built-in Windows script interpreters (cscript.exe or wscript.exe) being used to download an executable file
 36from a remote destination.
 37"""
 38from = "now-9m"
 39index = [
 40    "winlogbeat-*",
 41    "logs-endpoint.events.network-*",
 42    "logs-endpoint.events.file-*",
 43    "logs-windows.sysmon_operational-*",
 44]
 45language = "eql"
 46license = "Elastic License v2"
 47name = "Remote File Download via Script Interpreter"
 48note = """## Triage and analysis
 49
 50### Investigating Remote File Download via Script Interpreter
 51
 52The Windows Script Host (WSH) is a Windows automation technology, which is ideal for non-interactive scripting needs, such as logon scripting, administrative scripting, and machine automation.
 53
 54Attackers commonly use WSH scripts as their initial access method, acting like droppers for second stage payloads, but can also use them to download tools and utilities needed to accomplish their goals.
 55
 56This rule looks for DLLs and executables downloaded using `cscript.exe` or `wscript.exe`.
 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- Examine the host for derived artifacts that indicate suspicious activities:
 65  - Analyze both the script and the executable involved using a private sandboxed analysis system.
 66  - Observe and collect information about the following activities in both the sandbox and the alert subject host:
 67    - Attempts to contact external domains and addresses.
 68      - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
 69      - Examine the DNS cache for suspicious or anomalous entries.
 70        - $osquery_0
 71    - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
 72    - Examine the host services for suspicious or anomalous entries.
 73      - $osquery_1
 74      - $osquery_2
 75      - $osquery_3
 76  - 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.
 77- Investigate potentially compromised accounts. Analysts can do this by searching for login events (for example, 4624) to the target host after the registry modification.
 78
 79### False positive analysis
 80
 81- The usage of these script engines by regular users is unlikely. In the case of authorized benign true positives (B-TPs), exceptions can be added.
 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- 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.
 95- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 96- 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).
 97"""
 98
 99setup = """## Setup
100
101This 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.
102
103Setup instructions: https://ela.st/install-elastic-defend
104
105### Additional data sources
106
107This rule also supports the following third-party data sources. For setup instructions, refer to the links below:
108
109- [Sysmon Event ID 3 - Network Connection](https://ela.st/sysmon-event-3-setup)
110- [Sysmon Event ID 11 - File Create](https://ela.st/sysmon-event-11-setup)
111"""
112
113risk_score = 47
114rule_id = "1d276579-3380-4095-ad38-e596a01bc64f"
115severity = "medium"
116tags = [
117    "Domain: Endpoint",
118    "OS: Windows",
119    "Use Case: Threat Detection",
120    "Tactic: Command and Control",
121    "Tactic: Execution",
122    "Resources: Investigation Guide",
123    "Data Source: Elastic Defend",
124    "Data Source: Sysmon",
125    "Noise: Medium",
126    "Performance: Normal",
127    "Profile: Recommended",
128    "Threat: Download Tool Abuse",
129    "Threat: Script-Based Execution",
130    "Rule Type: Event Correlation (EQL)",
131    "Platform: Windows",
132    "Resources: Osquery",
133]
134type = "eql"
135
136query = '''
137sequence by host.id, process.entity_id
138  [network where host.os.type == "windows" and process.name : ("wscript.exe", "cscript.exe") and network.protocol != "dns" and
139   network.direction : ("outgoing", "egress") and network.type == "ipv4" and destination.ip != "127.0.0.1"
140  ]
141  [file where host.os.type == "windows" and event.type == "creation" and
142   file.extension : ("exe", "dll", "bat", "cmd", "ps1", "vbs", "vbe", "js", "jse", "wsh", "wsf", "sct", "hta", "scr", "pif", "com", "cpl")]
143'''
144
145
146[[rule.threat]]
147framework = "MITRE ATT&CK"
148
149[[rule.threat.technique]]
150id = "T1105"
151name = "Ingress Tool Transfer"
152reference = "https://attack.mitre.org/techniques/T1105/"
153
154[rule.threat.tactic]
155id = "TA0011"
156name = "Command and Control"
157reference = "https://attack.mitre.org/tactics/TA0011/"
158
159[[rule.threat]]
160framework = "MITRE ATT&CK"
161
162[[rule.threat.technique]]
163id = "T1059"
164name = "Command and Scripting Interpreter"
165reference = "https://attack.mitre.org/techniques/T1059/"
166
167[[rule.threat.technique.subtechnique]]
168id = "T1059.005"
169name = "Visual Basic"
170reference = "https://attack.mitre.org/techniques/T1059/005/"
171
172[[rule.threat.technique.subtechnique]]
173id = "T1059.007"
174name = "JavaScript"
175reference = "https://attack.mitre.org/techniques/T1059/007/"
176
177[rule.threat.tactic]
178id = "TA0002"
179name = "Execution"
180reference = "https://attack.mitre.org/tactics/TA0002/"

Triage and analysis

Investigating Remote File Download via Script Interpreter

The Windows Script Host (WSH) is a Windows automation technology, which is ideal for non-interactive scripting needs, such as logon scripting, administrative scripting, and machine automation.

Attackers commonly use WSH scripts as their initial access method, acting like droppers for second stage payloads, but can also use them to download tools and utilities needed to accomplish their goals.

This rule looks for DLLs and executables downloaded using cscript.exe or wscript.exe.

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.
  • Examine the host for derived artifacts that indicate suspicious activities:
    • Analyze both the script and the executable involved 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

  • The usage of these script engines by regular users is unlikely. In the case of authorized benign true positives (B-TPs), exceptions can be added.

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

Related rules

to-top