Abusing Windows Subsystem for Linux (WSL)

Understanding WSL Architecture

What WSL Really Is

Windows Subsystem for Linux (WSL) is Microsoft's compatibility layer that allows you to run Linux binary executables natively on Windows. Think of it as a bridge between two worlds - Windows and Linux - but this bridge creates unique attack opportunities.

WSL1 vs WSL2 Key Differences:

  • WSL1: Translation layer that converts Linux system calls to Windows NT kernel calls in real-time

  • WSL2: Full Linux kernel running in a lightweight Hyper-V virtual machine with bridged file system and network access

Important WSL2 Isolation Notes: WSL2 introduces more isolation than WSL1. While file access and network interfaces are bridged, WSL2 runs in a VM which means:

  • Direct memory access to Windows processes is not possible

  • Some networking behaviors differ from WSL1

  • The isolation is more rigid, though file system bridges still work

Why WSL Creates Security Risks

The fundamental problem is privilege inheritance and cross-platform access:

  1. User-Level Privilege Inheritance: WSL processes run with the same Windows user privileges (not SYSTEM, but the user's token)

  2. File System Bridge: WSL can read/write Windows files through /mnt/c/ and \\wsl$\ shares

  3. Cross-Platform Execution: WSL can execute Windows binaries via cmd.exe and powershell.exe

  4. Network Interface Sharing: Both systems can share network interfaces

  5. Credential Access: WSL can potentially access Windows user-level credentials and data

Critical Understanding: WSL root ≠ Windows SYSTEM. WSL inherits the launching Windows user's privileges, not elevated system privileges.

Discovery and Enumeration

Detecting WSL Installation

From Windows Command Line:

From PowerShell:

From Linux Side:

File System Reconnaissance

Windows to WSL Access:

WSL to Windows Access:

Cross-Platform File Access Exploitation

Understanding the File System Bridge

The /mnt/c/ mount point in WSL provides access to the Windows C: drive with the launching user's permissions:

  • Read access: Any file readable by the Windows user

  • Write access: Any location writable by the Windows user

  • This includes user documents, some system locations, and application data

  • Does NOT include files requiring administrator privileges unless user is admin

Data Exfiltration Techniques

From Windows to WSL:

From WSL to External Systems:

Advanced File Manipulation

Bypassing Windows File Locks:

Creating Cross-Platform Access:

Privilege Escalation via WSL

Understanding WSL Privilege Model

Key Principle: WSL inherits the exact privileges of the launching Windows user:

  • Regular user → WSL has regular user privileges

  • Administrator → WSL can access admin-level Windows resources

  • WSL "root" ≠ Windows SYSTEM (this is a common misconception)

Token Access and Manipulation

Checking Current Token Privileges:

Leveraging Inherited Privileges:

WSL Root Exploitation

Understanding WSL Root:

Exploiting Default Configurations:

Cross-Platform Process Execution

Windows to WSL Execution

Basic Command Execution:

WSL to Windows Execution

Cross-Platform Command Execution:

Advanced Execution Techniques:

Network Attack Vectors

Network Interface Behavior

WSL1 vs WSL2 Networking:

  • WSL1: Shares Windows network stack directly

  • WSL2: Uses NAT with port forwarding for external access

Network Reconnaissance:

Traffic Interception (WSL1 primarily):

Port Forwarding and Tunneling

WSL2 Port Forwarding:

Credential Access and Harvesting

Windows Credential Access from WSL

Registry Credential Mining (via Windows tools):

File System Credential Search:

Memory Analysis Limitations

Memory Analysis Considerations:

Persistence Mechanisms

WSL-Specific Persistence

WSL Startup Script Persistence:

Important Note: WSL persistence only triggers when WSL is launched. For cross-reboot persistence, combine with Windows-side triggers.

Windows Startup via WSL

Effective Cross-Platform Persistence:

Service Creation via WSL

Windows Service Creation:

Evasion Techniques

Detection Evasion

Process Hiding:

File System Evasion:

Anti-Forensics:

Modern EDR Considerations

Important Note: Modern EDRs (Defender for Endpoint, CrowdStrike, etc.) may monitor:

  • WSL process execution

  • Cross-platform file access

  • Command-line activity in both environments

  • Network connections from WSL

EDR Evasion Strategies:

Advanced Attack Scenarios

Scenario 1: Corporate Environment Lateral Movement

Network Discovery via WSL:

Scenario 2: Data Exfiltration Pipeline

Comprehensive Data Gathering:

Scenario 3: Privilege Escalation Chain

Complete Escalation Process:

Key Considerations

Technical Limitations

  • WSL2 Isolation: More network and memory isolation than WSL1

  • Process Injection: Cannot directly inject into Windows processes from WSL

  • DLL Compilation: Must use MinGW cross-compiler for Windows-compatible DLLs

  • Registry Access: Must use Windows tools (reg.exe) - no direct access from WSL

  • Privilege Boundaries: WSL inherits Windows user privileges, not system privileges

Operational Requirements

  • WSL must be installed and enabled on target system

  • User must have permissions to launch WSL

  • Cross-platform techniques require Windows binaries accessible from WSL

  • Network behavior differs between WSL1 and WSL2

Detection Considerations

  • Modern EDRs may monitor WSL activity

  • Cross-platform file access can be logged

  • Command-line activity in both environments may be monitored

  • Network connections from WSL may be scrutinized

Last updated

Was this helpful?