Your friendly neighbourhood penguin: Using Linux and WSL to stay under the radar

Idan Ron (Senior Red Team Consultant · Mandiant), Max De Lacey (Security Consultant, Red Team · Mandiant)

Security BSides London 2023 · Day 1 · Track 3

Overview

This talk, presented by Mandiant red teamers Idan Ron and Max De Lacey at BSides London, delves into advanced evasion techniques for offensive operations targeting Linux hosts and leveraging the Windows Subsystem for Linux (WSL). The presentation is split into two distinct, yet complementary, parts. Idan Ron focuses on the challenges and successes of bypassing Endpoint Detection and Response (EDR) solutions on Linux systems during a purple team engagement, sharing practical lessons learned in achieving stealth and persistence.

Watch on YouTube

Visual summary for Your friendly neighbourhood penguin: Using Linux and WSL to stay under the radar by Idan Ron, Max De Lacey
Visual summary for Your friendly neighbourhood penguin: Using Linux and WSL to stay under the radar by Idan Ron, Max De Lacey

Key moments

  1. 2:37 Initial surprise: Linux EDRs are effective
  2. 11:46 Sliver payload bypasses EDR using Python loader
  3. 16:03 Memory-only BOFs and read-only execution techniques
  4. 22:50 Leveraging Windows Subsystem for Linux (WSL) for evasion
  5. 33:38 Executing Linux ELF binaries to bypass Windows EDR
  6. 39:40 Critical differences in WSL1 and WSL2 logging visibility
  7. 43:00 WSL persistence, networking, and proxy considerations

Your friendly neighbourhood penguin: Using Linux and WSL to stay under the radar

Speakers: Idan Ron (Senior Red Team Consultant, Mandiant); Max De Lacey (Security Consultant, Red Team, Mandiant)

Conference: BSides London

YouTube: https://www.youtube.com/watch?v=RQu0o6pHQ68

Overview

This talk, presented by Mandiant red teamers Idan Ron and Max De Lacey at BSides London, delves into advanced evasion techniques for offensive operations targeting Linux hosts and leveraging the Windows Subsystem for Linux (WSL). The presentation is split into two distinct, yet complementary, parts. Idan Ron focuses on the challenges and successes of bypassing Endpoint Detection and Response (EDR) solutions on Linux systems during a purple team engagement, sharing practical lessons learned in achieving stealth and persistence.

Max De Lacey then expands on the concept of operating "under the radar" by exploring the strategic abuse of WSL on Windows hosts. He highlights how this increasingly common feature can be weaponized to execute Linux binaries on Windows, bypass traditional EDR defenses, and achieve command and control (C2) with reduced visibility. The combined research provides valuable insights for both offensive security practitioners seeking to enhance their evasion capabilities and defensive teams aiming to improve their detection and prevention strategies against sophisticated threats targeting hybrid environments.

Background

▶ Watch: Initial surprise: Linux EDRs are effective (2:37)

The landscape of enterprise security increasingly features a mix of Windows and Linux operating systems, often protected by EDR solutions. While Windows EDRs are highly mature, the effectiveness of Linux EDRs has historically been perceived as less robust by red teamers, a notion challenged and explored in Idan Ron's segment. His research stemmed from a specific purple team engagement where Mandiant was tasked with compromising Linux hosts equipped with different EDR products, operating under an assumed breach scenario with VPN access to the network. The target systems, notably running an older kernel (version 3.10 from 2013), presented unique challenges as many modern techniques and protections were inapplicable. The objective was not just to gain initial access but to establish stealthy command and control (C2) without using Mandiant's proprietary internal tools, necessitating the use of publicly available alternatives like Mythic or Sliver.

Max De Lacey's segment addresses the growing prevalence of Windows Subsystem for Linux (WSL) in modern enterprise environments. Despite its increasing adoption, WSL has received comparatively little attention in public discourse regarding its potential for offensive security. While threat actors have historically leveraged virtual machines and containers, the specific advantages of WSL—such as running unmodified ELF binaries directly on Windows and its unique logging characteristics—remain underexplored. This gap in awareness, combined with the observation of some "Bashware" malware leveraging WSL in the wild, set the stage for Max's investigation into how red teamers could exploit WSL to evade detection and achieve objectives on Windows hosts.

Key Findings

▶ Watch: Memory-only BOFs and read-only execution techniques (16:03)

