C ++代码注入使注入的应用程序崩溃

编程入门 行业动态 更新时间:2024-10-20 03:16:54
本文介绍了C ++代码注入使注入的应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

不幸的是,我尝试将一个简单的可执行文件注入到我制作的另一个可执行文件中,每当我将代码注入可执行文件时,它说 simpleinjected.exe已停止工作,然后关闭。我正在使用 CreateRemoteThread 注入代码。

I'm trying to inject a simple executable into another executable that I made, unfortunately, whenever I inject the code into the executable, it says 'simpleinjected.exe has stopped working' then it closes. I'm using CreateRemoteThread to inject the code. This is what I have done so far.

Injector.exe // //注入代码的文件

Injector.exe // the file that's injecting the code

#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 // //正在注入的文件

Simpleinjected.exe // the file being injected

#include <stdio.h> int main() { printf("Hello"); return 0; }

executable.exe //被注入的可执行文件放入simpleinjected

executable.exe // the executable being injected into simpleinjected

#include <windows.h> int main() { MessageBox(NULL, "Injected successfully", "Code Injection", MB_OK); return 0; }

消息未显示,并且 simpleinjected.exe 崩溃。崩溃表明已插入代码,但我不明白为什么崩溃。

The message is not displaying and simpleinjected.exe crashes. The crash shows that the code was inserted but I don't understand why it's crashing.

使用DLL和上述相同技术时,dll以'simpleinjected'执行。 exe,但在注入Firefox时不起作用。 dll代码如下。即使已成功注入,它也会在自定义应用程序中执行,但不会在Firefox中执行。

When using DLL and the same technique above, the dll executes in the 'simpleinjected.exe' but doesn't work when injected into Firefox. The dll code is below. It executes in the custom application but not Firefox even though it's injected successfully.

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; }

推荐答案

Simpleinjected.exe的修改后的代码如下。然后尝试再次将dllinject.dll注入Simpleinjected.exe。

modified code of Simpleinjected.exe as these below. and then try inject dllinject.dll to Simpleinjected.exe again.

#include <stdio.h> int main() { while(true) { printf("Hello"); } return 0; }

您应将以下定义与Simpleinjected.exe相同。

you should modify the defines below as same as Simpleinjected.exe.

#define procId 2844 //process id of Simpleinjected.exe #define executable "dllinject.dll" // located in same directory

更多推荐

C ++代码注入使注入的应用程序崩溃

本文发布于:2023-11-07 22:59:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567672.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!