[C] 纯文本查看 复制代码
#include <Windows.h>
#include <TlHelp32.h>
int main()
{
/**********Ⅰ.依次获取窗口句柄,进程ID,线程句柄**********/
DWORD pid = NULL;
HWND hWnd = FindWindowW(NULL, L"Plants vs. Zombies");
GetWindowThreadProcessId(hWnd, &pid);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
/*********************Ⅱ.获取模块地址*******************/
DWORD modaddr = NULL;
MODULEENTRY32 modentry;
memset(&modentry, 0, sizeof(modentry));
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
modentry.dwSize = sizeof(MODULEENTRY32);
Module32FirstW(hSnapshot, &modentry);
do {
if (wcscmp(modentry.szModule, L"popcapgame1.exe") == 0)
{
modaddr = (DWORD)modentry.hModule;
CloseHandle(hSnapshot);
break;
}
} while (Module32Next(hSnapshot, &modentry));
/**************Ⅲ.创建并远程调用shellcode***************/
BYTE shellcode[1024] =
{
0x60, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x8D, 0x6D, 0x1D, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0x6A,
0x14, 0x8B, 0x45, 0x00, 0x8B, 0x4D, 0x04, 0x51, 0x8B, 0x55, 0x08, 0x52, 0x8B, 0x4D, 0x0C, 0xFF,
0xD1, 0x61, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
};
//对象指针 pObj [[popcapgame1.exe + 0x331C50]+ 0x868]
//函数指针 pFunc popcapgame1.exe + 105A0
DWORD x = 0;
DWORD y = 0;
DWORD pObj = modaddr;
ReadProcessMemory(hProcess, (LPCVOID)(pObj + 0x331C50), &pObj, 4, 0);
ReadProcessMemory(hProcess, (LPCVOID)(pObj + 0x868), &pObj, 4, 0);
DWORD pFunc = modaddr + 0x105A0;
*(DWORD*)(shellcode + 0x23) = y;
*(DWORD*)(shellcode + 0x27) = x;
*(DWORD*)(shellcode + 0x2B) = pObj;
*(DWORD*)(shellcode + 0x2F) = pFunc;
while (true)
{
*(DWORD*)(shellcode + 0x23) = y;
LPVOID calladdr = VirtualAllocEx(hProcess, NULL, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(hProcess, calladdr, shellcode, 1024, NULL);
HANDLE hRemote = CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)calladdr, NULL, NULL, NULL);
WaitForSingleObject(hRemote, INFINITE);
y++;
if (y == 5) y = 0;
Sleep(1000);
VirtualFreeEx(hProcess, calladdr, NULL, MEM_RELEASE);
CloseHandle(hRemote);
}
CloseHandle(hProcess);
return 0;
}