Windows PE resource embedding Shellcode, loading and executing Shellcode from the DATA resource segment of EXE
- Compiler: MSVC (Visual Studio 2019)
- Platform Toolset: v142
- Target Platform: Windows x86 / x64
- Subsystem: Windows (No console)
Win32 Windows subsystem program (without console black window). Embed the shellcode binary file as a 'DATA' type resource inside the EXE, read the shellcode in its own PE resource segment at runtime, apply for memory, copy, and modify memory page permissions, and then execute the shellcode.
- PE Resource section
.rsrc: Use.rcresource script embed binary file asDATAresource. PE资源段,通过rc脚本将二进制文件打包为DATA自定义资源 - Resource related Win32 API:
FindResourceW— Locate resource by ID & resource‑typeLoadResource— Load resource into process memorySizeofResource— Get resource binary sizeLockResource— Get pointer point to resource raw data(return read‑only memory pointer)
- VirtualAlloc: Reserve & commit memory page, initial permission
PAGE_READWRITE - VirtualProtect: Modify memory page permission to
PAGE_EXECUTE_READafter memcpy shellcode - Function pointer cast, jump to memory buffer and execute raw machine‑code shellcode