Arbitrary Command Execution Using WSL

Detects potential abuse of Windows Subsystem for Linux (WSL) binary as a LOLBIN to execute arbitrary Linux or Windows commands

Sigma rule (View on GitHub)

 1title: Arbitrary Command Execution Using WSL
 2id: dec44ca7-61ad-493c-bfd7-8819c5faa09b
 3related:
 4    - id: 2267fe65-0681-42ad-9a6d-46553d3f3480 # Generic susp child processes rules
 5      type: similar
 6status: test
 7description: Detects potential abuse of Windows Subsystem for Linux (WSL) binary as a LOLBIN to execute arbitrary Linux or Windows commands
 8references:
 9    - https://lolbas-project.github.io/lolbas/OtherMSBinaries/Wsl/
10    - https://twitter.com/nas_bench/status/1535431474429808642
11author: oscd.community, Zach Stanford @svch0st, Nasreddine Bencherchali (Nextron Systems)
12date: 2020/10/05
13modified: 2023/04/12
14tags:
15    - attack.execution
16    - attack.defense_evasion
17    - attack.t1218
18    - attack.t1202
19logsource:
20    category: process_creation
21    product: windows
22detection:
23    selection_img:
24        - Image|endswith: '\wsl.exe'
25        - OriginalFileName: 'wsl.exe'
26    selection_cli:
27        CommandLine|contains:
28            - ' -e '
29            - ' --exec'
30            - ' --system'
31            - ' --shell-type '
32            - ' /mnt/c' # Path to mounted "C:\" partition (Indication of running Windows binaries via WSL)
33            - ' --user root'
34            - ' -u root'
35            - '--debug-shell'
36    filter_main_kill:
37        # This filter is to handle a FP that occurs when a process is spawned from WSL and then closed by the user
38        # Example would be to open VsCode through it's server extension from WSL
39            # GrandparentCommandLine: "C:\Users\XXX\AppData\Local\Programs\Microsoft VS Code\Code.exe" --ms-enable-electron-run-as-node c:\Users\XXX\.vscode\extensions\ms-vscode-remote.remote-wsl-0.72.0\dist\wslDaemon.js
40            # ParentCommandLine: C:\WINDOWS\system32\cmd.exe /d /s /c "C:\WINDOWS\System32\wsl.exe -d Ubuntu-20.04 -e kill 1366"
41            # CommandLine: C:\WINDOWS\System32\wsl.exe -d Ubuntu-20.04 -e kill 1366
42        ParentImage|endswith: '\cmd.exe'
43        CommandLine|contains|all:
44            - ' -d '
45            - ' -e kill '
46    condition: all of selection_* and not 1 of filter_main_*
47falsepositives:
48    - Automation and orchestration scripts may use this method to execute scripts etc.
49    - Legitimate use by Windows to kill processes opened via WSL (example VsCode WSL server)
50level: medium

References

Related rules

to-top