【问题标题】:how to use dll injecting?如何使用dll注入?
【发布时间】:2010-05-02 00:21:25
【问题描述】:

我正在研究如何将 dll 注入程序(exe 或 dll 等)。我一直在用谷歌搜索 dll 注入,但我没有找到任何非常有用的东西 :(。我没有经常使用 dll,所以我不知道该怎么做,我真的可以在这方面使用一些帮助。

呃,我真正找到的唯一东西是 setwindowshookex,但我找不到任何示例,而且我不知道如何使用它。任何问题都可以问,我会尽力提供帮助。

编辑嘿,我在谷歌上搜索,这看起来像是关于 dll 注入的东西,值得一看,但我无法运行代码:\ (How to hook external process with SetWindowsHookEx and WH_KEYBOARD)

【问题讨论】:

    标签: visual-c++ dll


    【解决方案1】:

    我最熟悉的方法是 Jefferey Richter 在Programming Applications for Microsoft Windows 中描述的。我之所以提到这一点,是因为即使您没有接触到这本书本身,也可能会出现示例代码。我想他可能也写过一些期刊文章。他还提到了几种替代方法,我将仅根据记忆描述其中一种。他也可能写过一些相关的 MSJ / MSDN 文章。

    无论如何,基本思想是使您要加载 DLL 的进程发出对 @987654322@ 的调用。这是使用@987654323@ 来完成的,LoadLibary 的地址为lpStartAddress,一个字符串的地址为lpParameter 命名你的DLL。使用@987654324@ 在远程进程中分配一些内存,并使用@987654325@ 用字符串填充它来安排和定位字符串。

    伪代码:

    void InjectDllIntoProcess(DWORD processId, char *dllName)
    {
      HANDLE hRemoteProcess = OpenProcess(
    
      // Assumes that dll and function addresses are the same in different processes
      // on the same system. I think that this is true even with ASLR, only issue I
      // can think of is to make sure that the source and target process are both 32
      // or both 64 bit, not a mixture.
      // Note that it is asking for the ASCII version
      HMODULE hDll = LoadLibrary(_T("Kernel32.dll"));
      void *loadLibAddr = GetProcAddress(hDll, _T("LoadLibraryA"));
    
    
      // Inject the DLL name
      char * remoteAddr = 
            (char *)VirtualAllocEx(hRemoteProcess, NULL, strlen(dllName) + 1, ...
      WriteProcessMemory(hRemoteProcess, remoteAddr, dllName, strlen(dllName) + 1 ...
    
      CreateRemoteThread(hRemoteProcess, ??, 0, loadLibAddr, remoteAddr, ...
    }
    

    【讨论】:

    • 好的,如果它加载我的 dll,它会像运行自己的代码一样运行我的代码?
    • 它所要做的就是加载库。这确实意味着它将调用 DLL 的 DllMain 进行初始化。从那里您可以做出您需要的任何其他安排。一旦对 LoadLibrary 的调用返回,您为调用 LoadLibrary 而创建的线程将终止。
    • 嗯不错 xD 这也是那本书的全部内容,对吧? amazon.com/Programming-Applications-Microsoft-Windows-General/…如果它有这一切我可能会买它,它还有什么?
    • @blood - 抱歉耽搁了,但是是的,这就是书。您会看到后面的一章专门讨论该主题。虽然这本书很旧,但作者有更新的书籍,可能值得看看是否有相同或更新的内容。
    猜你喜欢
    • 2014-05-10
    • 2023-03-27
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    相关资源
    最近更新 更多