WriteProcessMemory
BOOL WriteProcessMemory(
[in] HANDLE hProcess,
[in] LPVOID lpBaseAddress,
[in] LPCVOID lpBuffer,
[in] SIZE_T nSize,
[out] SIZE_T *lpNumberOfBytesWritten
);인자
설명
Example
#include <windows.h>
#include <iostream>
using namespace std;
BOOL writeRemoteMemory(HANDLE hProc, LPVOID dest, void* data, SIZE_T size) {
// 쓴 데이터 크기 초기화
SIZE_T written = 0;
if (!WriteProcessMemory(hProc, dest, data, size, &written)) {
wcout << L"Failed to write memory" << endl;
return FALSE;
}
wcout << L"Written " << written << L" bytes" << endl;
return TRUE;
}
int main() {
DWORD pid = 1234;
unsigned char shellcode[] = { 0x90, 0x90, 0x90, 0xCC };
// OpenProcess를 통해 프로세스 핸들 획득
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (hProc) {
LPVOID mem = VirtualAllocEx(hProc, NULL, sizeof(shellcode),
MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (mem) {
// VirtualAllocEx로 획득한 메모리에 쉘코드 삽입
writeRemoteMemory(hProc, mem, shellcode, sizeof(shellcode));
VirtualFreeEx(hProc, mem, 0, MEM_RELEASE);
}
CloseHandle(hProc);
}
return 0;
}References
Last updated