Bei OpenProcess habe ich seither PROCESS_ALL_ACCESS verwendet. Auch mit den Änderungen, die Bot_interesierter vorgeschlagen hat, hats leider nicht funktioniert.
Hier mein Source-Code:
Code:
const char Path[] = "C:\\Message Box.dll";
int main()
{
PROCESSENTRY32 p32;
DWORD processId = NULL;
HANDLE hSnapshot;
p32.dwSize = sizeof(p32);
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
Process32First(hSnapshot,&p32);
if(!strcmp("notepad.exe",p32.szExeFile))
{
processId = p32.th32ProcessID;
}else
{
while(Process32Next(hSnapshot,&p32))
{
if(!strcmp("notepad.exe",p32.szExeFile))
{
processId = p32.th32ProcessID;
break;
}
}
}
if(processId == NULL)
{
printf("Zielprozess wurde nicht gefunden\n");
pause();
return -1;
}
if(!insertDll(processId,Path))
{
printf("Dll konnte nicht injected werden!\n");
}else
printf("Dll injected!\n");
pause();
return 0;
}
Und ganz wichtig insertDll:
Code:
bool insertDll(DWORD procID, std::string dll)
{
HMODULE hLocKernel32 = GetModuleHandle("kernel32.dll");
FARPROC hLocLoadLibrary = GetProcAddress(hLocKernel32, "LoadLibraryA");
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, 0, &tkp, sizeof(tkp), NULL, NULL);
}
HANDLE hProc = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, procID);
dll += '\0';
LPVOID hRemoteMem = VirtualAllocEx(hProc, NULL, dll.size(), MEM_COMMIT, PAGE_READWRITE);
DWORD numBytesWritten;
WriteProcessMemory(hProc, hRemoteMem, dll.c_str(), dll.size(), &numBytesWritten);
HANDLE hRemoteThread = CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)hLocLoadLibrary, hRemoteMem, 0, NULL);
bool res = false;
if (hRemoteThread)
res = (bool)WaitForSingleObject(hRemoteThread, INFINITE);
else
{
DWORD err = GetLastError();
LPVOID MsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,err,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &MsgBuf,0, NULL );
printf("%s",(LPSTR)MsgBuf);
}
VirtualFreeEx(hProc, hRemoteMem, dll.size(), MEM_RELEASE);
CloseHandle(hProc);
return res;
}
Wenn ich das Programm ausführe, kommen die beiden Fehlermeldungen
Der Vorgang wurde erfolgreich beendet. und
Dll konnte nicht injected werden!
Die dll "Message Box.dll" ist die Dll aus dem Tutorial, dass ich in meinem ersten Post verlinkt habe. Könnte es vll. auch an der dll liegen und wenn ja, gibt es ne Möglichkeit zu testen, ob es mit der Dll überhaupt funktioniert?