Windows PE Binary: Structure, Sections, and Stealth Techniques

Yua Mikanana
3 min readSep 17, 2023

--

The Windows Portable Executable (PE) format is the cornerstone of Windows executables, whether they be applications or system binaries. In this article, we’ll dive deep into the architecture of the PE format, its various sections, and explore how certain manipulations, such as embedding custom resources in the .rsrc section, can be leveraged in the world of cybersecurity, potentially for evasive techniques.

Looking for a practical demonstration? In this video posted on Gemini Cyber Security Youtube channel, it is shown step-by-step on how this can be achieved.

By embedding an AES encrypted MSFVenom generated reverse shell shellcode into a EXE binary’s resource section, it was possible to bypass the latest running Windows Defender on a Windows 11 machine, successfully obtaining a reverse shell connection a remote Kali machine.

https://youtu.be/36O2qDrHQnk

What is a Windows PE Binary?

Windows PE stands for Portable Executable. It’s the native file format for executables, DLLs, and others in Windows. PE is pivotal in telling the Windows loader how the code should be loaded and how it should start executing, making it crucial for anyone diving into Windows internals or cybersecurity.

Key Sections of a PE File

The PE format comes with several sections, each designed to hold specific types of information:

  1. .text: This is the section containing the executable code.
  2. .data: Contains initialized global and static data.
  3. .rdata: Contains read-only, initialized data such as constants.
  4. .bss: Has uninitialized global and static data.
  5. .idata: Stores import data, i.e., functions and data imported from DLLs.
  6. .edata: Contains exported data, functions, and data made available to other programs.
  7. .rsrc: The resource section, it holds resources like icons, menus, and other elements.
  8. .reloc: Contains relocation information. Necessary if the binary can’t be loaded at its preferred base address.

These are the most common sections, but PE files can contain other sections, depending on the compiler and linker settings.

Embedding in the .rsrc Section

The .rsrc or resource section is intriguing. Typically, it contains elements like icons, images, or strings. But its generic structure allows embedding virtually any kind of data, including other binaries or custom payloads.

By embedding data into the .rsrc section, malicious actors can potentially evade some security solutions, especially those that only scan typical sections like .text for malicious code. When a PE loader reads the binary, it treats the embedded data in the .rsrc section as resources, and unless the security solution is explicitly checking for anomalies in the resource section, this embedded data might go unnoticed.

How Does Embedding Work?

  1. Preparation: First, a malicious actor prepares their payload, which could be another binary or custom data.
  2. Embedding: Tools or custom scripts are used to inject this payload into the .rsrc section of a benign PE file.
  3. Execution: Once embedded, the main PE file would contain code to extract and execute this payload from the resource section at runtime.

Countermeasures & Detection

Advanced cybersecurity solutions are aware of such evasive techniques. Here are a few countermeasures:

  1. Anomaly Detection: Check for unusually large .rsrc sections or those containing non-standard data.
  2. Behavioral Analysis: Rather than just statically scanning the file, monitor its behavior when executed.
  3. Heuristics: Use heuristics to identify patterns typical of embedded payloads.

Conclusion

The Windows PE format, while serving as the foundation for Windows executables, can be leveraged in crafty ways by those with ill intent. While embedding custom binaries in the .rsrc section is a known technique, it's a constant cat-and-mouse game between attackers finding new evasive techniques and defenders catching up. Always ensure your security solutions are updated and employ multiple layers of defenses to catch such stealth techniques.

Check out a practical demonstration on embedding payloads into the .rsrc of a EXE binary, bypassing Windows Defender!

https://youtu.be/36O2qDrHQnk

--

--