Skip to content

onedays12/Convert2Shellcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

English | ไธญๆ–‡

Introduce

Two types of SRDI implemented in MASM assemblyโ€”front-style RDI and post-tyle RDIโ€”can convert EXE/DLL into position-independent shellcode.

An embedded RDI (improved variant) only supports DLL-to-shellcode conversion. This DLL must export a loader function (e.g., ReflectiveLoader or custom names like HahaLoader). While challenging for practitioners unfamiliar with RDI, its simplicity has led to wide adoption by C2 frameworks.

Current SRDI Limitations:

  1. EXE's main or wmain can have parameters.
  2. DLL's DllMain must adhere to Microsoft's official specifications.
  3. EXEs/DLLs written in C# are unsupported.
  4. x64 architecture only.

Embedded RDI Specifics:

  1. DLL-exclusive conversion.
  2. Requires an exported loader function (name flexibility exists, e.g., HahaLoader).

Project Structure

Convert2Shellcode

  • Convert2Shellcode_embed.cpp๏ผšC++ version, uses improved RDI (embedded) to convert DLL to shellcode
  • Convert2Shellcode_embed.go๏ผšGo version, uses improved RDI (embedded) to convert DLL to shellcode
  • Convert2Shellcode_front.cpp๏ผšC++ version, uses front-style RDI to convert EXE/DLL to shellcode
  • Convert2Shellcode_front.go๏ผšGo version, uses front-style RDI to convert EXE/DLL to shellcode
  • Convert2Shellcode_post.cpp๏ผšC++ version, uses post-style RDI to convert EXE/DLL to shellcode
  • Convert2Shellcode_post.go๏ผšGo version, uses post-style RDI to convert EXE/DLL to shellcode

Debug

  • DebugForRDI.asm๏ผšASM file created for debugging and developing RDI, verified for functionality
  • Sever.py๏ผšPython-written TCP server used withย DebugForRDI.asm

SRDI Asm

  • RDI_front.asm๏ผšFront-style RDI shellcode
  • RDI_post.asm๏ผšPost-style RDI shellcode

Test

  • ReflectiveDLL.cpp๏ผšDLL source code with exportedย ReflectiveLoaderย function
  • ReflectiveDLL.dll๏ผšCompiled DLL binary with exportedย ReflectiveLoaderย function
  • stager_x64_reverseTcp.asm๏ผšCobalt Strike-like stager; executeย Sever.pyย to start server, then run this ASM to fetch/execute payload
  • Test_for_dll.cpp๏ผšTest DLL source code
  • Test_for_dll.dll๏ผšTest DLL binary
  • Test_for_exe.cpp๏ผšTest EXE source code
  • Test_for_exe.exe๏ผšTest EXE binary

Usage

1.Convert2Shellcode_post.exe <DLL/EXE Path> [Output File Path]  
2.Convert2Shellcode_post.exe <DLL/EXE Path> [Output File Path]  
3.Convert2Shellcode_embed.exe <DLL Path> [Output File Path] [The Export Function Name of Loader]

Example

PS C:\Users\Xxxxxxxx\Desktop\Convert2Shellcode_v1.0> .\Convert2Shellcode_front.exe .\mimikatz.exe
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘                           Convert2Shellcode_front                                    โ•‘
โ•‘------------------------------------------------------------------------------------- โ•‘
โ•‘ Function: Use front-style RDI to convert EXE/DLL into position-independent shellcode โ•‘
โ•‘ Author๏ผšoneday                                                                       โ•‘
โ•‘ Compilation Date๏ผšJun 12 2025 21:29:52                                               โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

[+] Successfully opened .
[*] File size is 1355264
[+] Memory allocation successful, address is 0x4bc9b040
[*] 1355264 bytes read into memory
[+] Memory allocation successful, address is 0x4bdf9040
[+] Successfully generated shellcode file: s (Size: 1356147 bytes)

Use runshc64.exe with pe2shellcode for verification๏ผšhasherezade/pe_to_shellcode: Converts PE into a shellcode, or you can write your own loader.

For More Details

If you are interested in the implementation details, you can check out this article I wrote๏ผšไปŽSRDIๅŽŸ็†ๅ‰–ๆžๅ†ๅˆฐPE2Shellcode็š„ๅฎž็Žฐ-ๅ…ˆ็Ÿฅ็คพๅŒบ

My blog๏ผšๅ…ณไบŽ่ฟ™ไธชๅšๅฎข | onedaybook

TODO

I will maintain this project, focusing on the following key points:

  1. Add x86 support
  2. Introduce advanced features, such as supporting user data, obfuscating PE headers, etc.
  3. Add support for .NET assemblies
  4. Enhance RDI functionalities, including deferred imports, export conversion, etc.
  5. Further reduce the size of the srdi shellcode
  6. Fix bugs and address issues raised by community members

Disclaimer

This tool is provided for educational and research purposes only. It is intended for use by security professionals in legally authorized engagements. The author is not responsible for any misuse of this software. Users must ensure that they have proper authorization before using this tool on any system.

One more thing, I am no longer working in security, don't trace me.

test