Abusing RWX-S binaries for post-exploitation
At0m (Senior Incident Response Analyst)
Security BSides London 2023 · Day 1 · Rookie Track
Overview
In this compelling talk at BSides London, At0m, a Senior Incident Response Analyst, unveiled a sophisticated post-exploitation technique centered on abusing Read, Write, Execute, Sharable (RWX-S) sections within Portable Executable (PE) files. The presentation, titled "Abusing RWX-S binaries for post-exploitation," delved into how attackers can manipulate the memory characteristics of Dynamic Link Libraries (DLLs) to achieve potent capabilities like forensic evasion and privilege escalation. This method leverages a lesser-known property of PE sections, transforming a seemingly innocuous memory characteristic into a powerful vector for injecting and executing malicious code within the context of other processes, often with elevated privileges, while simultaneously making detection significantly harder.

Key moments
- 0:00 Background on PE files and Dynamic Link Libraries
- 2:10 Explaining the "Sharable" (RWX-S) characteristic
- 4:00 Introducing the custom DLL modification tool
- 6:30 First demo: Calc.exe injection and return stub
- 8:20 Demonstrating forensic evasion by erasing payload
- 10:00 Privilege escalation via vulnerable admin process
Abusing RWX-S binaries for post-exploitation
Speakers: At0m, Senior Incident Response Analyst
Conference: BSides London
YouTube: https://www.youtube.com/watch?v=8CCFT7l0tjg
Overview
In this compelling talk at BSides London, At0m, a Senior Incident Response Analyst, unveiled a sophisticated post-exploitation technique centered on abusing Read, Write, Execute, Sharable (RWX-S) sections within Portable Executable (PE) files. The presentation, titled "Abusing RWX-S binaries for post-exploitation," delved into how attackers can manipulate the memory characteristics of Dynamic Link Libraries (DLLs) to achieve potent capabilities like forensic evasion and privilege escalation. This method leverages a lesser-known property of PE sections, transforming a seemingly innocuous memory characteristic into a powerful vector for injecting and executing malicious code within the context of other processes, often with elevated privileges, while simultaneously making detection significantly harder.
At0m's research highlights a critical blind spot in many traditional security defenses. By modifying the "sharable" bit within a DLL's section characteristics, an attacker can ensure that a malicious payload, once injected into a locally modified DLL, is automatically shared and executed by any target process that subsequently loads that same DLL. This talk is highly relevant for both red teamers seeking advanced evasion techniques and blue teamers striving to understand and defend against novel memory-based attacks that bypass conventional endpoint detection and response (EDR) mechanisms. The practical demonstrations underscore the severity of this vulnerability and the need for a deeper understanding of PE file structure and memory management in modern Windows environments.
Background
▶ Watch: Background on PE files and Dynamic Link Libraries (0:00)
To comprehend the intricacies of abusing RWX-S binaries, a foundational understanding of Windows PE files and process memory management is essential. A Portable Executable (PE) file is the standard executable file format for 32-bit and 64-bit Windows operating systems. These compiled files, which cannot be read as plain text, encapsulate all the necessary code and data for a program. The structure typically begins with a DOS header (for backward compatibility), followed by a PE header containing metadata, and then several distinct sections. Common sections include .text (containing executable code), .data (for initialized global and static variables), and .rdata (for read-only data).
A process in Windows is an instance of a running program, represented by an EPROCESS structure in the kernel, which encapsulates all attributes and resources related to it. Each process is assigned a Process ID (PID) and utilizes a Process Environment Block (PEB) – a user-mode data structure pointed to by EPROCESS – that holds information about the process's memory layout, loaded modules, and other critical data. The memory space of a process is compartmentalized into areas like the stack, heap, and mapped DLLs. Dynamic Link Libraries (DLLs) are crucial components that provide abstracted, reusable functions, allowing multiple processes to share code and resources, thus conserving memory and facilitating modular programming.
Central to this talk is the concept of section characteristics. When a PE file is loaded into memory, its sections are mapped with specific permissions, such as Read (R), Write (W), and Execute (X). These permissions dictate how the memory region can be accessed. Typically, code sections are RWX to allow for execution and self-modification, while data sections might be RW or R. However, At0m focuses on an additional characteristic: Sharable (S). This characteristic is defined by the top four bits of the 32-bit Characteristics property within a section header. When the 'S' bit is set, it indicates that the memory section can be shared across multiple processes. While this feature is intended for legitimate purposes, such as efficient sharing of common system DLLs like ntdll.dll, it presents a significant attack surface when maliciously manipulated. Previous research, dating back to at least 2004, has explored similar concepts, with notable work by "Bill" who utilized VirusTotal's Retrohunt functionality to identify existing DLLs susceptible to such abuse.
Key Findings
▶ Watch: Introducing the custom DLL modification tool (4:00)
At0m's primary finding is the demonstration of a practical, real-world method for abusing the Sharable (S) characteristic in PE file sections for post-exploitation. The core idea revolves around modifying a target DLL's section headers to enable the 'S' bit, specifically alongside Read, Write, and Execute permissions (RWX-S). This manipulation allows an attacker, even from an unprivileged process, to inject shellcode into a modified DLL. When a target process (e.g., a privileged application or a common system process like Notepad) subsequently loads this modified DLL, the RWX-S section is mapped into its memory space at a predictable, shared address. The attacker's process can then write to this shared memory region, effectively injecting and executing arbitrary code within the target process's context.
The research highlights several critical implications:
- Arbitrary Code Execution: By leveraging RWX-S sections, an attacker can execute shellcode within the address space of any process that loads the specially crafted DLL. This bypasses many traditional code injection prevention mechanisms that focus on direct memory allocation or process manipulation.
- Forensic Evasion: A significant capability demonstrated is the ability to "erase" the malicious payload after execution. The custom tool developed by At0m caches the original legitimate data that was overwritten by the shellcode. After the payload executes, the tool can restore the original data, making it exceedingly difficult for forensic tools (like Yara scanners) to detect the payload in memory or on disk post-compromise. This transient nature of the payload significantly raises the bar for detection.
- Privilege Escalation: The technique can be effectively used for privilege escalation. By targeting a privileged process that loads a specific DLL from a predictable path, an unprivileged attacker can modify that DLL's RWX-S section. When the privileged process loads the DLL and calls a specific function within the modified section (e.g.,
McInitialize), the attacker's shellcode executes with the elevated privileges of the target process. - Windows 10 Specific Behavior: Interestingly, on Windows 10, when injecting into processes like Notepad, the execution of the shellcode (specifically, a
calc.exepop-up) resulted in a "ghost" Notepad process spawning alongside the original. This behavior, while not fully explained in detail regarding its root cause, indicates a unique process handling mechanism on newer Windows versions when code is injected in this manner, potentially relating to the integrity of the original process. - Tooling for Exploitation: At0m developed a custom tool in C# .NET 6 to automate the process of modifying DLL sections, injecting payloads, and demonstrating the attack. This tool makes the exploitation of RWX-S binaries accessible and practical.
These findings collectively present a sophisticated and stealthy post-exploitation primitive, challenging existing defense strategies and demanding a deeper understanding of low-level Windows memory management.
Technical Deep Dive
▶ Watch: First demo: Calc.exe injection and return stub (6:30)
At0m's research hinges on a custom tool, written in C# .NET 6, designed to interact with unmanaged code and raw binary data using P/Invoke. This tool provides a user-friendly interface for manipulating PE file structures, specifically focusing on DLLs. It supports 64-bit architectures and allows for precise control over section characteristics.
The tool's workflow for exploiting RWX-S binaries involves several key steps:
- DLL Selection and Analysis: The user first selects a target DLL. The tool then parses the PE file to display its various sections and their current characteristics. For instance, a typical section might have characteristics represented by the hex value
0x6, indicating Read and Execute permissions. - Section Modification: The critical step is to modify the characteristics of a chosen section to include the 'Sharable' bit. If a section initially has
0x6(Read+Execute), adding the 'Sharable' bit (which is part of the top four bits, making it0xFwhen combined with RWX) transforms it into an RWX-S section. The tool facilitates this by allowing the user to select a section and change its properties or even add an entirely new section with the desired characteristics. A copy of the modified DLL is created in a subfolder. - DLL Loading and Memory Mapping: The modified DLL is then loaded into the attacker's malicious process. Crucially, because the 'Sharable' bit is set, any other process (the target process) that subsequently loads this same DLL will map the RWX-S section to the exact same virtual memory address. This shared mapping is the cornerstone of the attack. At0m demonstrated this by showing both the malicious process and a target Notepad process loading
ntdll.dllat the same memory address ending in0000. - Payload Selection and Targeting: The attacker then selects a shellcode payload. The tool offers fine-grained control, allowing the payload to target either the starting address of the entire RWX-S section or a specific function within that section. This latter option is particularly powerful, leveraging the Export Address Table (EAT) to precisely overwrite the entry point of a legitimate function.
- Injection and Execution: With the modified DLL loaded and the payload ready, the tool uses various injection techniques. While modular for extensibility (e.g., supporting process hollowing), the current implementation primarily uses
CreateRemoteThread. The shellcode is written into the shared RWX-S memory region. To prevent the target process from crashing due to overwritten legitimate code, At0m implemented a return code stub. This stub identifies the original entry point of the overwritten function or section. After the shellcode executes, aJMPinstruction is appended to the payload, redirecting execution back to the legitimate code, allowing the target process to continue its normal operation or gracefully exit. - Payload Erasure: For forensic evasion, the tool includes an "erase payload" feature. It maintains a cache of the original bytes that were overwritten by the shellcode. After the payload has executed, these original bytes can be restored to the RWX-S section in memory, effectively removing all traces of the malicious code.
The technical elegance lies in the exploitation of Windows' legitimate memory sharing mechanisms. By setting the 'S' bit, the attacker ensures that the memory region becomes a shared canvas. The attacker's unprivileged process can then write its malicious shellcode onto this canvas. When a privileged target process loads the same DLL, it maps this shared canvas into its own memory space. Since the section is also RWX, the shellcode is executable within the privileged process's context, without the attacker ever directly injecting into the privileged process's private memory. This indirect injection via shared memory segments makes detection challenging.
Demo / Proof of Concept
▶ Watch: Demonstrating forensic evasion by erasing payload (8:20)
At0m presented several compelling demonstrations of the RWX-S abuse, showcasing its versatility for post-exploitation.
1. Classic Calc Popper:
The initial demonstration involved injecting a simple calc.exe shellcode into a target Notepad process.
- Method: The attacker's tool modified a common DLL (e.g.,
ntdll.dll) to have an RWX-S section, loaded it, and then injected thecalc.exepayload into that shared section. Notepad was then started, loading the same DLL. - Observation: Upon execution,
calc.exesuccessfully popped up. However, a peculiar behavior was noted on Windows 10: a "ghost" Notepad process also spawned. The original Notepad process remained, but thecalc.exeappeared to be launched by a newly created, transient Notepad instance that was not immediately visible as a distinct process in typical task managers. - Significance: This showed the core capability of arbitrary code execution. The "ghost process" behavior on Windows 10 indicates a unique interaction with the operating system's process management when such memory manipulations occur, differing from older Windows versions where a crash might be more likely without the return code stub. The return code stub played a crucial role here, ensuring the target process didn't crash.
2. Forensic Evasion:
This demonstration highlighted the stealth capabilities of the technique.
- Scenario: A malicious payload, containing strings like "calc" or "CreateProcess," was injected into the Notepad process via the modified DLL with an RWX-S section.
- Detection Tool: At0m used a custom, simple Yara scanner designed to detect these specific strings or their hex equivalents within a process's memory footprint.
- Phase 1 (Payload Present): When the payload was active in Notepad's memory, the Yara scanner successfully identified the malicious strings, confirming the presence of the injected code.
- Phase 2 (Payload Erased): The "erase payload" functionality of At0m's tool was then invoked. This feature restored the original, legitimate bytes that were overwritten by the shellcode, effectively removing the malicious content from the RWX-S section in memory.
- Result: After the erasure, the Yara scanner was run again against the Notepad process's memory. This time, it failed to find any matches.
- Significance: This proved that the technique enables significant forensic evasion. By restoring the original data, the malicious footprint becomes transient, making it extremely difficult for memory-based forensic tools to detect the attack after it has completed execution. This makes it a potent threat for advanced persistent threats (APTs) aiming for low-detection operations.
3. Privilege Escalation:
This was arguably the most impactful demonstration, showcasing how RWX-S abuse can lead to elevated privileges.
- Scenario: An unprivileged attacker process aimed to escalate privileges by targeting a dummy administrative process. This dummy admin process was designed to load a specific DLL from a hardcoded path (e.g.,
C:\ProgramData\App\mal_lib.dll) and, critically, call a function namedMcInitializewithin that DLL without any further security checks. - Attack: The attacker's unprivileged tool modified this specific DLL to set the RWX-S characteristic on a section and then injected shellcode into the
McInitializefunction's entry point. The shellcode's purpose was to add a new user named "Boku" to both the "Administrators" and "Remote Desktop Users" groups. - Execution: Unlike the
calc.exedemo where the attacker's tool explicitly executed the payload, in this privilege escalation scenario, the attacker merely patched theMcInitializefunction. The unprivileged attacker's process did not directly execute the payload. Instead, the privileged dummy admin process, upon its normal execution, loaded the modified DLL and automatically called itsMcInitializefunction. - Result: The
net usercommand, executed before the attack, showed no "Boku" user. After the privileged process called the patchedMcInitializefunction, anet usercommand revealed that "Boku" was successfully added as a new user and assigned to both the Administrators and Remote Desktop Users groups. - Significance: This is a powerful privilege escalation vector. By leveraging a privileged process's legitimate DLL loading and function calling mechanisms, an unprivileged attacker can execute arbitrary code with the highest system privileges, bypassing User Account Control (UAC) and other privilege separation mechanisms. The attack is entirely passive from the perspective of the attacker's process once the DLL is modified, relying on the target process's normal operation.
These demonstrations collectively illustrate the severe implications of RWX-S abuse, from stealthy code execution to full administrative control, making it a formidable post-exploitation technique.
Defensive Implications
▶ Watch: Privilege escalation via vulnerable admin process (10:00)
The abuse of RWX-S binaries presents significant challenges for traditional security defenses, necessitating a multi-layered approach to detection and prevention. Defenders must evolve beyond signature-based and basic behavioral monitoring to address these sophisticated memory-based attacks.
- Enhanced Memory Forensics and Monitoring:
- Dynamic Analysis: Security teams should implement advanced memory scanning capabilities that can identify sections with unusual
0xF(RWX-S) characteristics, especially in commonly loaded system or application DLLs. Tools should be able to detect when such characteristics are dynamically changed at runtime. - Baseline Deviation: Establish baselines for normal DLL section characteristics. Any deviation, particularly the addition of the 'S' bit to RWX sections, should trigger high-priority alerts.
- Transient Artifacts: Recognize that payloads can be erased. Focus on detecting the act of modification and execution, rather than just the persistent presence of malicious code. This requires continuous, granular memory monitoring.
- DLL Loading and Integrity Checks:
- DLL Sideloading Prevention: While not strictly sideloading, the technique relies on a target process loading a modified DLL. Enforce strict controls over DLL search paths and ensure applications only load DLLs from trusted, immutable locations.
- Code Signing and Integrity Verification: Implement strong code signing policies. Any unsigned or tampered DLLs, especially those loaded by privileged processes, should be blocked or flagged. Monitor for attempts to disable or bypass code integrity checks.
- Supply Chain Security: Scrutinize third-party DLLs and application dependencies for any anomalous section characteristics, even before deployment.
- Behavioral Analysis and Anomaly Detection:
- Process Creation Anomalies: Monitor for unusual process spawning, such as the "ghost process" phenomenon observed with Notepad on Windows 10. Unexpected child processes or processes running with unusual parent-child relationships should be investigated.
- Privilege Escalation Indicators: Look for typical indicators of privilege escalation, such as new user accounts being added (especially to privileged groups like Administrators), unexpected service installations, or unauthorized changes to system configurations. Even if the payload is erased, these lasting effects remain.
- API Hooking and Call Monitoring: Monitor for suspicious API calls, particularly those related to memory manipulation (
VirtualAllocEx,WriteProcessMemory,CreateRemoteThread) and PE file modification. WhileCreateRemoteThreadwas used in the demo, the core technique involves writing to shared memory, which might be less directly observable without deep kernel-level monitoring.
- Principle of Least Privilege:
- Ensure all applications and services run with the absolute minimum necessary privileges. This reduces the impact of a successful RWX-S attack, as even if a DLL is compromised, the resulting shellcode will execute with limited permissions.
- Regularly audit application permissions and user accounts to identify and rectify over-privileged entities.
- Endpoint Detection and Response (EDR) Enhancements:
- EDR solutions need to evolve to detect not just the presence of malicious files or processes, but also subtle changes in memory characteristics and the flow of execution within shared memory regions.
- Leverage kernel-level visibility to monitor low-level memory operations and detect modifications to PE section headers at load time or runtime.
- Integrate threat intelligence on known RWX-S abuse patterns.
Defending against RWX-S abuse requires a proactive stance, combining robust static and dynamic analysis with vigilant behavioral monitoring and strict adherence to security best practices. The transient nature of the payload means that detection must occur during the attack's execution phase or by analyzing its lasting side effects.
Key Takeaways
- RWX-S sections enable potent post-exploitation: By manipulating the "Sharable" (S) bit in conjunction with Read, Write, and Execute (RWX) permissions on DLL sections, attackers can create shared memory regions for arbitrary code injection.
- Forensic evasion is a critical capability: The ability to "erase" the malicious payload from memory after execution by restoring original bytes makes detection extremely challenging for traditional memory forensics and Yara scans.
- Privilege escalation is a direct consequence: Targeting privileged processes that load specific DLLs allows unprivileged attackers to execute shellcode with elevated permissions, bypassing UAC and other security controls.
- The "return code stub" is crucial for stability: Implementing a jump instruction back to the legitimate code after payload execution prevents target processes from crashing, ensuring stealth and persistence.
- Windows 10 exhibits unique "ghost process" behavior: When injecting into certain processes like Notepad, a new, transient "ghost" process may spawn alongside the original, indicating specific OS-level handling of such memory manipulations.
- Detection requires advanced monitoring: Defenders must implement sophisticated memory analysis to detect unusual RWX-S characteristics, monitor for transient payload execution, and correlate behavioral anomalies (e.g., unexpected process spawns, new privileged users) to identify this attack.
About the Speaker(s)
At0m is a Senior Incident Response Analyst, specializing in blue team operations but also engaging in red teaming. His work primarily involves coding, automation, and incident response. He is associated with his local Defcon chapter and delivered this talk as his first presentation at BSides London.
Reviews
Dr. Zero (Offensive Security Researcher) — SOLID
At0m dusted off a 2004 PE section trick to weaponize the Sharable bit for cross-process injection and payload scrubbing. It's a neat, practical C# weaponization of old-school Windows memory manager behavior. Good technical baseline, even if the demonstrations rely on some highly contrived dummy applications and a slight misunderstanding of modern Windows process spawning.
Heather Calloway (CISO) — SOLID
This is deep-in-the-weeds post-exploitation research demonstrating how attackers can abuse shared memory in DLLs to bypass EDR and erase forensic footprints. While not a board-level topic, your security engineering and IR leads need to understand this mechanism. It directly challenges the assumption that our standard memory scanning and endpoint agents will reliably catch post-compromise privilege escalation.