-
February 3rd, 2012, 02:09 AM
#1
[Help/Advice needed]Program crashes when code is injected
Hi,
I have been trying awhile for weeks to do dll injection. Found several ways such as CreateRemoteThread(), SetWindowsHookEx() and Code Cave method. Currently working on CreateRemoteThread(), I have read up A LOT on it. Finally i managed to grab hold of it quite abit. But I'm still left with one last problem. I'm sure the code is injected into the remoteprocess, but the remote process crashes immediately after the code is injected.
Attached is the main highlights that the error should reside in.
Code:
typedef void (WINAPI *_GetModuleHandle)(LPCTSTR);
typedef struct MyData {
TCHAR dll_data_name[128];
HANDLE (WINAPI * _GetModuleHandle)(LPCTSTR);
} MYDATA, *PMYDATA;
DWORD WINAPI MyThreadFunction( LPVOID lpParam )
{
PMYDATA prd = (PMYDATA)lpParam;
prd->_GetModuleHandle(prd->dll_data_name);
return 0;
}
BOOL Inject(DWORD pID, char * DLL_N)
{
HANDLE Proc, hThread;LPVOID RemoteString;MYDATA * VirtualAllooo;HMODULE hModule;
DWORD dwNumBytesXferred = 0, dwThreadId = 0;
hModule = LoadLibrary("Project1");
MYDATA *dataLocal = {(PMYDATA)GetProcAddress(hModule, "Function")};
Proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
VirtualAllooo = (MYDATA*)VirtualAllocEx(Proc, NULL, sizeof(MYDATA), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(Proc, VirtualAllooo, &dataLocal, sizeof(MYDATA), &dwNumBytesXferred);
RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_N), MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(Proc, (LPVOID)RemoteString, DLL_NAME, strlen(DLL_N), NULL);
hThread = CreateRemoteThread(Proc, NULL, 0, (LPTHREAD_START_ROUTINE)RemoteString, VirtualAllooo, 0, &dwThreadId);
return true;
}
What went wrong here?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|