BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
MessageBox(NULL,TEXT("注入次数!"),TEXT("提示"),MB_OK);
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBox(NULL,TEXT("DLL注入成功!"),TEXT("提示"),MB_OK);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
MessageBox(NULL,TEXT("DLL卸载成功!"),TEXT("提示"),MB_OK);
break;
}
return TRUE;
}
dllmain被调用了,但是会被反复调用很多次不知道为什么...
注入DLL的函数是在另一个DLL中的
int WINAPI cb_InjectDll(DWORD processID,PTCHAR dllName)
{
int len = wcslen(dllName);
LPVOID dllParam;
HANDLE hProcess;
HANDLE hThread;
LPTHREAD_START_ROUTINE dllStartFunc;
#ifdef INJECT_DEBUG
DWORD errorCode;
TCHAR code[128];
#endif
HMODULE hModule = GetModuleHandle(TEXT("kernel32.dll"));
if (hModule == NULL)
{
return ID_ERT_GETM_FALSE;
}
hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,processID);
if (hProcess == 0)
{
return ID_RET_OPEN_FALSE;
}
dllParam = VirtualAllocEx(hProcess,NULL,len * 2 + 1,MEM_COMMIT,PAGE_READWRITE);
if (dllParam == NULL)
{
CloseHandle(hProcess);
return ID_RET_ML_FALSE;
}
if (!WriteProcessMemory(hProcess,dllParam,dllName,len * 2 + 1,NULL))
{
VirtualFreeEx(hProcess,dllParam,len * 2 + 1,MEM_RELEASE);
CloseHandle(hProcess);
return ID_RET_WRITE_FALSE;
}
dllStartFunc = (LPTHREAD_START_ROUTINE)GetProcAddress(hModule,"LoadLibraryW");
if (dllStartFunc == NULL)
{
VirtualFreeEx(hProcess,dllParam,len * 2 + 1,MEM_RELEASE);
CloseHandle(hProcess);
return ID_RET_GETADD_FALSE;
}
hThread = CreateRemoteThread(hProcess,NULL,0,dllStartFunc,dllParam,0,NULL);
#ifdef INJECT_DEBUG
errorCode = GetLastError();
wsprintf(code,TEXT("%d"),errorCode);
MessageBox(NULL,code,NULL,MB_OK);
#endif
if (hThread == NULL)
{
VirtualFreeEx(hProcess,dllParam,len * 2 + 1,MEM_RELEASE);
CloseHandle(hProcess);
return ID_RET_CR_FALSE;
}
WaitForSingleObject(hThread,INFINITE);
VirtualFreeEx(hProcess,dllParam,len * 2 + 1,MEM_RELEASE);
CloseHandle(hThread);
CloseHandle(hProcess);
return ID_RET_SUCCESS;
}
而且用cmd tasklist /m命令查看被注入的程序的DLL引用中也没有被注入的函数
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)