Suspicious Execution via Windows Subsystem for Linux
Detects Linux Bash commands from the Windows Subsystem for Linux. Adversaries may enable and use WSL for Linux to avoid detection.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/01/13"
3integration = ["endpoint", "windows", "m365_defender", "sentinel_one_cloud_funnel"]
4maturity = "production"
5updated_date = "2026/10/06"
6
7[rule]
8author = ["Elastic"]
9description = """
10Detects Linux Bash commands from the Windows Subsystem for Linux. Adversaries may enable and use WSL for Linux to
11avoid detection.
12"""
13from = "now-9m"
14index = [
15 "winlogbeat-*",
16 "logs-endpoint.events.process-*",
17 "logs-windows.sysmon_operational-*",
18 "endgame-*",
19 "logs-m365_defender.event-*",
20 "logs-sentinel_one_cloud_funnel.*",
21]
22language = "eql"
23license = "Elastic License v2"
24name = "Suspicious Execution via Windows Subsystem for Linux"
25note = """## Triage and analysis
26
27> **Disclaimer**:
28> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
29
30### Investigating Suspicious Execution via Windows Subsystem for Linux
31
32Windows Subsystem for Linux (WSL) allows users to run Linux binaries natively on Windows, providing a seamless integration of Linux tools. Adversaries may exploit WSL to execute Linux commands stealthily, bypassing traditional Windows security measures. The detection rule identifies unusual WSL activity by monitoring specific executable paths, command-line arguments, and parent-child process relationships, flagging deviations from typical usage patterns to uncover potential threats.
33
34### Possible investigation steps
35
36- Review the process command line and executable path to determine if the execution of bash.exe or any other Linux binaries is expected or authorized for the user or system in question.
37- Investigate the parent-child process relationship, especially focusing on whether wsl.exe is the parent process and if it has spawned any unexpected child processes that are not wslhost.exe.
38- Examine the command-line arguments used with wsl.exe for any suspicious or unauthorized commands, such as accessing sensitive files like /etc/shadow or /etc/passwd, or using network tools like curl.
39- Check the user's activity history and system logs to identify any patterns of behavior that might indicate misuse or compromise, particularly focusing on any deviations from typical usage patterns.
40- Correlate the alert with other security events or logs from data sources like Elastic Endgame, Microsoft Defender XDR, or Sysmon to gather additional context and determine if this is part of a broader attack or isolated incident.
41
42### False positive analysis
43
44- Frequent use of WSL for legitimate development tasks may trigger alerts. Users can create exceptions for specific user accounts or directories commonly used for development to reduce noise.
45- Automated scripts or tools that utilize WSL for system maintenance or monitoring might be flagged. Identify these scripts and whitelist their specific command-line patterns or parent processes.
46- Docker-related processes may cause false positives due to their interaction with WSL. Exclude Docker executable paths from the detection rule to prevent unnecessary alerts.
47- Visual Studio Code extensions that interact with WSL can generate alerts. Exclude known non-threatening extensions by specifying their command-line arguments in the exception list.
48- Regular system updates or administrative tasks that involve WSL might be misidentified. Document these activities and adjust the detection rule to recognize them as benign.
49
50### Response and remediation
51
52- Isolate the affected system from the network to prevent further unauthorized access or data exfiltration.
53- Terminate any suspicious processes identified by the detection rule, such as those involving bash.exe or wsl.exe with unusual command-line arguments.
54- Conduct a thorough review of the affected system's WSL configuration and installed Linux distributions to identify any unauthorized changes or installations.
55- Remove any unauthorized or suspicious Linux binaries or scripts found within the WSL environment.
56- Reset credentials for any accounts that may have been compromised, especially if sensitive files like /etc/shadow or /etc/passwd were accessed.
57- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if additional systems are affected.
58- Implement enhanced monitoring and logging for WSL activities across the network to detect similar threats in the future, ensuring that alerts are promptly reviewed and acted upon."""
59references = [
60 "https://lolbas-project.github.io/lolbas/OtherMSBinaries/Wsl/",
61 "https://blog.qualys.com/vulnerabilities-threat-research/2022/03/22/implications-of-windows-subsystem-for-linux-for-adversaries-defenders-part-1",
62]
63risk_score = 21
64rule_id = "3e0eeb75-16e8-4f2f-9826-62461ca128b7"
65severity = "low"
66tags = [
67 "Domain: Endpoint",
68 "OS: Windows",
69 "Use Case: Threat Detection",
70 "Tactic: Execution",
71 "Tactic: Defense Evasion",
72 "Data Source: Elastic Endgame",
73 "Data Source: Elastic Defend",
74 "Data Source: Microsoft Defender XDR",
75 "Data Source: Sysmon",
76 "Data Source: SentinelOne",
77 "Resources: Investigation Guide",
78 "Noise: High",
79 "Performance: Normal",
80 "Profile: Aggressive",
81 "Rule Type: Event Correlation (EQL)",
82 "Platform: Windows",
83]
84timestamp_override = "event.ingested"
85type = "eql"
86
87query = '''
88process where host.os.type == "windows" and event.type : "start" and
89 (
90 (
91 (process.executable : "?:\\Windows\\System32\\bash.exe" or ?process.pe.original_file_name == "Bash.exe") and
92 not process.command_line : ("bash", "bash.exe")
93 ) or
94 process.executable : "?:\\Users\\*\\AppData\\Local\\Packages\\*\\rootfs\\usr\\bin\\bash" or
95 (
96 process.parent.name : "wsl.exe" and process.parent.command_line : "bash*" and not process.name : "wslhost.exe"
97 ) or
98 (
99 process.name : "wsl.exe" and
100 (
101 process.args : "--system" or
102 (
103 process.args : "--manage" and process.args : "--set-default-user" and process.args : "root"
104 ) or
105 (
106 (process.args : ("curl", "wget") and process.args : ("http://*", "https://*")) or
107 process.args : ("*curl*http://*", "*curl*https://*", "*wget*http://*", "*wget*https://*")
108 ) or
109 (
110 (
111 process.args like~ ("*/dev/tcp/*", "*/dev/udp/*", "*zsh/net/tcp*") and
112 process.args like ("*&>*", "*<>*", "*>&*", "*<&*")
113 ) or
114 (
115 process.args : ("nc", "netcat", "nc.traditional", "ncat", "*/nc", "*/netcat", "*/nc.traditional", "*/ncat") and
116 process.args : ("sh", "/bin/sh", "bash", "/bin/bash") and
117 process.args : ("-e", "--exec", "-c", "--sh-exec")
118 ) or
119 (
120 process.args like~ "*socat*" and
121 process.args like~ ("*exec:*", "*system:*", "*shell:*") and
122 process.args like~ ("*tcp*", "*udp*", "*openssl*")
123 )
124 ) or
125 (
126 process.args : ("-e", "--exec") and
127 process.args : (
128 "/mnt/c/*.exe", "/mnt/c/*.ps1", "/mnt/c/*.bat", "/mnt/c/*.cmd", "/mnt/c/*.vbs", "/mnt/c/*.js",
129 "/mnt/c/*.hta"
130 ) and
131 not process.args : "*wslpath*"
132 ) or
133 process.args : (
134 "*/etc/passwd*", "*/etc/shadow*", "*/etc/sudoers*", "*/etc/sudoers.d/*", "*/root/.ssh/*", "*/home/*/.ssh/*",
135 "*/root/.aws/credentials*", "*/home/*/.aws/credentials*", "*/root/.kube/config*", "*/home/*/.kube/config*",
136 "*/mnt/c/Windows/System32/config/SAM*",
137 "*/mnt/c/Windows/System32/config/SECURITY*",
138 "*/mnt/c/Windows/System32/config/SYSTEM", "*/mnt/c/Windows/System32/config/SYSTEM.*",
139 "*/mnt/c/Windows/NTDS/ntds.dit*",
140 "*/mnt/c/Users/*/AppData/Roaming/Microsoft/Credentials/*",
141 "*/mnt/c/Users/*/AppData/Local/Microsoft/Credentials/*",
142 "*/mnt/c/Users/*/AppData/Roaming/Microsoft/Protect/*",
143 "*/mnt/c/Users/*/.ssh/*",
144 "*/mnt/c/Users/*/.aws/credentials",
145 "*/mnt/c/Users/*/.azure/*",
146 "*/mnt/c/Users/*/.config/gcloud/*",
147 "*/mnt/c/Users/*/AppData/Local/Google/Chrome/User Data/*/Login Data*",
148 "*/mnt/c/Users/*/AppData/Local/Microsoft/Edge/User Data/*/Login Data*"
149 )
150 )
151 )
152 ) and
153 not process.parent.executable : ("?:\\Program Files\\Docker\\*.exe", "?:\\Program Files (x86)\\Docker\\*.exe")
154'''
155
156setup = """## Setup
157
158This 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.
159
160Setup instructions: https://ela.st/install-elastic-defend
161
162### Additional data sources
163
164This rule also supports the following third-party data sources. For setup instructions, refer to the links below:
165
166- [Microsoft Defender XDR](https://ela.st/m365-defender)
167- [SentinelOne Cloud Funnel](https://ela.st/sentinel-one-cloud-funnel)
168- [Sysmon Event ID 1 - Process Creation](https://ela.st/sysmon-event-1-setup)
169"""
170
171
172[[rule.threat]]
173framework = "MITRE ATT&CK"
174
175[[rule.threat.technique]]
176id = "T1202"
177name = "Indirect Command Execution"
178reference = "https://attack.mitre.org/techniques/T1202/"
179
180[rule.threat.tactic]
181id = "TA0005"
182name = "Defense Evasion"
183reference = "https://attack.mitre.org/tactics/TA0005/"
184
185[[rule.threat]]
186framework = "MITRE ATT&CK"
187
188[[rule.threat.technique]]
189id = "T1059"
190name = "Command and Scripting Interpreter"
191reference = "https://attack.mitre.org/techniques/T1059/"
192
193[[rule.threat.technique.subtechnique]]
194id = "T1059.004"
195name = "Unix Shell"
196reference = "https://attack.mitre.org/techniques/T1059/004/"
197
198[rule.threat.tactic]
199id = "TA0002"
200name = "Execution"
201reference = "https://attack.mitre.org/tactics/TA0002/"
202
203[[rule.threat]]
204framework = "MITRE ATT&CK"
205
206[[rule.threat.technique]]
207id = "T1003"
208name = "OS Credential Dumping"
209reference = "https://attack.mitre.org/techniques/T1003/"
210
211[[rule.threat.technique.subtechnique]]
212id = "T1003.008"
213name = "/etc/passwd and /etc/shadow"
214reference = "https://attack.mitre.org/techniques/T1003/008/"
215
216[rule.threat.tactic]
217id = "TA0006"
218name = "Credential Access"
219reference = "https://attack.mitre.org/tactics/TA0006/"
Triage and analysis
Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
Investigating Suspicious Execution via Windows Subsystem for Linux
Windows Subsystem for Linux (WSL) allows users to run Linux binaries natively on Windows, providing a seamless integration of Linux tools. Adversaries may exploit WSL to execute Linux commands stealthily, bypassing traditional Windows security measures. The detection rule identifies unusual WSL activity by monitoring specific executable paths, command-line arguments, and parent-child process relationships, flagging deviations from typical usage patterns to uncover potential threats.
Possible investigation steps
- Review the process command line and executable path to determine if the execution of bash.exe or any other Linux binaries is expected or authorized for the user or system in question.
- Investigate the parent-child process relationship, especially focusing on whether wsl.exe is the parent process and if it has spawned any unexpected child processes that are not wslhost.exe.
- Examine the command-line arguments used with wsl.exe for any suspicious or unauthorized commands, such as accessing sensitive files like /etc/shadow or /etc/passwd, or using network tools like curl.
- Check the user's activity history and system logs to identify any patterns of behavior that might indicate misuse or compromise, particularly focusing on any deviations from typical usage patterns.
- Correlate the alert with other security events or logs from data sources like Elastic Endgame, Microsoft Defender XDR, or Sysmon to gather additional context and determine if this is part of a broader attack or isolated incident.
False positive analysis
- Frequent use of WSL for legitimate development tasks may trigger alerts. Users can create exceptions for specific user accounts or directories commonly used for development to reduce noise.
- Automated scripts or tools that utilize WSL for system maintenance or monitoring might be flagged. Identify these scripts and whitelist their specific command-line patterns or parent processes.
- Docker-related processes may cause false positives due to their interaction with WSL. Exclude Docker executable paths from the detection rule to prevent unnecessary alerts.
- Visual Studio Code extensions that interact with WSL can generate alerts. Exclude known non-threatening extensions by specifying their command-line arguments in the exception list.
- Regular system updates or administrative tasks that involve WSL might be misidentified. Document these activities and adjust the detection rule to recognize them as benign.
Response and remediation
- Isolate the affected system from the network to prevent further unauthorized access or data exfiltration.
- Terminate any suspicious processes identified by the detection rule, such as those involving bash.exe or wsl.exe with unusual command-line arguments.
- Conduct a thorough review of the affected system's WSL configuration and installed Linux distributions to identify any unauthorized changes or installations.
- Remove any unauthorized or suspicious Linux binaries or scripts found within the WSL environment.
- Reset credentials for any accounts that may have been compromised, especially if sensitive files like /etc/shadow or /etc/passwd were accessed.
- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if additional systems are affected.
- Implement enhanced monitoring and logging for WSL activities across the network to detect similar threats in the future, ensuring that alerts are promptly reviewed and acted upon.
References
Related rules
- Disabling Windows Defender Security Settings via PowerShell
- Potential DLL Side-Loading via Trusted Microsoft Programs
- Clearing Windows Event Logs
- Code Signing Policy Modification Through Registry
- Disabling Lsa Protection via Registry Modification