我正在尝试创建一个用于执行DLL-Injection的工具,方法是使用VirtualAclloc() API在正在运行的进程的内存中写入DLL,然后通过将入口点偏移量添加到VirtualAlloc函数的基址,找到入口点的偏移量并将其传递给VirtualAlloc API。
由于在调用lpStartAddress时没有任何需要传递给CreateRemoteThread()的参数,所以我将lpParameter初始化为NULL。
LPVOID lpParameter = NULL;
...
...
thread_handle = CreateRemoteThread(process_handle, NULL, 0, (LPTHREAD_START_ROUTINE)(base_address + offset), lpParameter, 0, NULL);在编译代码时,我得到了错误:
LPVOID:未知大小“和消息”表达式必须是指向完整对象类型的指针.
有什么方法可以将lpParameter的值作为NULL传递吗?
发布于 2019-07-05 07:01:14
base_address + offset将offset*sizeof *base_address字节添加到指针base_address中。但是如果base_address的类型是LPVOID,那么*base_address没有大小,所以这是一个错误。看看C++书中关于指针算法的一节。
从上下文来看,我想您应该将base_address改为char*而不是LPVOID。或者你可以添加一个像这样的(LPTHREAD_START_ROUTINE)((char*)base_address + offset)。
发布于 2019-07-05 11:41:49
在这种情况下,您需要遵循以下过程:
下面是示例代码:
char* dllPath = "C:\\testdll.dll";
int procID = 16092;
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
if (!hProcess) {
    printf("Error: Process not found.\n");
}
LPVOID lpvLoadLib = (LPVOID)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryA");       /*address of LoadLibraryA*/
if (!lpvLoadLib) {
    printf("Error: LoadLibraryA not found.\n");
}
LPVOID lpBaseAddress = (LPVOID)VirtualAllocEx(hProcess, NULL, strlen(dllPath)+1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);     /*Initialize and Allocate memory to zero in target process address space*/
if (!lpBaseAddress) {
    printf("Error: Memory was not allocated.\n");
}
SIZE_T byteswritten;
int result = WriteProcessMemory(hProcess, lpBaseAddress, (LPCVOID)dllPath, strlen(dllPath)+1, &byteswritten);   /*Write the path of dll to an area of memory in a specified process*/
if (result == 0) {
    printf("Error: Could not write to process address space.\n");
}
HANDLE threadID = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)lpvLoadLib, lpBaseAddress, NULL, NULL); /*lpStartAddress = lpvLoadLib address of LoadLibraryA function*/
if (!threadID) {
    printf("Error: Not able to create remote thread.\n");
}
else {
    printf("Remote process created...!");
}希望这能帮上忙
https://stackoverflow.com/questions/56897872
复制相似问题