I am trying to inject Dll throught CreateRemoteThread.
I am trying to inject it into notepad.exe whose pid is 1616
My code of injector program is
Code:
int main()
{
HANDLE hProcess = NULL, hThread = NULL;
PWSTR p = NULL;
// Get a handle for the target process.
hProcess = OpenProcess(
PROCESS_CREATE_THREAD | // For CreateRemoteThread
PROCESS_VM_OPERATION | // For VirtualAllocEx/VirtualFreeEx
PROCESS_VM_WRITE, // For WriteProcessMemory
FALSE, 1616);
printf("%d",hProcess);
PTHREAD_START_ROUTINE pfnThreadRtn = (PTHREAD_START_ROUTINE)
GetProcAddress(GetModuleHandle(TEXT("Kernel32")), "LoadLibraryA");
printf("%d",pfnThreadRtn);
char* pszLibFile = "C:\\dll_process_attach.dll";
int cch = 1 + strlen(pszLibFile);
int cb = cch * sizeof(WCHAR);
p=(PWSTR)VirtualAllocEx(hProcess,0,cb,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
if(p==NULL)
{
printf("virtual alloc funtion fiailed %d",GetLastError());
}
if (!WriteProcessMemory(hProcess, p,(PVOID)pszLibFile, cb, NULL))
printf("failed");
hThread = CreateRemoteThread(hProcess, NULL, 0,pfnThreadRtn, p, 0, NULL);
if (hThread == NULL) printf("\nremorethrad failed");
printf("%d",hThread);
}
code for the dll is....
Code:
#include "stdafx.h"
#include
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, PVOID fImpLoad)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
printf("Dll Injected");
return(TRUE); // Used only for DLL_PROCESS_ATTACH
}
}
Problem :-
code for the injector program is not showing any error while execution . But at the same time i dont see any change into my notepad.exe(1616) process.
I am a newbie to windows programming and just have basic knowledge abt dlls...
Shud`nt after the dll injection into the notepad process, "dll_injected" shud be printed as specified in the DllMain
If i am wrong or anything wrong with the injector code or dll code .. plz correct me ..
Thanx in advance