c++ winsock hook funktioniert nicht bei allen programmen ?



  • hi, ich habe einen dll geschrieben die ich in einen process injecte und mir dan die datenpakete die versendet werden anzeigt, hier der code: (kompiliert in visual studio 2013)

    #include <winsock2.h>
    #include <windows.h>
    #include <iostream>
    #include <fstream>
    
    #pragma comment(lib, "ws2_32.lib")
    using namespace std;
    
    BYTE hook[6];
    BYTE hook2[6];
    BYTE jmp[6] = { 0xe9, 0x00, 0x00, 0x00, 0x00, 0xc3 };
    DWORD pPrevious;
    
    DWORD HookFunction(LPCSTR lpModule, LPCSTR lpFuncName, LPVOID lpFunction, unsigned char *lpBackup)
    {
    	std::cout << "HOOK wird gestarted" << std::endl;
    	DWORD dwAddr = (DWORD)GetProcAddress(GetModuleHandle(lpModule), lpFuncName);
    	ReadProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, lpBackup, 6, 0);
    	DWORD dwCalc = ((DWORD)lpFunction - dwAddr - 5);
    	VirtualProtect((void*)dwAddr, 6, PAGE_EXECUTE_READWRITE, &pPrevious);
    	memcpy(&jmp[1], &dwCalc, 4);
    	WriteProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, jmp, 6, 0);
    	VirtualProtect((void*)dwAddr, 6, pPrevious, &pPrevious);
    	FlushInstructionCache(GetCurrentProcess(), 0, 0);
    	return dwAddr;
    }
    
    BOOL UnHookFunction(LPCSTR lpModule, LPCSTR lpFuncName, unsigned char *lpBackup)
    {
    	std::cout << "HOOK wird -gestarted" << std::endl;
    	DWORD dwAddr = (DWORD)GetProcAddress(GetModuleHandle(lpModule), lpFuncName);
    
    	if (WriteProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, lpBackup, 6, 0))
    		return TRUE;
    	FlushInstructionCache(GetCurrentProcess(), 0, 0);
    
    	return FALSE;
    }
    
    int __stdcall nSend(SOCKET s, const char *buf, int len, int flags){
    	UnHookFunction("ws2_32.dll", "send", hook);
    
    	int result = send(s, buf, len, flags);
    	MessageBox(NULL, TEXT("YOUS SEND"), TEXT("SEND"), MB_OK);
    	std::cout << "send: " << buf << std::endl;
    
    	HookFunction("ws2_32.dll", "send", (LPVOID*)nSend, hook);
    	return result;
    }
    
    int __stdcall nRecv(SOCKET s, char* buf, int len, int flags)
    {
    	UnHookFunction("ws2_32.dll", "recv", hook2);
    	DWORD tmp;
    
    	len = recv(s, buf, len, flags);
    
    	if (len > 0)
    	{
    		MessageBox(NULL, TEXT("YOUS recv"), TEXT("recv"), MB_OK);
    		std::cout << "recv: " << buf << std::endl;
    	}
    	HookFunction("ws2_32.dll", "recv", (LPVOID*)nRecv, hook2);
    	return len;
    }
    
    BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
    {
    	switch (ul_reason_for_call)
    	{
    	case DLL_PROCESS_ATTACH:
    		AllocConsole();
    		freopen("CONOUT$", "wb", stdout);
    		freopen("CONOUT$", "wb", stderr);
    		freopen("CONIN$", "rb", stdin);
    		std::cout << "DLL INJECTED------" << std::endl;
    		MessageBox(NULL, TEXT("DLL WRD GELADE"), TEXT("dll"), MB_OK);
    		HookFunction("ws2_32.dll", "send", (LPVOID*)nSend, hook);
    		HookFunction("ws2_32.dll", "recv", (LPVOID*)nRecv, hook2);
    	case DLL_THREAD_ATTACH:
    	case DLL_THREAD_DETACH:
    	case DLL_PROCESS_DETACH:
    		break;
    	}
    	return TRUE;
    }
    

    😋 wenn ich die dll in meinen konsolen chat client injecte klappt alles doch wenn ich es ine in spiel wie assaultcube injecte zeigt es mit keine gesendeten oder empfangenen daten 😮
    Ich join zuert ein server un dan injecte ich die dll 😃
    Hat jemand vielleicht eine lösun ?



  • Neben send() gibt's ja noch sendto, WSASend, WSASendTo usw.
    Vermutlich verwendet das Spiel WSASend.



  • Hi schrieb:

    Neben send() gibt's ja noch sendto, WSASend, WSASendTo usw.
    Vermutlich verwendet das Spiel WSASend.

    Werde es mal probieren 😋 👍
    Gibts auch einen weg herauszufinden welsche funktion das spiel benutz ?



  • hookuser schrieb:

    Hi schrieb:

    Neben send() gibt's ja noch sendto, WSASend, WSASendTo usw.
    Vermutlich verwendet das Spiel WSASend.

    Werde es mal probieren 😋 👍
    Gibts auch einen weg herauszufinden welsche funktion das spiel benutz ?

    Sorry aber ich glaube du hast nicht verstanden! Lerne mal Grundlagen!


Anmelden zum Antworten