Shellcode Injection
Apr 4, 2023
Last updated
Apr 4, 2023
Last updated
Shellcode injection consists of four basic steps which are:
Attach to/create a process.
Allocate some memory within that process.
Write the memory to the process.
Finally, create a thread to execute the code we injected into the process's memory.
Documentation for the following API calls can be found by clicking the functions header.
We will use msfvenom
in order to generate a simple payload that will run the calc.exe
application.
Remember to make an exception in your antivirus software. Using the Win32 API like that will immediately get the program flagged by your AV.
Now let's compile our script
Great! Our injector is ready. For demonstration purposes, we will inject into notepad.exe
For the sake of demonstration and logging, I added some prints in the code.
In the next writeup we will be talking about DLL Injections.
Let's start by implementing . The OpenProcess
function returns a handle to a specified process. In case of failure, it will return NULL
and we can get the error by calling GetLastError()
.
Therefore we can implement a simple check to handle errors:
And we did it! Congratulations