Salve,
Nel corso della mia carriera da sviluppatore e da videogiocatore, mi sono ritrovato spesso a dovermi interfacciare con cheat che includevano l'edit di alcuni pacchetti scambiati tra client e server, così da exploitare alcune funzioni: un esempio comune è l'integer exploit (overflow/underflow).
Intrigato da questo argomento, stavo pensando di scrivere una dll, che se injectata mi consentisse di "sviare" il normale corso di "send" e "recv" così da leggere il traffico di pacchetti e gestirlo come meglio credo (al netto di crittazioni di cui sono già a conoscenza), e per l'occasione, ho deciso di affidarmi direttamente alla libreria Microsoft Detour la quale dovrebbe consentirmi di eseguire l'hook delle suddette funzioni, senza dovermi scervellare più di tanto.
Ebbene, sono riuscito ad includere l'header nel progetto senza troppi problemi, ma sto avendo alcuni problemi con la compilazione.... vi mostro il codice!
CODE:
Purtroppo è uno dei miei primi progetti in C++ e quasi sicuramente avrò sbagliato qualcosa, allego anche la lista degli errori che il compilatore mi da:
Il problema fondamentale, è che l'IDE non mostra alcun segno rosso se tento di cliccare sull'errore, "come se in verità la sintassi fosse corretta, ma fosse sbagliata la semantica", allego un esempio:
Nel corso della mia carriera da sviluppatore e da videogiocatore, mi sono ritrovato spesso a dovermi interfacciare con cheat che includevano l'edit di alcuni pacchetti scambiati tra client e server, così da exploitare alcune funzioni: un esempio comune è l'integer exploit (overflow/underflow).
Intrigato da questo argomento, stavo pensando di scrivere una dll, che se injectata mi consentisse di "sviare" il normale corso di "send" e "recv" così da leggere il traffico di pacchetti e gestirlo come meglio credo (al netto di crittazioni di cui sono già a conoscenza), e per l'occasione, ho deciso di affidarmi direttamente alla libreria Microsoft Detour la quale dovrebbe consentirmi di eseguire l'hook delle suddette funzioni, senza dovermi scervellare più di tanto.
Ebbene, sono riuscito ad includere l'header nel progetto senza troppi problemi, ma sto avendo alcuni problemi con la compilazione.... vi mostro il codice!
CODE:
C++:
#include <windows.h>
#include <fstream> // Required to output logs to files
#include <iomanip> // Required to display the hex properly
#include "pch.h"
// Detours: https://www.microsoft.com/en-us/research/project/detours/
#include "E:\Informatica\Detours-4.0.1\src\detours.h" // Version 3.0 use for this hook. Be sure to include the library and includes to your project in visual studio
#pragma comment(lib,"detours.lib") // Need to include this so we can use Detours
#pragma comment(lib,"ws2_32.lib") // Required to hook Send and Recv since they both reside in this library
extern "C"
{ // Pointers to the original functions
int (WINAPI* originalSend)(SOCKET s, const char* buf, int len, int flags) = send; // https://msdn.microsoft.com/en-us/library/windows/desktop/ms740149(v=vs.85).aspx
int (WINAPI* originalRecv)(SOCKET s, char* buf, int len, int flags) = recv; // https://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx
}
HMODULE hModule;
std::ofstream sendLog;
std::ofstream recvLog;
int WINAPI newSend(SOCKET s, char* buf, int len, int flags) // Dumps each buffer to a new line in the "send.txt" file in the games directory
{
sendLog.open("send.txt", std::ios::app); // Opens a handle to the send file
for (int i = 0; i < len; i++) { // For each byte:
sendLog << std::hex << std::setfill('0') << std::setw(2) << (unsigned int)(unsigned char)buf[i] << " "; // Log the hex of the byte with a width of 2 (leading 0 added if necessary) and a space after to separate bytes
}
sendLog << std::endl; // Add a newline to the text file, indicating the end of this request
sendLog.close(); // Close the text file
return originalSend(s, buf, len, flags); // Send the buffer to the original send function
}
int WINAPI newRecv(SOCKET s, char* buf, int len, int flags) // Dumps each buffer to a new line in the "recv.txt" file in the games directory
{
len = originalRecv(s, buf, len, flags); // Send the request with a pointer to the buffer for recv to store the response
recvLog.open("recv.txt", std::ios::app); // Opens a handle to the recv file
for (int i = 0; i < len; i++) // For each byte in the response:
{
recvLog << std::hex << std::setfill('0') << std::setw(2) << (unsigned int)buf[i] << " "; // Log the hex of the byte with a width of 2 (leading 0 added if necessary) and a space after to separate bytes
}
recvLog << std::endl; // Add a newline to the text file, indicating the end of this request
recvLog.close(); // Close the text file
return len; // Returns the output from the original recv call
}
void hook() // Basic detours
{
DisableThreadLibraryCalls(hModule);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)originalSend, newSend);
DetourAttach(&(PVOID&)originalRecv, newRecv);
DetourTransactionCommit();
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD Reason, LPVOID reserved)
{
switch (Reason)
{
case DLL_PROCESS_ATTACH:
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)hook, NULL, 0, NULL);
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Purtroppo è uno dei miei primi progetti in C++ e quasi sicuramente avrò sbagliato qualcosa, allego anche la lista degli errori che il compilatore mi da:
Il problema fondamentale, è che l'IDE non mostra alcun segno rosso se tento di cliccare sull'errore, "come se in verità la sintassi fosse corretta, ma fosse sbagliata la semantica", allego un esempio: