Shellcode Process Injection

Basic process injection

My Corresponding GitHub Page

General Steps

  • Save a list of all running processes

  • Search for the defined target process

  • Extract the PID of the target process

  • Open the target process

  • Allocate memory in target process

  • Inject code into target process

  • Execute the injected code

Windows APIs

  • CreateToolhelp32Snapshot to create a "snapshot" of all processes in the system to later enumerate

  • Process32First to start enumerating the list of processes from the snapshot starting from the first

  • Process32Next goes to the next process in the snapshot

  • OpenProcess to open a handle to the target process

  • VirtualAllocEx to allocated memory in the target process

  • WriteProcessMemory to write the payload into the allocated memory spaces

  • CreateRemoteThread to start executing a thread in the process to run the payload

  • WaitForSingleObject to pause execution of the injecting process until the injected code is completed or the specified time amount (500 milliseconds in the code)

  • CloseHandle to close a handle

Code

Last updated