How restkhz/shellcodeencrypt2dll works
Project type and purpose
• This is a security-oriented CLI tool written in Python and C++.
• Purpose: take raw shellcode, encrypt it (AES-CBC), generate a static Windows DLL loader (with or without embedding the key), optionally patch it further, then load and execute the shellcode via rundll32.
File structure
• Top level files:
• README.md – project description, usage, internals
• ShellcodeEncrypt2Dll.py – main Python script (encryption, code-gen, compile)
• patch.py – optional post-build DLL patcher to bypass AV
• template.cpp – C++ loader template that receives encrypted payload and decrypts/executes at runtime
• No separate “frontend/backend,” it’s a CLI-driven code-generation pipeline.
README for key insights
• Dependencies: pycryptodome, mingw-w64 toolchain, msfvenom for shellcode.
• Two modes:
• non-standalone (key passed at runtime)
• standalone (key embedded in DLL)
• Build flow: generate header from Python → compile via x86_64-w64-mingw32-g++ → produce loader.dll → optional patch → loader_patched.dll → load with rundll32.
Main components and their interactions
a. Shellcode input
• External: msfvenom (or any raw .raw shellcode file)
b. Encryption & code generation (ShellcodeEncrypt2Dll.py)
• Reads raw shellcode and API names
• Encrypts with AES-CBC using user key
• Emits a C/C++ header containing encrypted byte arrays + encrypted function name strings
c. Compilation
• template.cpp + generated header compiled by x86_64-w64-mingw32-g++ → loader.dll
d. Optional patching (patch.py)
• Applies binary modifications to loader.dll to further evade antivirus
• Outputs loader_patched.dll
e. Runtime loader
• Windows rundll32 loads DLL, calls export “EPoint”
• DLL decrypts payload, resolves WinAPI dynamically, allocates executable memory, launches shellcode
Architectural patterns & design principles
• Pipeline pattern: linear data flow through stages (encrypt → code-gen → compile → patch → run)
• Code-generation: Python script dynamically producing C++ source artifacts
• Separation of concerns:
• Encryption logic in Python
• Decryption/execution logic in C++ at runtime
• Optional AV-bypass patch in separate script
Technologies & external dependencies
• Python 3 + pycryptodome (AES library)
• MinGW-w64 cross-compiler (x86_64-w64-mingw32-g++)
• Windows API: VirtualAlloc, CreateThread, LoadLibrary/GetProcAddress (dynamic loading)
• msfvenom or equivalent for shellcode generation