This repository demonstrates a clean and modular approach to executing shellcode in a Windows environment using Golang. The project leverages Windows API calls via the windows
and syscall
packages to dynamically allocate memory, copy shellcode, change memory permissions, and create a new thread for execution.
-
Memory Allocation:
UtilizesVirtualAlloc
to reserve and commit memory for the shellcode. -
Shellcode Copy:
UsesRtlMoveMemory
fromNtdll.dll
to copy the decoded shellcode into the allocated memory space. -
Memory Protection:
Changes memory permissions from read-write to execute-read usingVirtualProtect
, ensuring the shellcode can be safely executed. -
Thread Creation:
EmploysCreateThread
fromkernel32.dll
to run the shellcode in a new thread. -
Thread Synchronization:
ImplementsWaitForSingleObject
to pause the main program until the shellcode execution completes, preventing premature termination.
-
Clean & Modular Code:
The source code is organized into clear, self-contained functions (e.g.,AllocateShellcode
,CopyShellcodeToMemory
,ChangeShellcodeMemoryToRX
,CreateThread
, andRunShellcode
). This structure not only makes the code easy to read and maintain but also serves as a good reference for best practices in shellcode execution on Windows using Golang. -
Descriptive Logging & Comments:
Throughout the code, descriptive log messages and inline comments explain the purpose of each operation, enhancing readability and maintainability.
-
Shellcode Decoding & Memory Allocation:
The shellcode is stored as a hex string and is decoded into a byte slice usinghex.DecodeString
. Memory is then allocated usingVirtualAlloc
to provide a writable region. -
Copying & Setting Up Shellcode:
The decoded shellcode is copied into the allocated memory usingRtlMoveMemory
. Memory permissions are changed from read-write to execute-read withVirtualProtect
to allow execution. -
Execution via Thread Creation:
A new thread is created withCreateThread
that points directly to the shellcode's memory location. The main function waits for the thread to finish execution usingWaitForSingleObject
.
-
Setup:
Ensure you have Go installed on your Windows machine and that your environment is properly configured. -
Build the Project:
Compile the project by running:go build -o shellcodeRunner.exe
-
Execute:
Run the generated executable. The shellcode (provided as a hex string in the code) will be allocated, copied into memory, and executed within a new thread.
This project is intended for educational and research purposes only. Use it responsibly and ensure you have proper authorization before executing or testing shellcode in any environment.
Feel free to explore the code and use it as a learning tool to understand advanced Windows API interactions and dynamic code execution using Golang.