KratosA How do I cheat?
Reputation: 0
Joined: 29 May 2015 Posts: 1
|
Posted: Fri May 29, 2015 11:48 am Post subject: Hooking Send , Recv Problem |
|
|
Ok i been playing around with some hooking again. I recently moved from studying php to c/c++ for several months now . so i decided to do something about Hooking looking up some facts from msdn and some other things on here .
I try to inject this DLL into Firefox, when i do, i do not see it open the hookFile.txt and save the buffer to the .txt file, am i getting something wrong ? my source code goes like this
Code: |
#include <windows.h>
#include <stdio.h>
void ApiHook(LPSTR Module,LPCSTR OldFunc,LPVOID NewFunc,unsigned char *backup);
extern "C" _declspec(dllexport) void newSend(SOCKET s, const char* buf, int len, int flags);
extern "C" _declspec(dllexport) void newRecv(SOCKET s, const char* buf, int len, int flags);
|
now the main.cpp looks like this
Code: |
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <Winsock.h>
#include "DLLHookSendRecv.h"
#pragma comment (lib,"ws2_32")
typedef int (*WINAPI oldsend)(SOCKET s,const char* buf,int len,int flags);
typedef int (*WINAPI oldrecv)(SOCKET s,const char* buf,int len,int flags);
BYTE hook[6];
void ApiHook(LPSTR Module,LPCSTR OldFunc,LPVOID NewFunc,unsigned char *backup)
{
DWORD dwProtect;
HINSTANCE hLib = LoadLibraryA(Module);
DWORD OldFuncAddr = (DWORD)GetProcAddress(hLib,OldFunc);
DWORD NewFuncAddr = (DWORD)NewFunc;
BYTE jmp[6] ={0xE9,0x00,0x00,0x00,0x00,0xC3};
DWORD jmpAddr = (NewFuncAddr - OldFuncAddr) -5;
memcpy(&jmp[1],&jmpAddr,4);
VirtualProtect((LPVOID) OldFuncAddr,6,PAGE_EXECUTE_READWRITE,&dwProtect);
WriteProcessMemory(GetCurrentProcess(),(LPVOID)OldFuncAddr,jmp,6,0);
VirtualProtect((LPVOID)OldFuncAddr,6,dwProtect,&dwProtect);
}
extern "C" _declspec(dllexport) void newSend(SOCKET s, const char* buf, int len, int flags)
{
FILE* logFile;
logFile = fopen("hookFile.txt","w");
fprintf(logFile,"%s",buf);
fclose(logFile);
return send(s,buf,len,flags);
}
extern "C" _declspec(dllexport) void newRecv(SOCKET s, const char* buf, int len, int flags)
{
FILE* logFile;
logFile = fopen("hookFile.txt","w");
fprintf(logFile,buf);
fclose(logFile);
return recv(s,buf,len,flags);
}
BOOL APIENTRY DllMain(HINSTANCE hInstDLL,DWORD ul_reason_for_call,LPVOID lpReserved)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
ApiHook("ws2_32.dll","send",newSend,hook);
ApiHook("ws2_32.dll","recv",newRecv,hook);
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
ApiHook("ws2_32.dll","send",newSend,hook);
ApiHook("ws2_32.dll","recv",newRecv,hook);
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
|
|
|