注入依赖项的DLL

时间:2019-06-30 07:30:19

标签: winapi c++-cli

我正在尝试将多个(2)DLL注入正在运行的进程中。我要注入的第一个是sdk,第二个需要sdk来确定操作。

当注入一个没有依赖性的DLL时,它可以完美地工作。另外,问题不在DLL上,因为在使用Xenos注入DLL时,它们工作得很好。

这是我的“注射器”功能。一个很标准的方法。

bool Core::b_Inject(DWORD id, const char* spath)
{
        System::Diagnostics::Trace::TraceInformation("Started DLL injection on {0}", System::DateTime::Now);

        HANDLE tarProcess = OpenProcess(PROCESS_ALL_ACCESS, false, id);

            if (tarProcess) {
            /*LoadLibrary is always on the same adress, so calling it is as easy as*/
            LPVOID loadLibW = (LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");

            if (!loadLibW) {
                System::Diagnostics::Trace::TraceError("Failed to LoadLibrary {0}", GetLastError());
                return false;
            }

            /*
            Allocate the dll
            */
            LPVOID loadPath = VirtualAllocEx(tarProcess,
                0,
                strlen(spath) + 1,
                MEM_RESERVE | MEM_COMMIT,
                PAGE_EXECUTE_READWRITE);

            /*
            IF WPM goes wrong.
            */
              if (!WriteProcessMemory(tarProcess,
                loadPath,
                (LPVOID)spath,
                strlen(spath) + 1,
                0)) {
                System::Diagnostics::Trace::TraceError("Failed to WPM {0}", GetLastError());
                return false;
             }

                /*
                WPM has been succesful. Let's create the remote thread
                */
             HANDLE remThread = CreateRemoteThread(tarProcess,
                    0,
                    NULL,
                    (LPTHREAD_START_ROUTINE)loadLibW,
                    loadPath,
                    NULL,
                    NULL);

                /*
                Oh noes, something's gone wrong
                */
            if (!remThread) {
                    System::Diagnostics::Trace::TraceError("Failed to create remote thread {0}", GetLastError());
                    return false;
                }

                /*
                Wait until CRT finishes
                */
            WaitForSingleObject(remThread, INFINITE);

                /*
                    We no longer need RemoteThread, Openprocess or RemoteProcess. So let's free em

                */
            CloseHandle(remThread);

             VirtualFreeEx(tarProcess,
                            loadPath,
                            strlen(spath) + 1,
                            MEM_RELEASE);

            CloseHandle(tarProcess);

            /*Everything gone's properly*/


            return true;
            }

            /*Shit's gone wrong*/
            System::Diagnostics::Trace::TraceError("Failed to inject {0}", GetLastError());
            return false;

}

This is where my inject function is called. pID is correct, too
```cpp
if (b_Inject(id, "sdk.dll")) {
                System::Diagnostics::Trace::TraceInformation("Injected sdkdll on {0}", id);

                if (b_Inject(id, "Client.dll")) {
                    System::Diagnostics::Trace::TraceInformation("Injected Client dll on {0}", id);
                }


I'd expect to either my injector fuction to fail and get an error in the log or the Client dll to load (it should create a logs folder + a log file, none of those is the case). None of those is the case

0 个答案:

没有答案