Feasability of Protocol Filtering
Hi there,
Quoted 5 lines · Matt Skidmore
I have gained some interest in adding a new module to the netfilter code for filtering by protocol. However, I do not know how realistic this project would be. I have not found any projects similar to it as of yet. But, I would like to be able to REJECT, DENY, or REDIRECT packets based on the protocol of their connection.
i'm doing a quite similar thing at the moment: i'm developing a match that recognizes p2p traffic (kazaa, edonkey finished but more to come) by their protocol and mark them. After that i use a tc filter to read the marks and put the packets in QoS classes. What you need is something characteristic for every protocol. For example: every kazaa-download starts with a packet containing the string "GET /.hash=" - i do a string-match on each packet and if i find a match i just mark the whole connection with CONNMARK. By doing this i can treat every kazaa-download in the same way regardless of port or ip-adress. But i'm a little bit concerned about the required ressources. If you're going to use this match for many protocols and in a highly stressed environment you will need much ram and lots of cpu power. I'm going to test the behavior of my match in a couple of weeks for a 10MBit/sec environment - if someone is interessted i can send the results to the list or put it on a webpage.
I started doing some network sniffin' and if you can find something characteristic for the protocols you're going to match it should be easy to create an appropriate module. Hope my thoughts will help you a little bit.
Regards,
Eicke.
PS: if you receive this message twice - sorry! first time i used the wrong mailbox.
Quoted 7 lines
i'm doing a quite similar thing at the moment: i'm developing a match that recognizes p2p traffic (kazaa, edonkey finished but more to come) by their protocol and mark them. After that i use a tc filter to read the marks and put the packets in QoS classes. What you need is something characteristic for every protocol. For example: every kazaa-download starts with a packet containing the string "GET /.hash=" - i do a string-match on each packet and if i find a match i just mark the whole connection with CONNMARK.
thats about what im thinking. im going to use HTTP and SSH as examples because i know those protocols the best. and to keep it simple ill just say we wish to REJECT the packet. for HTTP the syn and acks might go through to establish the handshake, but you can examine the begining few packet contents to figure out that its trying to GET some url and then drop that packet and kindly reset the connection to be polite in this case. same with SSH, when the connection begins it usually says SSH with the version and some other tidbits that can be easily recognized. i would say build the basic protocol identification source file and then create the ability to choose which protocols you want to be able to recognize as to keep down bloat on a module.
I was heading to p2p programs myself. but this sort of feature would be nice to identify p2p stuff and perhaps reject or use QoS on them. once the connection has been established the data in the packets may not match the pattern for that protocol, but you could use connection tracking with dest/src ip and port to mark said packets.
the downside to this is, say you want to reject SSH traffic. you issue the command to reject it based on protocol. if there is a connection already in progress it probably wouldnt get it unless there are some telltale signs in the data packets, but since you can at least identify the initial connection packets you could at least stop additional connections.
I would be interested in seeing what you have so far. as for CPU and RAM concerns, I thought about this a bit myself. it could also intoduce latency as well.
-matt
Quoted 3 lines · Eicke Friedrich
I'm going to test the behavior of my match in a couple of weeks for a 10MBit/sec environment - if someone is interessted i can send the results to the list or put it on a webpage.
I do something similar here, no problem to do two stringmatches on a 100Mbit/s link.
I benchmarked the stringmatch a bit a while ago.
On my pIII it uses ~50k cycles / kB.
If using the Boyer-Moore algorithm instead you get it down to ~3k cycles / kB when searching for a 5 byte string (cpu usage decreases with string length)
The Boyer-Moore patch was sent to this list quite some time ago. I should update it so it applies.
Signature · 1 line
/Martin
Quoted 9 lines · Martin Josefsson
I benchmarked the stringmatch a bit a while ago.
On my pIII it uses ~50k cycles / kB.If using the Boyer-Moore algorithm instead you get it down to ~3k cycles / kB when searching for a 5 byte string (cpu usage decreases with string length)
The Boyer-Moore patch was sent to this list quite some time ago. I should update it so it applies.
Would you do so? Let's try to collect the missed bits :-(
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
H-1525 Budapest 114, POB. 49, Hungary
Quoted 4 lines · Jozsef Kadlecsik
Quoted 2 lines
The Boyer-Moore patch was sent to this list quite some time ago. I should update it so it applies.
Would you do so? Let's try to collect the missed bits :-(
I'll see what I can do, it needs some cleanups.
There are tons of stuff missed, That reminds me, I once had a plan to go through my netfilter and netfilter-devel folders and shake out all missed patches. I'll see what I can do.
Signature · 1 line
/Martin
pre, pre, premangle?
Hiyas,
Is there any way to hook into incoming packets
such that you get it before any other investigative code (such as conn tracking), examine it, and mangle it before letting them work on the packet?
-Scott
__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com
Re: pre, pre, premangle?
Quoted 5 lines · Scott MacKay
Hiyas,
Is there any way to hook into incoming packets
such that you get it before any other investigative code (such as conn tracking), examine it, and mangle it before letting them work on the packet?
./runme --batch pending
./runme userspace/raw.patch
iptables -t raw -A PREROUTING yada yada
Many of the targets that mangle packets have checks for which table they are beeing added too and refuse to be added to other tables than mangle. So to be able to use them in the raw table you will have to modify them a bit. The raw table is mostly used for DROP-ing, NOTRACK-ing and TRACE-ing packets.
userspace/raw.patch tries to patch the userspace iptables as well.
Signature · 1 line
/Martin
Re: pre, pre, premangle?
Actually, my goal is to mangle packet contents before conn track gets its hands on it. I currently do some packet mangling as part of a PREROUTING userspace queue (QUEUE), but I think my mangling is occuring after conn track has already looked at the contents (actually the problem is that the packet comes in 'mangled' and my stuff demangles it. I think conn track is building its assumptions on the mangled packet contents).
Using this patch as a base, do you believe I could add in QUEUE as a target? If so, is there any way to identify which table a userspace module is getting the packet from? I see ipq_packet_msg has a hook field, but never saw any apps use it. Since I still need to do processing at the mangle PREROUTING (or INPUT & FORWARD) stages and there can be only 1 QUEUE target, I would probably need to differentiate between a raw and mangle table...Thanks for the info so far tho!
-Scott
Quoted 24 lines · --- Martin Josefsson
Quoted 3 lines · Scott MacKay
Hiyas,
Is there any way to hook into incoming packets
such that you get it before any otherinvestigative
Quoted 1 line
code (such as conn tracking), examine it, and
mangle
Quoted 1 line
it before letting them work on the packet?
./runme --batch pending
./runmeuserspace/raw.patchiptables -t raw -A PREROUTING yada yada
Many of the targets that mangle packets have checks for which table they
are beeing added too and refuse to be added to other tables than mangle.
So to be able to use them in the raw table you will have to modify them
a bit. The raw table is mostly used for DROP-ing, NOTRACK-ing and
TRACE-ing packets.
Quoted 5 lines
userspace/raw.patchtries to patch the userspace
iptables as well.Signature · 1 line
/Martin
__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com
Quoted 2 lines · Martin Josefsson
I do something similar here, no problem to do two stringmatches on a 100Mbit/s link.
What about throughput, packets per second and latency? Do you have any experiences? I'm going to face a 100MBit/sec link in a couple of months so any hints are appreciated. By the way it's a Linux Bridge with netfilter support that has nothing else to do than marking p2p-packets and put them in a HTB class to reduce the "wasted" bandwidth.
Quoted 3 lines
If using the Boyer-Moore algorithm instead you get it down to ~3k cycles / kB when searching for a 5 byte string (cpu usage decreases with string length)
Maybe it's not so important for my project because i know the exact position in the payload where the string has to be so i don't search the whole packet but just the specific position in the payload. For this purpose i use memcmp(kazaa) or memchr(edonkey) - maybe there is a way to improve this?
intsearch_kazaa (char *needle, char *haystack, int needle_len)
{
char *t = haystack;
t += 20; //skippin tcp-header
if (memcmp(t, needle, needle_len) == 0)
return 1;
else
return 0;}
This is the one for kazaa where needle is the string "GET /.hash=" and haystack is the ip-packet. Next one is similar but i'm just searching for 0xe3 and 0x47 (edonkey get segment command).
intsearch_edk (char *haystack)
{
char *t = haystack;
t += 20; //skippin tcp-header
if (memchr(t, 0xe3, 1) == 0)
return 0;
else
t += 5; //jump to command position
if (memchr(t, 0x47, 1) != 0) return 1;
else return 0;}
Best regards,
Eicke.
Quoted 10 lines · Eicke Friedrich
i'm doing a quite similar thing at the moment: i'm developing a match that recognizes p2p traffic (kazaa, edonkey finished but more to come) by their protocol and mark them. After that i use a tc filter to read the marks and put the packets in QoS classes. What you need is something characteristic for every protocol. For example: every kazaa-download starts with a packet containing the string "GET /.hash=" - i do a string-match on each packet and if i find a match i just mark the whole connection with CONNMARK. By doing this i can treat every kazaa-download in the same way regardless of port or ip-adress. But i'm a little bit concerned about the required ressources. If you're going to use this match for many protocols and in a highly stressed environment you will need much ram and lots of cpu power. I'm going to test the behavior of my match in a couple of weeks for a 10MBit/sec environment - if someone is interessted i can send the results to the list or put it on a webpage.
I started doing some network sniffin' and if you can find something characteristic for the protocols you're going to match it should be easy to create an appropriate module. Hope my thoughts will help you a little bit.Regards,
Eicke.PS: if you receive this message twice - sorry! first time i used the wrong mailbox.
Hi there,
Hi have something similiar to that, and running for a couple of months on a 15MB/s network connection. Almost no performance impact noted.
http://mega.ist.utl.pt/~filipe/ipt_p2p/
It is still very primitive and easily forgeable, but it is efficient. Fell free to work on top of these code.
It detects kazaa, edonkey, gnutella and direct connect.
Since I'm not doing statefull filtering on the whole connection, it is possible to subvert these type of filters, but I am working on a work around.
Filipe Almeida
Quoted 3 lines
Quoted 1 line · Filipe Almeida
Hi have something similiar to that, and running for a couple of months on a 15MB/s network connection. Almost no performance impact noted.
What hardware is doing this job? Any tweaks (Kernel patches, NAPI ...) installed? Is it a router (NAT) or a bridge?
Quoted 1 line
Can't reach the url with my DSL-connection but with a 100MBit-connection everything is fine - maybe one of those internet black holes or whatever they're called?
I'm not sure if the developer list is the right place for such a discussion but if not please answer directly to my mail adress (and start flaming me ;-]).
Thanks for your help,
Eicke.
Quoted 5 lines · Matt Skidmore
the downside to this is, say you want to reject SSH traffic. you
issue the command to reject it based on protocol. if there is a
connection already in progress it probably wouldnt get it unless
there are some telltale signs in the data packets, but since you can at least identify the initial connection packets you could at least stop additional connections.
Yes, you are absolute right. But i don't see a way to change this. For p2p the already
established connections are not worth any effort. At some point the file is completly
transfered (kazaa) or the transfered segment has to be acknowlegded (edk). My match will
find this ack and treat the following packets as p2p-traffic.
Quoted 3 lines
I would be interested in seeing what you have so far. as for CPU and RAM concerns, I thought about this a bit myself. it could also intoduce latency as well.
I can send you the source-code if you want to.
Regards,
Eicke.
ipq_packet_msg, hook?
In reply to Martin JosefssonHello,
How exactly do you get anything useful from the libipq's ipq_packet_msg structure field 'hook'? Can anyone point me to which APIs translate that to something useful?
-Scott
__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com