C ++ Dll注入 [英] C++ Dll Injection

查看:184
本文介绍了C ++ Dll注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很感谢你的帮助。



我一直在试图将一个Dll注入一个远程进程,并在其中进行一些更改,这个问题我现在遇到了,我不知道该怎么做。



首先,这是我迄今为止开发的一段代码:

dllmain.cpp

  #include< windows.h> 
#include< stdio.h>

BOOL APIENTRY DllMain(HINSTANCE hInst / *库实例句柄* /,
DWORD原因/ *正在调用此函数的原因* /,
LPVOID reserved / *不使用。* /)
{
开关(原因)
{
案例DLL_PROCESS_ATTACH:
MessageBox(0,From DLL\\\
,Process Attach ,MB_ICONINFORMATION);
break;

case DLL_PROCESS_DETACH:
MessageBox(0,From DLL\\\
,Process Detach,MB_ICONINFORMATION);
break;

case DLL_THREAD_ATTACH:
MessageBox(0,From DLL\\\
,Thread Attach,MB_ICONINFORMATION);
break;

case DLL_THREAD_DETACH:
MessageBox(0,From DLL\\\
,Thread Detach,MB_ICONINFORMATION);
break;
}

返回TRUE;
}

它只是根据满足的条件显示一个消息框。
现在我想要我的Dll做的是,在注入到远程进程后,我想要它写一个内存位置并更改它的值。



数据类型:Unsigned Short Int

内存位置:0041D090



我希望一切都清楚,
谢谢你的耐心,帮助不胜感激。

解决方案

您不必编写一个DLL来修改另一个进程的内存。您可以使用 WriteProcessMemory()



然而...将DLL注入另一个进程的方式如下...


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


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


  3. 使用 CreateRemoteThread() 。您可以将 LoadLibrary()指向作为参数的入口点和步骤1和2的文件路径。说实话,这有点黑客,但是如果你正在注射一个DLL,那么你已经很吃惊了。另一种技术是使用步骤1& 2将一些机器代码加载到远程进程中,并将其指向。


请记住,这种技术是这是破坏目标进程稳定的好办法。特别是,这不是我最终会将产品交付给他人的产品。


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.

解决方案

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.

这篇关于C ++ Dll注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