我正在尝试创建一个用于执行DLL-Injection
的工具,方法是使用VirtualAclloc()
API将DLL写入正在运行的进程的内存中,然后找到入口点的偏移量并将其传递给{{ 1}} API,方法是将入口点偏移量添加到CreateRemoteThread()
函数的基地址中。
由于在调用VirtualAlloc
时没有传递给lpStartAddress
的任何参数,因此将CreateRemoteThread()
初始化为NULL。
lpParameter
在编译代码时出现错误:
LPVOID:未知大小”和消息“表达式必须是指向完整对象类型的指针。
有没有一种方法可以将
LPVOID lpParameter = NULL;
...
...
thread_handle = CreateRemoteThread(process_handle, NULL, 0, (LPTHREAD_START_ROUTINE)(base_address + offset), lpParameter, 0, NULL);
的值传递为NULL?
答案 0 :(得分:4)
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)
添加演员表。
答案 1 :(得分:0)
在这种情况下,您需要执行以下过程:
下面是示例代码:
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...!");
}
希望这会有所帮助