C++ DLL注入

发布于 2024-08-12 13:18:08 字数 1122 浏览 3 评论 0原文

我非常感谢您对此的帮助。

我一直在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So要识趣 2024-08-19 13:18:08

您不必编写 DLL 来更改另一个进程的固定地址内存。您可以使用 WriteProcessMemory()< /代码>。

但是...将DLL注入另一个进程的方法如下...

  1. 使用VirtualAllocEx() 将文件路径的长度分配给目标进程内存中的 DLL...这就像远程执行 malloc

  2. 使用WriteProcessMemory() 将 DLL 的文件路径复制到上一步返回的内容中。这就像远程执行 strcpy

  3. 使用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...

  1. Use VirtualAllocEx() to allocate the length of the file path to the DLL inside the target process's memory... This is like remotely doing a malloc.

  2. Use WriteProcessMemory() to copy the file path to the DLL into what was returned from the previous step. This is like remotely doing a strcpy.

  3. Use CreateRemoteThread(). You can point it at LoadLibrary() 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文