Hallo allerseits,
erstmal vorweg, ich hab die Frage auch schon in einem anderen Forum gestellt, dort konnte mir aber nicht zur Lösung weitergeholfen werden.
C/C++ Forum :: Beispielprogramm zu Codeinjection
Ich versuch ein Programm zur Codeinjection zu schreiben und hab dazu ein Programm gefunden, dass in Assembler vorliegt und wollte das in C++ übersetzen und ausprobieren.
Hier ist erstmal der code was ich bisher hab:
Das Programm lässt sich compilieren und ausführen, aber sobald es VirtualFreeEx() und VirtualAllocEx() erreicht, bekomm ich den Fehlercode 87, welcher besagt, dass die Parameter incorrect sind. Nun, ich hab mit diesen Funktionen keine Erfahrung und finde den Fehler nicht. Könnt ihr mir da weiterhelfen?
erstmal vorweg, ich hab die Frage auch schon in einem anderen Forum gestellt, dort konnte mir aber nicht zur Lösung weitergeholfen werden.
C/C++ Forum :: Beispielprogramm zu Codeinjection
Ich versuch ein Programm zur Codeinjection zu schreiben und hab dazu ein Programm gefunden, dass in Assembler vorliegt und wollte das in C++ übersetzen und ausprobieren.
Hier ist erstmal der code was ich bisher hab:
Code:
#include <iostream>
#include <windows.h>
using namespace std;
void injectedThread();
int main()
{
//get imagebase address
HMODULE mHandle = GetModuleHandle(0);
/*HMODULE mHandle;
if(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, , mHandle) == 0)
{
cout << "GetModuleHandleEx() hat ein Problem" << endl;
return 0;
}*/
//PE headers stuff
DWORD *mHandlePtr = reinterpret_cast<DWORD*>(&mHandle);
mHandlePtr += 60; // 3Ch = 60d ... 3Ch = DOS_PREOFFSET
DWORD mHandleEx = reinterpret_cast<DWORD>(mHandle) + *mHandlePtr;
mHandleEx += 4;
mHandleEx += 20; //14h = 20d
mHandlePtr = &mHandleEx;
//DWORD dwSize = *(mHandlePtr + 56);
DWORD dwSize = 1884160;
//Internet Explorer fenster finden:
HWND hIExplorer = FindWindow("IEFrame", 0);
//HWND hIExplorer = FindWindow(0, "OllyDbg");
if(hIExplorer == 0)
cout << "Internet Explorer nicht gestartet." << endl;
else
cout << "Internet Explorer gefunden" << endl;
DWORD dwPID;
GetWindowThreadProcessId(hIExplorer, &dwPID);
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, false, dwPID);
if(process == 0)
cout << "Process konnte nicht geoeffnet werden" << endl;
else
cout << "Process geoeffnet" << endl;
LPVOID baseAddrOfAllcRgn = VirtualAllocEx(process, mHandle, dwSize, MEM_COMMIT || MEM_RESERVE,PAGE_EXECUTE_READWRITE);
//LPVOID baseAddrOfAllcRgn = VirtualAllocEx(process, NULL, dwSize, MEM_COMMIT || MEM_RESERVE,PAGE_EXECUTE_READWRITE);
if(baseAddrOfAllcRgn == NULL)
{
cout << "VirtualAllocEx hat ein Problem: " << GetLastError() << endl;
return 0;
}
else
cout << "VirtualAllocEx hat speicher reserviert" << endl;
bool bVFE = VirtualFreeEx(process, mHandle, 0, MEM_RELEASE);
if( bVFE == 0)
{
cout << "VirtualFreeEx hat ein Problem: " << GetLastError() << endl;
return 0;
}
else
cout << "VirtualFreeEx hat speicher freigegeben" << endl;
SIZE_T nBytesWritten;
WriteProcessMemory(process, baseAddrOfAllcRgn, mHandle, dwSize, &nBytesWritten);
LPDWORD lpNULL;
CreateRemoteThread(process, 0, 0, (LPTHREAD_START_ROUTINE)injectedThread, mHandle, 0, lpNULL);
ExitProcess(0);
return 0;
}
void injectedThread()
{
LoadLibrary("user32.dll");
MessageBox(0, "IExplorer", "Hello from iExplorer", 0);
ExitThread(0);
}