Windows Script Executing PowerShell

Identifies a PowerShell process launched by either cscript.exe or wscript.exe. Observing Windows scripting processes executing a PowerShell script, may be indicative of malicious activity.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/02/18"
  3integration = ["endpoint", "windows"]
  4maturity = "production"
  5updated_date = "2024/05/21"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10Identifies a PowerShell process launched by either cscript.exe or wscript.exe. Observing Windows scripting processes
 11executing a PowerShell script, may be indicative of malicious activity.
 12"""
 13from = "now-9m"
 14index = ["winlogbeat-*", "logs-endpoint.events.process-*", "logs-windows.sysmon_operational-*", "endgame-*"]
 15language = "eql"
 16license = "Elastic License v2"
 17name = "Windows Script Executing PowerShell"
 18note = """## Triage and analysis
 19
 20### Investigating Windows Script Executing PowerShell
 21
 22The Windows Script Host (WSH) is an Windows automation technology, which is ideal for non-interactive scripting needs, such as logon scripting, administrative scripting, and machine automation.
 23
 24Attackers 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.
 25
 26This rule looks for the spawn of the `powershell.exe` process with `cscript.exe` or `wscript.exe` as its parent process.
 27
 28#### Possible investigation steps
 29
 30- 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.
 31- Investigate commands executed by the spawned PowerShell process.
 32- If unsigned files are found on the process tree, retrieve them and determine if they are malicious:
 33  - Use a private sandboxed malware analysis system to perform analysis.
 34    - Observe and collect information about the following activities:
 35      - Attempts to contact external domains and addresses.
 36      - File and registry access, modification, and creation activities.
 37      - Service creation and launch activities.
 38      - Scheduled task creation.
 39  - Use the PowerShell Get-FileHash cmdlet to get the files' SHA-256 hash values.
 40    - Search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
 41- Determine how the script file was delivered (email attachment, dropped by other processes, etc.).
 42- Investigate other alerts associated with the user/host during the past 48 hours.
 43
 44### False positive analysis
 45
 46- 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.
 47
 48### Response and remediation
 49
 50- Initiate the incident response process based on the outcome of the triage.
 51- Isolate the involved host to prevent further post-compromise behavior.
 52- If the triage identified malware, search the environment for additional compromised hosts.
 53  - Implement temporary network rules, procedures, and segmentation to contain the malware.
 54  - Stop suspicious processes.
 55  - Immediately block the identified indicators of compromise (IoCs).
 56  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
 57- Remove and block malicious artifacts identified during triage.
 58- If the malicious file was delivered via phishing:
 59  - Block the email sender from sending future emails.
 60  - Block the malicious web pages.
 61  - Remove emails from the sender from mailboxes.
 62  - Consider improvements to the security awareness program.
 63- Reimage the host operating system and restore compromised files to clean versions.
 64- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 65- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 66- 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).
 67"""
 68risk_score = 21
 69rule_id = "f545ff26-3c94-4fd0-bd33-3c7f95a3a0fc"
 70setup = """## Setup
 71
 72If enabling an EQL rule on a non-elastic-agent index (such as beats) for versions <8.2,
 73events will not define `event.ingested` and default fallback for EQL rules was not added until version 8.2.
 74Hence for this rule to work effectively, users will need to add a custom ingest pipeline to populate
 75`event.ingested` to @timestamp.
 76For more details on adding a custom ingest pipeline refer - https://www.elastic.co/guide/en/fleet/current/data-streams-pipeline-tutorial.html
 77"""
 78severity = "low"
 79tags = [
 80    "Domain: Endpoint",
 81    "OS: Windows",
 82    "Use Case: Threat Detection",
 83    "Tactic: Initial Access",
 84    "Tactic: Execution",
 85    "Resources: Investigation Guide",
 86    "Data Source: Elastic Endgame",
 87    "Data Source: Elastic Defend",
 88    "Data Source: Sysmon",
 89]
 90timestamp_override = "event.ingested"
 91type = "eql"
 92
 93query = '''
 94process where host.os.type == "windows" and event.type == "start" and
 95  process.parent.name : ("cscript.exe", "wscript.exe") and process.name : "powershell.exe" and
 96  not (
 97    process.parent.name : "wscript.exe" and
 98    process.parent.args : "?:\\ProgramData\\intune-drive-mapping-generator\\IntuneDriveMapping-VBSHelper.vbs" and
 99    process.parent.args : "?:\\ProgramData\\intune-drive-mapping-generator\\DriveMapping.ps1"
100  )
101'''
102
103
104[[rule.threat]]
105framework = "MITRE ATT&CK"
106[[rule.threat.technique]]
107id = "T1566"
108name = "Phishing"
109reference = "https://attack.mitre.org/techniques/T1566/"
110[[rule.threat.technique.subtechnique]]
111id = "T1566.001"
112name = "Spearphishing Attachment"
113reference = "https://attack.mitre.org/techniques/T1566/001/"
114
115
116
117[rule.threat.tactic]
118id = "TA0001"
119name = "Initial Access"
120reference = "https://attack.mitre.org/tactics/TA0001/"
121[[rule.threat]]
122framework = "MITRE ATT&CK"
123[[rule.threat.technique]]
124id = "T1059"
125name = "Command and Scripting Interpreter"
126reference = "https://attack.mitre.org/techniques/T1059/"
127[[rule.threat.technique.subtechnique]]
128id = "T1059.001"
129name = "PowerShell"
130reference = "https://attack.mitre.org/techniques/T1059/001/"
131
132[[rule.threat.technique.subtechnique]]
133id = "T1059.005"
134name = "Visual Basic"
135reference = "https://attack.mitre.org/techniques/T1059/005/"
136
137
138
139[rule.threat.tactic]
140id = "TA0002"
141name = "Execution"
142reference = "https://attack.mitre.org/tactics/TA0002/"

Triage and analysis

Investigating Windows Script Executing PowerShell

The Windows Script Host (WSH) is an 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 the spawn of the powershell.exe process with cscript.exe or wscript.exe as its parent process.

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 commands executed by the spawned PowerShell process.
  • If unsigned files are found on the process tree, retrieve them and determine if they are malicious:
    • Use a private sandboxed malware analysis system to perform analysis.
      • Observe and collect information about the following activities:
        • Attempts to contact external domains and addresses.
        • File and registry access, modification, and creation activities.
        • Service creation and launch activities.
        • Scheduled task creation.
    • Use the PowerShell Get-FileHash cmdlet to get the files' SHA-256 hash values.
      • Search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
  • Determine how the script file was delivered (email attachment, dropped by other processes, etc.).
  • Investigate other alerts associated with the user/host during the past 48 hours.

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.
  • If the malicious file was delivered via phishing:
    • Block the email sender from sending future emails.
    • Block the malicious web pages.
    • Remove emails from the sender from mailboxes.
    • Consider improvements to the security awareness program.
  • Reimage the host operating system and restore compromised files to clean versions.
  • 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).

Related rules

to-top