gpt4 book ai didi

c++ - 使用 CreateRemoteThread 注入(inject) DLL

转载 作者:IT老高 更新时间:2023-10-28 21:42:40 27 4
gpt4 key购买 nike

如果您看一下以下简单 DLL 注入(inject)的工作代码:

  //Open the target process with read , write and execute priviledges
Process = OpenProcess(PROCESS_CREATE_THREAD|PROCESS_QUERY_INFORMATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_VM_OPERATION, FALSE, ID);

//Get the address of LoadLibraryA
LoadLibrary = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");

// Allocate space in the process for our DLL
Memory = (LPVOID)VirtualAllocEx(Process, NULL, strlen(dll)+1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

// Write the string name of our DLL in the memory allocated
WriteProcessMemory(Process, (LPVOID)Memory, dll, strlen(dll)+1, NULL);

// Load our DLL
CreateRemoteThread(Process, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibrary, (LPVOID)Memory, NULL, NULL);

//Let the program regain control of itself
CloseHandle(Process);

让我困惑的是GetProcAddress返回当前进程LoadLibraryA函数地址,你怎么能把它作为参数传递给CreateRemoteThread 并期望 目标进程 运行它?

最佳答案

它的工作原理是偶然的。这是一个非常常见的意外,Microsoft 做了很多努力来确保操作系统 DLL,如 kernel32.dll,有一个不会与任何其他 DLL 冲突的基地址。由于 kernel32.dll 在进程初始化时很早就被加载,因此它得到进一步增强的可能性非常低,以至于它必须努力获得它的首选基地址。

你会轻松逃脱。值得注意的是,这个已经在过去出了问题,有一个 XP 安全更新 oops 导致 gdi32.dll 重新定位并导致许多机器在启动时翻倒。正确的方法是相当痛苦的,CreateToolhelp32Snapshot() + Module32First/Next() 找到重定位偏移量并不是很开心。坦率地说,如果操作系统像那样“怪异”,您可能根本不应该这样做。

关于c++ - 使用 CreateRemoteThread 注入(inject) DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22750112/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com