gpt4 book ai didi

c++ - Dll 注入(inject) - 在另一个进程中编写 native 代码

转载 作者:太空狗 更新时间:2023-10-29 23:18:53 29 4
gpt4 key购买 nike

好的,我对 C++ Dll Injection 的第 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.

所以我的问题是:在使用 VirtualAllocEx 分配内存并使用 WriteProcessMemory 编写代码后,如何调用 CreateRemoteThread — 我的意思是第四和第五个参数是什么?

我的代码:

AllocatedMem = VirtualAllocEx(Proc, IntPtr.Zero, code.Length,
AllocationType.Reserve | AllocationType.Commit, MemoryProtection.ReadWrite);

WriteProcessMemory(Proc, AllocatedMem, code, code.Length, IntPtr.Zero);

CreateRemoteThread(Proc, IntPtr.Zero, 0, AllocatedMem,
IntPtr.Zero, 0, IntPtr.Zero);

最佳答案

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682437(v=vs.85).aspx

HANDLE WINAPI CreateRemoteThread(
_In_ HANDLE hProcess,
_In_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ SIZE_T dwStackSize,
_In_ LPTHREAD_START_ROUTINE lpStartAddress,
_In_ LPVOID lpParameter,
_In_ DWORD dwCreationFlags,
_Out_ LPDWORD lpThreadId
);

hProcess 是应在其中创建线程的进程的句柄。

lpThreadAttributes 可以为 NULL 以指定“使用默认值”

dwStackSize 可以为零以指定“使用默认值”

lpStartAddress 是线程开始执行的IN THE FOREIGN PROCESS地址

lpParameter 是在外部进程中传递给 ThreadMain 的参数(即在外部进程中,假定使用 WINAPI 调用约定调用 lpStartAddress,lpParameter 作为唯一参数)。

dwCreationFlags 可以为零。

lpThreadId 应该是一个指向 DWORD 的指针,如果成功,它会接收线程 ID。

如果您将 lpStartAddress 设置为 LoadLibraryW 的地址并将 lpParameter 设置为指向 L"foo.dll"的 IN THE FOREIGN PROCESS 指针,那么当线程在外部进程中启动时,它将立即调用LoadLibraryW(L"foo.dll") 在外部进程中,允许您从 DllMain 内部运行代码。

关于c++ - Dll 注入(inject) - 在另一个进程中编写 native 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11993098/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com