Raised This Month: $51 Target: $400
 12% 

Hooking socket recv


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 04-01-2014 , 22:45   Hooking socket recv
Reply With Quote #1

Arkshine hooked socket sendto on his bot played time faker... how could I do the same with socket recv? I tried but I couldn't.
__________________

Last edited by Neeeeeeeeeel.-; 04-03-2014 at 12:24.
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 04-02-2014 , 01:22   Re: Hooking socket recv
Reply With Quote #2

I hooked recvfrom using sendto hook from Arkshine as a guide.

I looked at the params here http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

Then I made my hook:
PHP Code:
size_t PASCAL OnNewRecv(int socketvoidmessagesize_t lengthint flagsstruct sockaddrdest_addrsocklen_t dest_len){
    
unsigned charmsg = (unsigned char*)malloc(length);
    
charip inet_ntoa(((struct sockaddr_in *)dest_addr)->sin_addr);
    
memcpy(msgmessagelength);
    
size_t ret 0;
    
printf("%s:%d - %s\n"ip, ((struct sockaddr_in *)dest_addr)->sin_portmsg);
    if(
RecvHook->Restore()){
        
ret RecvOriginal(socketmessagelengthflagsdest_addrdest_len);
        
RecvHook->Patch();
    }
    return 
ret;

The problem is that I cannot get the IP address properly.

I found that inet_ntoa returns IP address, but it needs IN_ADDR type param. So I casted sockaddr to sockaddr_in to get IN_ADDR value.
PHP Code:
charip inet_ntoa(((struct sockaddr_in *)dest_addr)->sin_addr); 
BUUUUUT this was the result:


I'm testing on a dedicated server so I should see 127.0.0.1 as my address...
As you can see on getchallange packet, my ip seems to be 136.115.171.4 which is impossible...

I also tried sending a test packet with a simple python script...


So the packet arrived but my ip seems to be 0.0.0.0
Port is wrong too.

What am I doing wrong?
__________________

Last edited by Neeeeeeeeeel.-; 04-03-2014 at 12:41.
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 04-02-2014 , 05:09   Re: Hooking socket recv
Reply With Quote #3

what do you want ?
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 04-02-2014 , 05:14   Re: Hooking socket recv
Reply With Quote #4

Quote:
Originally Posted by K.K.Lv View Post
what do you want ?
I want to get my ip at recvfrom hook.

I tried the same code in sendto hook and it works like a charm so the fact that doesn't work in recvfrom is breaking my mind.
__________________

Last edited by Neeeeeeeeeel.-; 04-03-2014 at 12:24.
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
Old 04-03-2014, 12:57
Destro-
This message has been deleted by Destro-. Reason: asd
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 04-06-2014 , 16:46   Re: Hooking socket recv
Reply With Quote #5

Update:

I have new info about my issue...

I changed the way I get IP address.
PHP Code:
char host[18];
char port[10];
getnameinfo(dest_addrdest_lenhostsizeof(host), portsizeof(port), NI_NUMERICHOST);
printf("IP: %s - Port: %s"hostport); 
Now I got:
Code:
IP: 0.0.0.0 - Port: 26002
Port is right...

Ok, if I delete NI_NUMERICHOST flag from getnameinfo I get "Nelson" as address. "Nelson" is my computer name so i'm assuming dest_addr in recvfrom is receiving my addresses as source.

http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
Following msdn, I should have source public IP.... I don't know why I'm receiving my own local IP...
__________________
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 04-06-2014 , 20:46   Re: Hooking socket recv
Reply With Quote #6

If you're behind nat device you can't
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 04-06-2014 , 20:52   Re: Hooking socket recv
Reply With Quote #7

Quote:
Originally Posted by joropito View Post
If you're behind nat device you can't
So if I put my gameserver in the cloud would work, wouldn't it?
__________________
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 04-06-2014 , 20:54   Re: Hooking socket recv
Reply With Quote #8

Yes, with poor performance.
Hooking recvfrom is not recommended for a game server
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 04-10-2014 , 21:43   Re: Hooking socket recv
Reply With Quote #9

Did you want to do something like server query ? then you can this one with the mod function
Code:
#define FN_ConnectionlessPacket  ConnectionlessPacket  /* pfnConnectionlessPacket() (wd) SDK2 */
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 04-11-2014 , 10:36   Re: Hooking socket recv
Reply With Quote #10

Quote:
Originally Posted by K.K.Lv View Post
Did you want to do something like server query ? then you can this one with the mod function
Code:
#define FN_ConnectionlessPacket  ConnectionlessPacket  /* pfnConnectionlessPacket() (wd) SDK2 */
That's only called if:

1- is not a HL game protocol packet
2- is not a "rcon" request packet
3- is not a "log" request packet
4- is not a "pstat" request packet
5- is not a "connect" request packet
6- is not a "challenge" request packet
7- is not a "getchallenge" request packet
8- is not a server query packet

Also it's handled after steamclient packet handling (authentication, voice processing, etc).

He only want to know the ip address where the game binds it's service.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode