C++ DLL注入
我非常感谢您对此的帮助。
我一直在尝试将 Dll 注入远程进程并在其中进行一些更改,我现在遇到的问题是我不知道如何实现这一点。
首先,这是我迄今为止开发的一段代码:
dllmain.cpp
#include <windows.h>
#include <stdio.h>
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
MessageBox (0, "From DLL\n", "Process Attach", MB_ICONINFORMATION);
break;
case DLL_PROCESS_DETACH:
MessageBox (0, "From DLL\n", "Process Detach", MB_ICONINFORMATION);
break;
case DLL_THREAD_ATTACH:
MessageBox (0, "From DLL\n", "Thread Attach", MB_ICONINFORMATION);
break;
case DLL_THREAD_DETACH:
MessageBox (0, "From DLL\n", "Thread Detach", MB_ICONINFORMATION);
break;
}
return TRUE;
}
它只是根据满足的条件显示一个消息框。 现在我希望我的 Dll 做的是,在注入远程进程后,我希望它写入一个内存位置并更改它的值。
数据类型:无符号短整型
内存位置:0041D090
我希望一切都清楚, 感谢您的耐心等待,感谢您的帮助。
I would really appreciate your help in this.
I have been trying to get a Dll injected into a remote process and do a few changes inside it, the problem I'm encountering right now is i don't know how to get this going.
So first, here is my piece of code that I have developed so far:
dllmain.cpp
#include <windows.h>
#include <stdio.h>
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
MessageBox (0, "From DLL\n", "Process Attach", MB_ICONINFORMATION);
break;
case DLL_PROCESS_DETACH:
MessageBox (0, "From DLL\n", "Process Detach", MB_ICONINFORMATION);
break;
case DLL_THREAD_ATTACH:
MessageBox (0, "From DLL\n", "Thread Attach", MB_ICONINFORMATION);
break;
case DLL_THREAD_DETACH:
MessageBox (0, "From DLL\n", "Thread Detach", MB_ICONINFORMATION);
break;
}
return TRUE;
}
It simply displays a message box depending on the conditions it meets.
Now what I would like my Dll to do is, after being injected into the remote process, I would like it to write a memory location and change it's value.
Data type: Unsigned Short Int
Memory location: 0041D090
I hope everything is clear,
Thank you for your patience, help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必编写 DLL 来更改另一个进程的固定地址内存。您可以使用
WriteProcessMemory()< /代码>。
但是...将DLL注入另一个进程的方法如下...
使用
VirtualAllocEx()
将文件路径的长度分配给目标进程内存中的 DLL...这就像远程执行malloc
。使用
WriteProcessMemory()
将 DLL 的文件路径复制到上一步返回的内容中。这就像远程执行strcpy
。使用
CreateRemoteThread()
。您可以将其指向 LoadLibrary() 作为入口点,并将步骤 1 和 2 中的文件路径作为参数。老实说,这有点 hacky,但是如果您注入 DLL,那么您就已经很 hacky 了。另一种技术是使用步骤 1 和步骤 2。 2 将一些机器代码加载到远程进程中并将其指向该进程。请记住,此技术是破坏目标过程稳定性的好方法。特别是,我不会在最终交付给其他人的产品中这样做。
You don't have to write a DLL to change another process's memory at a fixed address. You can use
WriteProcessMemory()
.However... The way to inject a DLL into another process is the following...
Use
VirtualAllocEx()
to allocate the length of the file path to the DLL inside the target process's memory... This is like remotely doing amalloc
.Use
WriteProcessMemory()
to copy the file path to the DLL into what was returned from the previous step. This is like remotely doing astrcpy
.Use
CreateRemoteThread()
. You can point it atLoadLibrary()
as the entry point and the file path from steps 1 and 2 as the argument. That's a bit hacky, to be honest, but if you are injecting a DLL you're already being quite hacky. Another technique would be to use steps 1 & 2 to load some machine code into the remote proceess and point it at that.Keep in mind that this technique is a great way to destabilize the target process. In particular, this isn't something I'd do in a product that ends up getting shipped to others.