Process Injection --Part 1--

This C program performs process injection, specifically remote code injection into a running instance of notepad.exe. Here's a step-by-step breakdown of what the code does:

1 - FindTarget Function (Finds Process ID)

  • The FindTarget function takes a process name (ProcName) as an argument and searches for a running process with that name.

  • It uses CreateToolhelp32Snapshot to take a snapshot of all running processes.

  • It iterates through the process list using Process32Next, checking if the process name matches ProcName (notepad.exe in this case).

  • If found, it returns the process ID (PID) of the target process

2 - Injection into Notepad

  1. Open Notepad Process

    • The OpenProcess function is used to get a handle to the notepad.exe process with full access (PROCESS_ALL_ACCESS)

  2. Allocate Memory in Notepad

    • VirtualAllocEx reserves memory inside notepad.exe with PAGE_EXECUTE_READWRITE permissions, allowing the shellcode to be written and executed.

  3. Write the Shellcode into Notepad

    • WriteProcessMemory writes the shellcode (payload[]) into the allocated memory space.

  4. Execute the Shellcode in Notepad

    • CreateRemoteThread starts a new thread inside notepad.exe at the memory location where the shellcode was written, effectively executing it.

Last updated