Idan Ron's purple team engagement yielded several critical findings regarding Linux EDR evasion:

  • Sliver C2 Evasion: Initial attempts with a standard ELF executable (50MB) of Sliver were immediately caught by both EDRs. Converting the payload to a shared library (.so) reduced its size to 17MB and bypassed one EDR. Further packing with UPX (to 9.8MB) did not bypass the remaining EDR. The ultimate success came from using GTFO bins (specifically Python) to load the shared library into memory, bypassing the final EDR and demonstrating that leveraging existing system utilities can be highly effective.
  • Memory-Only Execution (memfd): The concept of executing code directly in memory using memfd was identified as a highly stealthy technique, creating an anonymous file descriptor solely in RAM without backing it by disk. While not applicable to the older kernel in the engagement, it represents a significant modern evasion technique for Linux.
  • Linux Beacon Object Files (BOFs): Similar to their Windows counterparts, Linux BOFs (e.g., via TrustedSec's library) offer a stealthy way to execute ELF files in memory, providing a powerful add-on for evasive C2.
  • LinPEAS Customization: Modifying common privilege escalation tools like LinPEAS (e.g., removing ASCII art or irrelevant sections) significantly reduces their detection footprint.
  • Docker and EDR Visibility: Docker containers offer partial EDR evasion, with some EDRs failing to see inside them, while others can. This highlights an inconsistent but potentially exploitable blind spot.

Max De Lacey's research into WSL uncovered equally significant findings:

  • WSL 1 vs. WSL 2 Architecture: Understanding the architectural differences between WSL 1 (pico processes, syscall translation) and WSL 2 (Hyper-V virtualization, full Linux kernel) is crucial for offensive operations, particularly regarding performance and logging.
  • ELF Binary Evasion: Unmodified ELF binaries (e.g., from MSFVenom or Chisel) can bypass static detection of Windows EDR/AV products when executed within WSL, providing a novel execution path for malware.
  • Command-Line Argument Hiding (WSL 2 Interactive): Crucially, interactive sessions in WSL 2 do not log command-line arguments to Windows event logs or EDR telemetry, offering a significant stealth advantage over direct command execution.
  • Linux File System Access from Windows: Low-privileged Windows users can often read sensitive files (e.g., /etc/shadow) from the Linux file system within WSL (wsl.localhost) that would otherwise be restricted to privileged Linux users.
  • Programmatic WSL Control: The WSL API allows for programmatic control over WSL distributions, enabling attackers to register, launch, and execute commands within WSL from a Windows executable.

Technical Deep Dive

▶ Watch: Leveraging Windows Subsystem for Linux (WSL) for evasion (22:50)

Idan Ron's part of the talk commenced with the crucial choice of C2 framework for the purple team engagement. Given the constraints, Sliver was selected over Mythic due to its advanced features, popularity among APT actors, and native Garble obfuscation. Sliver supports HTTPS, MTLS, WireGuard, and various data submission methods, including long polling (keeping HTTP connections alive) versus periodic checks.

The evasion journey began with a standard Sliver ELF payload, which by default weighed 50 megabytes. This was immediately detected by both EDRs. The first modification involved generating a shared library (.so) payload, analogous to a Windows DLL. This reduced the size to 17 megabytes and successfully bypassed one of the EDRs. To further reduce the footprint and evade the remaining EDR, the shared library was packed using UPX with the highest compression (-9 flag), shrinking it to 9.8 megabytes. However, this still failed to bypass the second EDR, indicating its sophistication.

The breakthrough came from leveraging GTFO bins, a collection of legitimate system binaries that can be abused to execute malicious code, akin to Windows' Living Off The Land Binaries (LOLBAS). Specifically, Python was used to load the shared library into memory: python -c 'import ctypes; ctypes.CDLL("./payload.so")'. This technique successfully bypassed the remaining EDR, demonstrating that using legitimate processes to load malicious payloads can circumvent behavioral and signature-based detection. Idan also clarified the difference between shared libraries requiring an explicit function call (like start_W for Sliver) and those designed for immediate execution upon loading.

Beyond the immediate engagement, Idan discussed advanced stealth techniques. He introduced memfd, a Linux system call that creates an anonymous file descriptor for a memory region, allowing code execution entirely in RAM without a backing file on disk. While powerful for modern systems, it was unavailable on the target's kernel 3.10. Tools like ELF in memory and b_s (for abusing system calls) utilize memfd for highly evasive operations. The talk also highlighted Linux Beacon Object Files (BOFs), a concept ported from Windows, where raw ELF files are loaded and executed in memory, with TrustedSec having developed a library for this purpose. Other techniques included executing payloads on read-only file systems (common in Kubernetes) and customizing LinPEAS by removing its default ASCII art and unnecessary sections to reduce its signature. The use of static binaries (self-contained executables) was recommended, with a suggestion to build a CI/CD pipeline for generating modern versions of such tools rather than relying on outdated public repositories. Lastly, Docker containers were explored for evasion, with the finding that while some EDRs were blinded, others could still monitor activity within them.

Max De Lacey then shifted focus to Windows Subsystem for Linux (WSL). He explained the fundamental architectural differences: WSL 1 uses "pico processes" and relies on lxss.sys and lxcore.sys kernel mode drivers to translate Linux syscalls into Windows NT calls, allowing unmodified ELF binaries to run. WSL 2, conversely, utilizes Hyper-V virtualization to run a complete Linux kernel, offering improved performance and different logging characteristics.

Installation of WSL is straightforward, involving enabling Windows features via DISM and then installing distributions using wsl --install -d <DistributionName>. Max demonstrated that a standard MSFVenom ELF binary, without any encoding or obfuscation, could be dropped to a Windows host with an up-to-date EDR and executed via WSL without triggering static or behavioral alerts. This simple ELF, when run interactively in a WSL shell, successfully popped Notepad. A more advanced example showed using Chisel, an open-source TCP/UDP tunneling tool written in Go, compiled as an ELF binary, to establish an SSH tunnel back to a C2 server, again bypassing EDR detection on the Windows host.

A key offensive advantage identified was the ability for low-privileged Windows users to access the Linux file system within WSL via wsl.localhost/<distribution_name>. This allows reading sensitive files like /etc/shadow that would typically be protected from unprivileged Linux users. Max also detailed the WSL API, a Windows API that enables programmatic interaction with WSL. Functions like WslLaunchInteractive and WslRegisterDistribution allow for checking distribution existence, launching commands, and even registering custom distributions. He presented a basic C++ proof of concept that used WslLaunchInteractive to run whoami and then to execute the Chisel ELF binary, demonstrating how a Windows executable could orchestrate Linux malware via WSL.

Visibility and telemetry analysis revealed a critical difference: while Sysmon and EDRs can log process creation and command-line arguments for single wsl.exe commands in WSL 1, interactive WSL 2 sessions often mask command-line arguments. Although the initial wsl.exe process creation is visible, the subsequent commands executed within the interactive Linux shell are not logged by Windows event logs or some EDRs, providing a stealthy execution environment. Network considerations were also covered: WSL defaults to NAT-based networking, but mirrored mode allows direct LAN access. Auto proxy settings mean WSL will inherit Windows HTTP proxy configurations, which can be both a challenge (if proxies are monitored) and an advantage (for blending in). For persistence, WSL 2 supports modifying systemd services, while WSL 1 allows daemonizing processes, albeit with limitations.

Demo / Proof of Concept

▶ Watch: Critical differences in WSL1 and WSL2 logging visibility (39:40)

The talk featured several practical demonstrations and proof-of-concept scenarios, highlighting the effectiveness of the discussed evasion techniques:

  • Linux EDR Bypass Progression: Idan Ron systematically demonstrated the evasion process against two Linux EDRs:
  1. A default Sliver ELF payload (50MB) was caught by both EDRs.
  2. Converting it to a shared library (.so, 17MB) bypassed one EDR.
  3. Packing the shared library with UPX (9.8MB) failed to bypass the second EDR.
  4. The final bypass involved using Python to load the shared library into memory (python -c 'import ctypes; ctypes.CDLL("./payload.so")'), successfully evading the last EDR.
  • MSFVenom ELF on Windows via WSL: Max De Lacey showed a straightforward proof-of-concept where a standard, unobfuscated MSFVenom ELF binary was dropped onto a Windows host with an active, up-to-date EDR. Executing this ELF within an interactive WSL shell successfully popped Notepad, demonstrating that Windows EDRs may fail to detect malicious ELF binaries.
  • Chisel C2 via WSL: A more advanced demonstration involved compiling Chisel (a TCP/UDP tunneling tool) as an ELF binary. This Chisel ELF was then executed within WSL on the EDR-protected Windows host, successfully establishing an SSH tunnel back to a C2 server, proving C2 capabilities could be achieved with this method.
  • WSL File System Access: Max illustrated how a low-privileged Windows user could navigate to wsl.localhost/<distribution_name> in File Explorer and open sensitive Linux files, such as /etc/shadow, in Notepad. This highlighted a privilege escalation vector where Windows permissions could bypass Linux restrictions.
  • WSL API Programmatic Execution: A basic C++ executable was presented, utilizing the WSL API. This tool first checked if a WSL distribution was registered, then used WslLaunchInteractive to execute the whoami command within WSL, printing the output. The concept was extended to show how this API could programmatically launch the Chisel ELF for C2.

Defensive Implications

▶ Watch: WSL persistence, networking, and proxy considerations (43:00)

The insights from this talk provide critical defensive implications for securing both Linux and Windows environments against sophisticated attackers. For Linux hosts, defenders must move beyond the assumption that Linux EDRs are ineffective. The successful evasion using GTFO bins highlights the need for robust application control (e.g., AppArmor, SELinux) to restrict legitimate utilities from performing suspicious actions. Comprehensive log analysis is paramount, focusing on process creation, library loading, and network connections, even if the payload itself is not detected. While detecting EDRs on Linux is challenging due to a lack of public information on service names, actively mapping EDR processes and services in one's own environment can aid in understanding their visibility. Adopting MITRE ATT&CK for Linux is crucial for developing appropriate detection and response strategies. Furthermore, implementing and monitoring tools like Sysmon for Linux and Procmon for Linux can significantly enhance visibility into system activity, helping to detect stealthy behaviors that bypass traditional EDRs. The client in Idan's engagement successfully developed new EDR rules and increased their detection rate through this purple team exercise, underscoring the value of such proactive testing.

For Windows environments leveraging WSL, defenders face unique challenges. The architectural differences, especially in WSL 2, where interactive sessions can hide command-line arguments from standard Windows logs and EDR telemetry, necessitate deeper inspection methods. Defenders should:

  • Monitor WSL Installation and Usage: Track the enabling of WSL features (via DISM events) and the installation of Linux distributions. Unauthorized WSL installations could indicate malicious intent.
  • Enhance Application Whitelisting: Extend AppLocker or similar controls to block or monitor the execution of ELF files and bash scripts on Windows, as these are often overlooked by traditional Windows-focused policies.
  • Focus on Network Telemetry: Since WSL 2 interactive sessions may hide command-line arguments, network telemetry becomes even more critical. Monitor for unusual outbound connections originating from WSL processes, especially those bypassing standard proxies or communicating with known malicious infrastructure.
  • Review File System Permissions: Regularly audit the permissions between the Windows and Linux file systems within WSL, ensuring that sensitive Linux files (e.g., /etc/shadow) are not accessible from low-privileged Windows accounts via wsl.localhost.
  • Understand Auto Proxy Behavior: Be aware that WSL often inherits Windows HTTP proxy settings. This means that if an attacker leverages WSL, their traffic might still flow through enterprise proxies like Zscaler, which can be an opportunity for detection if logs are thoroughly analyzed.
  • Monitor for Persistence Mechanisms: Implement detection for common Linux persistence techniques within WSL 2, such as modifications to systemd services or other daemonized processes.
  • Utilize WSL-Specific Logging: Investigate and leverage advanced logging capabilities for WSL, such as those detailed in whitepapers like Amanda Drager's, to gain deeper insights into WSL activity beyond standard Windows event logs.

Key Takeaways

  • Linux EDRs are not a silver bullet: While often perceived as weak, modern Linux EDRs can be effective. However, sophisticated attackers can bypass them using techniques like GTFO bins to load shared libraries in memory.
  • WSL is a potent red team tool: Windows Subsystem for Linux (WSL), particularly WSL 2, offers significant advantages for attackers, including executing unmodified ELF binaries to bypass Windows EDR static detection and hiding command-line arguments in interactive sessions.
  • Memory-only execution is key for stealth: Techniques like memfd (on modern Linux kernels) and Linux BOFs allow for highly evasive code execution directly in memory, leaving minimal forensic artifacts on disk.
  • Customization reduces detection: Modifying common offensive tools like LinPEAS or building custom static binaries can significantly lower their detection rates by removing recognizable signatures.
  • Cross-platform visibility gaps exist: EDRs may have blind spots in hybrid environments, such as inconsistent visibility into Docker containers or the unique logging characteristics of WSL, which defenders must actively address.
  • Proactive purple teaming is essential: The engagement highlighted the value of purple teaming in identifying detection gaps, improving EDR rules, and enhancing both red team skills and blue team defenses.

About the Speaker(s)

Idan Ron is a Senior Red Team Consultant at Mandiant, part of Google Cloud. With seven years of experience in the security industry, he is a self-described "jack of all trades" who enjoys exploring all aspects of red teaming and security. Idan served three years in the military and is passionate about inspiring individuals without a university degree to enter the cybersecurity field. He is also an active presence on Twitter.

Max De Lacey is a Security Consultant on the Red Team at Mandiant, also part of Google Cloud. He has approximately five years of experience in security, with one and a half years at Mandiant. Max's background includes both physical and technical security roles in public and private sectors. His primary job responsibilities involve red teaming and purple teaming engagements.

Reviews

Dr. Zero (Offensive Security Researcher) — SOLID

Solid red team trench work from Mandiant. They didn't drop any zero-days, but orchestrating Linux ELFs through the Windows WSL API to blind EDRs is exactly the kind of practical, operational friction that ruins a SOC analyst's weekend.

Heather Calloway (CISO) — MUST SEE

Mandiant's research exposes a critical visibility gap in enterprise endpoint deployments by weaponizing the Windows Subsystem for Linux (WSL) and native Linux binaries. The technical execution is sharp, but the strategic takeaway is what matters: your Windows EDR is likely blind to ELF binaries, and WSL is effectively a sanctioned shadow environment on your corporate fleet. This requires immediate review by your endpoint architecture and detection teams.

→ Top-rated talks at Security BSides London 2023

All talks from Security BSides London 2023