If the preferred memory address is unavailable, the loader uses a .reloc section to fix hardcoded memory addresses inside the code. Shellcode Requirements
:
Standard executables use absolute memory addresses to find variables, strings, and functions. When the OS loads an EXE, it performs "base relocation" to fix these addresses if the file loads into a different memory space. Shellcode must be completely Position-Independent Code (PIC), meaning it must run successfully no matter where it is placed in memory. The Import Address Table (IAT)
EXEs are harder to convert than DLLs. Consider converting your payload to a first:
Using a tool like pe2shc is straightforward. Below is a conceptual workflow of how a conversion is performed via a command-line interface. Prerequisites A compiled Windows executable (e.g., target.exe ). A conversion tool (e.g., pe2shc.exe ). Step-by-Step Execution convert exe to shellcode
: Specifically designed to make a PE file runnable as shellcode by adding a specialized stub to the front. pe2shc.exe input.exe output.shc
The biggest hurdle in converting an EXE to shellcode is the concept of .
Shellcode, by definition, is . It must be able to execute from any location in memory.
The most practical method for converting an existing, compiled EXE into shellcode is using a PE-to-shellcode wrapper utility. A popular tool for this is (created by researcher Haserezrei). How it works: If the preferred memory address is unavailable, the
python clematis_gui.py
Another automated framework approach involves tools like pe2shc (PE to Shellcode). This approach modifies the executable itself so that the very beginning of the file contains a small piece of valid redirector shellcode, making the file structurally both a valid PE file and valid raw shellcode.
Once compiled, you can open the resulting binary in a disassembler (like IDA Pro, Ghidra, or x64dbg) or use objcopy to extract the .text section, which contains the raw machine code instructions.
Tools like Donut and Clematis can encrypt the generated shellcode using symmetric ciphers. The loader decrypts the payload at runtime, preventing static analysis from revealing the shellcode's intent. Below is a conceptual workflow of how a
The execution starts at the beginning of the Bootstrap Loader. Because the loader is written in pure position-independent assembly or highly optimized C, it runs perfectly regardless of its memory address. 2. Locating the Environment
Converting executable files to shellcode is a useful technique for several reasons:
Disclaimer: This article is for educational purposes and authorized penetration testing only. Utilizing these techniques on systems without permission is illegal. If you want to dive deeper into this topic, I can: Compare Donut vs. sRDI in more detail