我试图将一个简单的可执行文件注入另一个可执行文件中,不幸的是,每当我将代码注入可执行文件时,它会说'simpleinjected.exe已停止工作'然后关闭。我正在使用CreateRemoteThread
来注入代码。这是我到目前为止所做的。
Injector.exe //注入代码的文件
#include <stdio.h>
#include <windows.h>
#define procId 2844
#define executable "executable.exe" // located in same directory
int main()
{
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, procId);
LPVOID allocated = (LPVOID)VirtualAllocEx(hProc, NULL, strlen(executable), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(hProc, (LPVOID)allocated, executable, strlen(executable), NULL);
LPVOID libaddr = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
CreateRemoteThread(hProc, NULL, NULL, (LPTHREAD_START_ROUTINE)libaddr, NULL, NULL);
CloseHandle(hProc);
return 0;
}
Simpleinjected.exe //正在注入的文件
#include <stdio.h>
int main()
{
printf("Hello");
return 0;
}
executable.exe //将可执行文件注入simpleinjected
#include <windows.h>
int main()
{
MessageBox(NULL, "Injected successfully", "Code Injection", MB_OK);
return 0;
}
消息未显示且simpleinjected.exe
崩溃。崩溃显示代码已插入,但我不明白为什么它会崩溃。
当使用DLL和上面相同的技术时,dll在'simpleinjected.exe'中执行,但在注入Firefox时不起作用。 dll代码如下。它在自定义应用程序中执行,但不是Firefox,即使它已成功注入。
dllinject.dll
#include <windows.h>
int message(const char *msg)
{
MessageBox(NULL, msg, "Message from Dll", MB_OK);
return 0;
}
BOOL WINAPI DLLMain(HINSTANCE hInstDll, DWORD ulReason, LPVOID lpReserved)
{
switch(ulReason)
{
case DLL_PROCESS_ATTACH:
message("process attach");
break;
case DLL_THREAD_ATTACH:
message("thread attach");
break;
case DLL_PROCESS_DETACH:
message("process detach");
break;
case DLL_THREAD_DETACH:
message("thread detach");
break;
}
return true;
}
答案 0 :(得分:1)
Simpleinjected.exe的修改代码如下所示。然后再次尝试将dllinject.dll注入Simpleinjected.exe。
#include <stdio.h>
int main()
{
while(true)
{
printf("Hello");
}
return 0;
}
您应该修改下面的定义,与Simpleinjected.exe相同。
#define procId 2844 //process id of Simpleinjected.exe
#define executable "dllinject.dll" // located in same directory