【问题标题】:Windows - How can I inject code in the kernel of a application before it starts?Windows - 如何在应用程序启动之前将代码注入到应用程序的内核中?
【发布时间】:2017-10-20 17:27:18
【问题描述】:

我想做一个恶意软件分析软件,我必须将代码注入到进程的不同 kernel32 函数中,例如 Sleep 以覆盖恶意软件尝试进行的任何睡眠,ExitProcess 在进程被杀死之前转储内存等

我尝试启动暂停的进程,然后尝试枚举库,希望我能获得 kernel32 rva,但当我启动暂停的进程时,似乎甚至没有加载库。

【问题讨论】:

    标签: code-injection easyhook


    【解决方案1】:

    您想要实现的目标可以使用 EasyHook API 轻松完成。该 API 在

    上可用

    https://github.com/EasyHook/EasyHook

    以下是覆盖 Kernel32.dll 中的 CreateFile 的示例。你需要CreateAndInject方法

    EasyHook.RemoteHooking.CreateAndInject(
                        targetExe,          // executable to run
                        "",                 // command line arguments for target
                        0,                  // additional process creation flags to pass to CreateProcess
                        EasyHook.InjectionOptions.DoNotRequireStrongName, // allow injectionLibrary to be unsigned
                        injectionLibrary,   // 32-bit library to inject (if target is 32-bit)
                        injectionLibrary,   // 64-bit library to inject (if target is 64-bit)
                        out targetPID,      // retrieve the newly created process ID
                        channelName         // the parameters to pass into injected library
                                            // ...
                    );
    

    关键是将进程的主线程 ID 发送到 Hooking DLL,然后该 DLL 应该修补并唤醒主线程。如下在 EasyHook 中完成的

    if((hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, ThreadID)) == NULL)
        THROW(STATUS_INTERNAL_ERROR, L"Unable to open wake up thread.");
    
    if(!ResumeThread(hThread))
        THROW(STATUS_INTERNAL_ERROR, L"Unable to resume process main thread.");
    

    其余的挂钩过程与任何 Windows 进程相同,通过打开进程并写​​入其内存以发送有效负载

    PS:如果您需要有关示例记事本应用程序的文件监控的详细示例,请查看

    https://easyhook.github.io/tutorials/remotefilemonitor.html

    更多教程源代码可在

    https://github.com/EasyHook/EasyHook-Tutorials

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 2014-10-13
      • 2013-11-16
      • 2016-04-23
      • 2014-06-28
      相关资源
      最近更新 更多