PDA

View Full Version : UDPCap Extension


Naydef
12-01-2017, 16:39
UDPCap extension
Version: 0.0.0.1

Description:
Allows plugin developers to catch UDP packets sent to the server with the ability of getting IP, port, length of data, data itself, etc. Also plugins can selectively prevent futher processing of the packets or vice versa. Please notice that the extension is currently only for the Windows OS, although it contains the required gamedata for Linux OSes.

Changelog:


Version 0.0.0.1

First release
Probability of bugs
Only for Windows OS currently




Sample plugin:

The plugin prints the ip address and the country of origin of all TSource Engine Queries

#include <sourcemod>
#include <udpcap>
#include <geoip>
#pragma newdecls required

public Plugin myinfo =
{
name = "UDPCap Example Plugin / Source Query Country Logger",
author = "Naydef",
description = "Example",
version = "0.1",
};

public Action UDPC_ProcessIncomingPacket(const char[] ip, int port, const char[] data, int length, netadrtype_t netaddrtype)
{
if(netaddrtype==NA_IP && length>5 && data[4]=='T')
{
char countryname[64];
if(GeoipCountry(ip, countryname, sizeof(countryname)))
{
PrintToServer("Query from IP %s:%i, located in %s", ip, port, countryname);
}
}
return Plugin_Continue;
}



Compatibility:
The extension is tested and confirmed working on these games/OSes:

TF2/Windows Vista



Credit:
Zephyrus (https://forums.alliedmods.net/member.php?u=79786) - Copypasted some code from Console Cleaner extension at first, but then removed it.


Source Code:
https://github.com/naydef/UDPCap-ext


Bugs/Improvements:

None


Note:

You can only capture UDP packets received by the server, not possible to capture those sent by the server(If requested, might add such functionality)
Gamedata taken from TF2 engine.dll, so gamedata might not work on other Source games
This the first public extension I released.


Feedback is very welcomed!



Files:

Scruffy
02-24-2018, 04:40
Wow! This is fantastic! Can't wait to set this up on my server!

I can think of several use cases, but most of them require one of:

capturing the server's response
modifying the inbound packet
modifying the outbound packet


I'll see if I can use this to log voice chat to disk.

In the meantime, the features above and a linux .so binary would be useful.

I can confirm, it works like a charm for TF2 on Windows 10.

Again, thanks, this is fantastic extension!

Naydef
02-24-2018, 06:58
Wow! This is fantastic! Can't wait to set this up on my server!

I can think of several use cases, but most of them require one of:

capturing the server's response
modifying the inbound packet
modifying the outbound packet


I'll see if I can use this to log voice chat to disk.

In the meantime, the features above and a linux .so binary would be useful.

I can confirm, it works like a charm for TF2 on Windows 10.

Again, thanks, this is fantastic extension!
Thanks. About the suggestions:

Capturing server response - probably will add such callback
modifying inbound packet - currently you can block packet from the client and use Socket extension to send packet with modified data
modifying the outbound packet - same as second

Probably for the Linux variant of the extension, the way i made extension makes it rather hard to compile on Linux. Probably when I have more time going to compile it.

Scruffy
02-24-2018, 15:30
modifying inbound packet - currently you can block packet from the client and use Socket extension to send packet with modified data



I don't doubt blocking the packet will work, but I don't think Socket ext is able to send a modified packet from the right source IP and port.

When sending a replacement packet from the client to the server, SrcDS will expect the source IP address to be consistent with that client's - some internet IP, whereas the actual source IP will be SrcDS' localhost. Given that SrcDS distinguishes clients by IP:port data in the packet, I expect the packet would be disregarded. Similarly, to send a modified outbound packet to a client, the socket ext will bind to some port other than SrcDS' port; as such, NAT or not, the client will ignore the packet since it came from the wrong port on albeit the right IP.

I'm not sure what implementation you had in mind when you said that Socket ext could be used to send the modified packet - please clarify.

hmmmmm
02-24-2018, 16:40
You could push length/data by reference and allow it to be changed plugin side to allow modifying the packets.

Scruffy
02-24-2018, 18:31
You could push length/data by reference and allow it to be changed plugin side to allow modifying the packets.

I doubt it would be as simple as that. That would make the changed data available to the extension, but the extension would still need to implement the functionality to resend an updated packet.

hmmmmm
02-24-2018, 19:32
All it is is a detour. After calling the forward, it then calls the original function with the same params (unless plugin returns Plugin_Handled or whatever). It would be easy to change the params passed in to the original function.

Scruffy
02-24-2018, 20:28
All it is is a detour. After calling the forward, it then calls the original function with the same params (unless plugin returns Plugin_Handled or whatever). It would be easy to change the params passed in to the original function.

You seem more qualified than I am. Perhaps you should submit a pull request

Dr.Mohammad
03-23-2018, 23:51
hi
not worked !!! please update !!

http://s8.picofile.com/file/8322372068/Captur333e.PNG

i used last sm v1.8 and used this version ext:
https://forums.alliedmods.net/attachment.php?attachmentid=166993&d=1512164184

Naydef
03-26-2018, 12:45
hi
not worked !!! please update !!

http://s8.picofile.com/file/8322372068/Captur333e.PNG

i used last sm v1.8 and used this version ext:
https://forums.alliedmods.net/attachment.php?attachmentid=166993&d=1512164184
Next time tell me the game you're trying to run the extension. I suppose it's CS:GO, anyway the extensions ships with only TF2 gamedata and general gamedata(based on TF2 one) for other games. I already have made CS:GO ProcessIncomingPacket function signature, but the function is trickier to hook compared to other games because it uses the _fastcall calling convention. Also I will have more time for the extension to improve the incoming week.

Dr.Mohammad
03-26-2018, 22:11
Next time tell me the game you're trying to run the extension. I suppose it's CS:GO, anyway the extensions ships with only TF2 gamedata and general gamedata(based on TF2 one) for other games. I already have made CS:GO ProcessIncomingPacket function signature, but the function is trickier to hook compared to other games because it uses the _fastcall calling convention. Also I will have more time for the extension to improve the incoming week.

i tested on csgo but dont work.

please fix for csgo.

thank you

iGANGNAM
04-19-2018, 05:05
does this have something to do with serverquery? I mean like can you modify packets of current players on server etc. What main usages of this extension?

Naydef
06-12-2018, 10:50
Guys, if you have interest in this extension, then help me compile a Linux version, since i'm stuck with the tutorials! Also i tried to add hook for send packet, but i can't compile for some reason.