Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 18:33

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C++ Hooking ws2_32.dll send recv

Discussion on C++ Hooking ws2_32.dll send recv within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Nov 2010
Posts: 2
Received Thanks: 0
C++ Hooking ws2_32.dll send recv

Hi guys,

I am trying to learn hooking and want to hook only an .exe's send/recv function.

I'm building the project as a .dll and then injecting it to the .exe

Now my problem is I am stuck.

I am able to successfully find the address for recv function, next I would like to see the packets that's being received..

A little guide pls on what to do next..
This is my .cpp
Code:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "dll.h"

#include <Winsock.h>
#pragma warning(disable:4996)
#pragma comment (lib,"ws2_32.lib")

typedef int(*WINAPI oldsend)(SOCKET s, const char* buf, int len, int flags);



void Proc_Attach()
{
	DWORD dwProtect;
	HINSTANCE hLib = LoadLibrary(L"WS2_32.dll");
	DWORD OldFuncAddr = (DWORD)GetProcAddress(hLib, "recv");
	WCHAR szTest[100]; // WCHAR is the same as wchar_t
					  // swprintf_s is the same as sprintf_s for wide characters
	swprintf_s(szTest, 100, L"%d", OldFuncAddr); // use L"" prefix for wide chars
	MessageBox(0, szTest, L"A", MB_ICONINFORMATION);
	//MessageBox(0, L" Process Attached!\n", L"Hi", MB_ICONINFORMATION);
}



BOOL APIENTRY DllMain(HINSTANCE hInst     /* Library instance handle. */,
	DWORD reason        /* Reason this function is being called. */,
	LPVOID reserved     /* Not used. */)
{
	switch (reason)
	{
	case DLL_PROCESS_ATTACH:
		
		Proc_Attach();
		
		break;

	case DLL_PROCESS_DETACH:
	
		break;

	case DLL_THREAD_ATTACH:
	
		break;

	case DLL_THREAD_DETACH:
		
		break;
	}

	
	return TRUE;
}
header file
Code:
#pragma once
#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


DLLIMPORT void Proc_Attach(void);



#endif /* _DLL_H_ */
Speaker1337 is offline  
Old 07/27/2017, 11:38   #2

 
elite*gold: 64
Join Date: May 2011
Posts: 1,229
Received Thanks: 854
Wow^^ You've done so much already.
I never could do that...
You didn't even firgure out, how to hook?
I think you should really google a bit.
It's not that difficult to find a hook function.
And when you hooked it, it is very easy to get the packet out of the buffer.

(Look under: C++ how to detour)
BladeTiger12 is offline  
Thanks
2 Users
Old 07/27/2017, 11:41   #3
 
elite*gold: 0
Join Date: Apr 2011
Posts: 42
Received Thanks: 13
What about ?
XnovaFR is offline  
Old 09/05/2017, 03:30   #4
 
Ustonovic's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 89
Received Thanks: 48
Why do you load the winsock library when your target needs it anyway?
Ustonovic is offline  
Old 09/10/2017, 07:55   #5
 
atom0s's Avatar
 
elite*gold: 0
Join Date: May 2013
Posts: 175
Received Thanks: 125
Quote:
Originally Posted by Ustonovic View Post
Why do you load the winsock library when your target needs it anyway?
If the target late-loads the library and your DLL is injected before the target has loaded it, it won't be present. Using LoadLibrary on something that is already loaded will just return the current module handle. It is no different than calling GetModuleHandle at that point.
atom0s is offline  
Old 10/07/2017, 23:29   #6
 
elite*gold: 0
Join Date: Feb 2009
Posts: 542
Received Thanks: 112
u can do an easy IAT Hook.
1. write a function which has the same signature, analyzes the buffer and calls the orginal function at return.
2. overwrite the orignal adress of recv in iat table with ur new function adress
3. sucess
maxi39 is offline  
Reply


Similar Threads Similar Threads
Hooking recv
02/20/2013 - Kal Online - 15 Replies
I have a question about that ;) I'm trying to EAT Hook recv function after injecting dll into engine.exe. The trick is that i don't really know if kal is using GetProcAddress to retrieve recv address on every call. I suppose it does because if we try simple jmp patch on it. It works for a short time after hs patches it. My hook is also working i guess but, well i don't really know why it is not showing data ;) I found in EAT of ws2_32.dll address: recv 0x74B80DA8 and it is const....
[Help]recv midfunction hooking
07/17/2012 - C/C++ - 15 Replies
Hey, ich versuche die Funktion recv zu hooken ohne das der hook entdeckt wird. Kurzsichtig wie ich bin hab ich bei send nen midfunction hook gemacht nur bei recv muss sich der buffer ja erstmal füllen also kann ich erst fast am ende der Funktion hooken. Das hab ich auch probiert nur irgendwie funktioniert das nicht. recv ollydbg CPU Disasm Address Hex dump Command Comments 76AA47DF /$ 8BFF MOV EDI,EDI 76AA47E1 |. 55 ...
C# GetProcAddress WS2_32.dll connect
09/17/2011 - SRO Coding Corner - 3 Replies
Hello Guys, I have a problem, if i create my projekt with that: uint WS2Connect = GetProcAddress(GetModuleHandle("WS2_32.dll&qu ot;), "connect"); The address is 0x00000000, but if i start debugmodus in the C# Compiler im getting the right address. With this:
[C++]ws2_32.dll compilation help
06/10/2009 - C/C++ - 3 Replies
im trying to compile a .DLL for hacking an online game. currently making something like a pocket sender.. anyways, someone told me to use this code.. i've tried to edit it a little. and tried to compile it.. but got errors.. i hope you can help me fix it.. thanks.. #include <Winsock2.h>
[Question] Hooking send() & recv() works, but recv hiding data for co???
05/06/2009 - CO2 Programming - 2 Replies
Hey guys, I've been making a DLL to allow another program to intercept the packets of conquer using windows pipes. (Then its the job of the main program to decrypt the packets, the DLL only gives a communication channel for the main program) (winsock functions btw) - hooking send() works fine for my internet browser - hooking recv() works fine for my internet browser - hooking send() works fine for conquer online



All times are GMT +1. The time now is 18:35.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.