|
发表于 2025-3-16 17:42:46
|
显示全部楼层
山西省太原市
#include <windows.h>
#include <iostream>
// 示例: 一个简单的汇编代码片段,它只是返回0
unsigned char shellcode[] = {
0xB8, 0x00, 0x00, 0x00, 0x00, // mov eax, 0
0xC3 // ret
};
int main() {
DWORD targetPID = 1234; // 替换为你的目标进程ID
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, targetPID);
if (hProcess == NULL) {
std::cerr << "无法打开进程" << std::endl;
return -1;
}
// 分配内存
LPVOID pRemoteCode = VirtualAllocEx(hProcess, NULL, sizeof(shellcode), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (pRemoteCode == NULL) {
std::cerr << "内存分配失败" << std::endl;
CloseHandle(hProcess);
return -1;
}
// 写入shellcode
SIZE_T bytesWritten;
if (!WriteProcessMemory(hProcess, pRemoteCode, shellcode, sizeof(shellcode), &bytesWritten)) {
std::cerr << "写入内存失败" << std::endl;
VirtualFreeEx(hProcess, pRemoteCode, 0, MEM_RELEASE);
CloseHandle(hProcess);
return -1;
}
// 创建远程线程
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pRemoteCode, NULL, 0, NULL);
if (hThread == NULL) {
std::cerr << "创建远程线程失败" << std::endl;
VirtualFreeEx(hProcess, pRemoteCode, 0, MEM_RELEASE);
CloseHandle(hProcess);
return -1;
}
// 等待线程结束
WaitForSingleObject(hThread, INFINITE);
// 清理
VirtualFreeEx(hProcess, pRemoteCode, 0, MEM_RELEASE);
CloseHandle(hThread);
CloseHandle(hProcess);
std::cout << "执行完成" << std::endl;
return 0;
}
自己按自己的需求改装 |
|