[Reversing] Code Injection Step 0
코드 인젝션 (Code Injection) 정의
Code Injection이란 실행 가능한 코드를 대상 메모리 영역으로 삽입하여 실행하는 것을 말한다.
코드 인젝션 활용 영역
- 프로그램의 기능 개선 및 버그 패치
- API 후킹
- 일반 응용 프로그램에 특별한 목적의 코드를 추가
- 악성코드에서의 활용
코드 인젝션 주요 동작 흐름
Windows API / Kernel Function
- 프로세스 권한 획득 : OpenProcess() / NtOpenProcess()
- 메모리 공간 할당 : VirtualAllocEx() / NtAllocateVirtualMemory()
- 코드 삽입 : WriteProcessMemory() / NtWriteVirtualMemory()
- 코드 실행 : CreateRemoteThread() / NtCreateThreadEx()
코드 인젝션 관련 주요 API
OpenProcess function (processthreadsapi.h) - Win32 apps
Opens an existing local process object.
docs.microsoft.com
VirtualAllocEx function (memoryapi.h) - Win32 apps
Reserves, commits, or changes the state of a region of memory within the virtual address space of a specified process. The function initializes the memory it allocates to zero.
docs.microsoft.com
VirtualProtectEx function (memoryapi.h) - Win32 apps
Changes the protection on a region of committed pages in the virtual address space of a specified process.
docs.microsoft.com
WriteProcessMemory function (memoryapi.h) - Win32 apps
Writes data to an area of memory in a specified process. The entire area to be written to must be accessible or the operation fails.
docs.microsoft.com
CreateRemoteThread function (processthreadsapi.h) - Win32 apps
Creates a thread that runs in the virtual address space of another process.
docs.microsoft.com