Problem mit DLL Injector
-
hiho versuche gerade einen dll injector aus einem tut etwas umzubauen:
bool insertDll(DWORD procID, std::string dll) { //Find the address of the LoadLibrary api, luckily for us, it is loaded in the same address for every process HMODULE hLocKernel32 = GetModuleHandle("Kernel32"); FARPROC hLocLoadLibrary = GetProcAddress(hLocKernel32, "LoadLibraryA"); //Adjust token privileges to open system processes 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); } //Open the process with all access HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID); //Allocate memory to hold the path to the Dll File in the process's memory dll += '\0'; LPVOID hRemoteMem = VirtualAllocEx(hProc, NULL, dll.size(), MEM_COMMIT, PAGE_READWRITE); //Write the path to the Dll File in the location just created DWORD numBytesWritten; WriteProcessMemory(hProc, hRemoteMem, dll.c_str(), dll.size(), &numBytesWritten); //Create a remote thread that starts begins at the LoadLibrary function and is passed are memory pointer HANDLE hRemoteThread = CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)hLocLoadLibrary, hRemoteMem, 0, NULL); using namespace std; //Wait for the thread to finish bool res = false; if (hRemoteThread) res = (bool)WaitForSingleObject(hRemoteThread, MAXWAIT) != WAIT_TIMEOUT; //Free the memory created on the other process VirtualFreeEx(hProc, hRemoteMem, dll.size(), MEM_RELEASE); //Release the handle to the other process CloseHandle(hProc); return res; } int main() { DWORD PID; DWORD oldPID = 0; CHAR szAppPath[MAX_PATH]; GetModuleFileName(NULL,szAppPath,sizeof(szAppPath)); *(strrchr(szAppPath,'\\')) = 0; strcat(szAppPath, "\\"); strcat(szAppPath, DLL_NAME); PROCESSENTRY32 entry; entry.dwFlags = sizeof( PROCESSENTRY32 ); HANDLE snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, NULL ); if (Process32First(snapshot, &entry )) { while ( Process32Next( snapshot, &entry )) { if ( stricmp( entry.szExeFile, TARGET_PROCESS ) == 0) { EnableDebugPrivilege(); HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID ); PID = GetProcessId(hProcess); cout<<PID; cout<<"\n"; insertDll(PID, szAppPath); CloseHandle( hProcess ); } } }dabei geht es speziell um diesen Teil:
cout<<PID; cout<<"\n"; insertDll(PID, szAppPath);es wird einfach keine PID gedruckt in der konsole.
Kommentiere ich jedoch insertDll(...) aus dann geht alles wunderbar.Die DLL inject funktion geht jedoch wenn ich die PID selbst eingebe anstatt mit einer variable wird die .dll injected
es scheint mir so ,dass die insertDll irgendwelche probleme bei dem snapshot verursacht. Doch leider bin ich zu unfähig das ganze zu debuggen

jemand ne idee?
-
Habe nun weiter pobiert und hab nun gemerkt ,dass Process32First() den Fehler 24 zurück gibt (BAD_LENGTH)
PROCESSENTRY32 entry; entry.dwFlags = sizeof(PROCESSENTRY32);PROCESSENTRY32 entry; entry.dwFlags = sizeof(entry);hab ich schon versucht gibt das gleiche zurück

-
Hallo, du musst anstatt dwFlags dwSize verwenden.
Das müsste dann so aussehen:
PROCESSENTRY32 entry; entry.dwSize = sizeof(PROCESSENTRY32);MfG, Jochen
-
Willst wohl ein Hacker werden hä. Hör doch auf mit deinen DLL Injections