Injection: Schlägt fehl unter Windows 7 (32 & 64 Bit)



  • Hallo...
    Ich versuche derzeit eine DLL in einen Prozess zu injecten. Unter Windows XP (SP3) funktioniert das ganze problemlos. Unter Windows 7 (32 & 64 Bit) funktioniert das ganze jedoch nicht (Vista kann ich leider nicht testen).

    Ich verwende folgende Funktion (kommt aus den Weiten des Internets, ist leider schon ewig her und ich finde die Quelle nicht mehr :/):

    bool RemoteLoadLibW(DWORD dwProcessId, PCWSTR pszLibFile)
    {
    	bool bInjected = false;
    	HANDLE hProcess	= NULL, hThread = NULL;
    	int iChars = 1 + lstrlenW(pszLibFile);
    	int iSize = iChars * sizeof(WCHAR);
    	PWSTR pszLibFileRemote = NULL;
    
    	__try
    	{
    		hProcess = OpenProcess(PROCESS_ACCESS, FALSE, dwProcessId);
    
    		if (hProcess == NULL)
    		{
    			__leave;
    		}
    
    		pszLibFileRemote = (PWSTR)VirtualAllocEx(hProcess, NULL, iSize, MEM_COMMIT, PAGE_READWRITE);
    
    		if (pszLibFileRemote == NULL)
    		{
    			__leave;
    		}
    
    		if (!WriteProcessMemory(hProcess, pszLibFileRemote,(PVOID) pszLibFile, iSize, NULL))
    		{
    			__leave;
    		}
    
    		PTHREAD_START_ROUTINE pfnThreadRtn = (PTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("Kernel32"), "LoadLibraryW");
    
    		if (pfnThreadRtn == NULL)
    		{
    			__leave;
    		}
    
    		hThread = CreateRemoteThread(hProcess, NULL, 0, pfnThreadRtn, pszLibFileRemote, 0, NULL);
    
    		if (hThread == NULL)
    		{
    			__leave;
    		}
    
    		WaitForSingleObject(hThread, INFINITE);
    
    		bInjected = true;
    	}
    	__finally
    	{
    		if (pszLibFileRemote != NULL)
    		{
    			VirtualFreeEx(hProcess, pszLibFileRemote, iSize, MEM_RELEASE);
    		}
    
    		if (hThread  != NULL)
    		{
    			CloseHandle(hThread);
    		}
    
    		if (hProcess != NULL)
    		{
    			CloseHandle(hProcess);
    		}
    	}
    
    	return bInjected;
    }
    

    Selbst die einfachste DLL injected nicht (nur DLLMain und sonst nichts).
    Gibt es vielleicht bestimmte Projektoptionen die ich setzen muss?
    Als Compiler wird MSVC 08 verwendet.

    Edit: Also ich meine Projektoptionen für die DLL. Auch alternative Loader (z.B. Winject) funktionieren nicht.

    Gruß und Danke!



  • In der DLL die CRT statisch linken



  • Omg. Danke! 👍

    Gruß


Anmelden zum Antworten