Long time no see :). Some of you may have wondered or not, where I disappeared, I’m going to tell you anyway.
I’ve been writing my bachelor thesis and now I’m finally finished :). And I actually developed something useful, or at least, I think it’s useful.
My thesis’ subject is: Design and Prototypic Implementation of a Rule–Generator for Packetfilter–Firewalls with Integrated Detection of Malicious Traffic.
It’s in German, so most of you can’t read it, which you probably wouldn’t want anyway. So I’m going to tell what’s in it.
With your standard personal firewall you have a mechanism, which presents you potential rules, based on connections programs want to establish. This may be unnerving on a windows machine with windows popping up every 5 minutes, but the principle is kind of useful.
What I wanted to do was: Port this mechanism to packetfilter-firewalls. And I did it, it’s not exactly the same, but more or less similar.
I wrote a python program, which can read a traffic dump in pcap format and combines the traffic to rules. The rules can be printed out in pf- and netfilter-syntax. If you wonder: pf is the OpenBSD packetfilter.
Since that was not enough for a bachelor thesis, I also implemented simple portscan and ddos detection algorithms and a mechanism to filter out unwanted rules before printing out the ruleset.
It’s only a prototype and it has problems with traffic-dense dumps (it consumes all your memory and never comes to an end :( ). But all in all it works kind of good, at least in my tests :).
So, you may ask, can I test this rulegenerator-thingy? Yes, you can :D.
I put it on github [1]. You have to have dpkt [2] installed, a “python packet creation / parsing library”, which is used to read the dumps. Don’t forget to read the README :).
And, so you can see how it works right now, I included some examples here. I used the output in pf-syntax, because it’s more compact.
- rulegeneration with normal dump
Reading pcap file
Checking for DDoS
Filtering Rules with existing ruleset
Detecting PortscansGenerating TCP-Ruleset
Generating UDP-Ruleset
Generating ICMP-Ruleset1 rule for protocol tcp from 4 tcp connection(s)
pass none-outer proto tcp from 192.168.1.1 port random to 192.168.1.2 port { 21, 22, 23, 80 }5 rules for protocol udp from 12 udp connections
pass none-outer proto udp from 192.168.1.2 port 513 to 192.168.1.255 port 513
pass none-outer proto udp from 192.168.1.1 port 53 to 192.168.1.2
pass none-outer proto udp from 192.168.1.2 port 138 to 192.168.1.255 port 138
pass none-outer proto udp from 192.168.1.2 port random to 192.168.1.1 port 53
pass none-outer proto udp from 192.168.1.0/24 port 137 to 192.168.1.255 port 137No connections for protocol icmp
- rulegeneration with dump containing a portscan
Reading pcap file
Checking for DDoS
Detecting Portscans
Detecting infected hostsGenerating TCP-Ruleset
Generating UDP-Ruleset
Generating ICMP-RulesetNo connections for protocol tcp
1 rule for protocol udp from 1 udp connection(s)
pass none-outer proto udp from 192.168.2.105 port random to 224.0.0.251 port 5353No connections for protocol icmp
1 rule which results from traffic which looks like a portscan
1000 ports were scanned in range: 1:65389
block none-outer proto tcp from 192.168.2.101 port random to 192.168.2.105
1 IP(s) scanned: 1 IP(s)
192.168.2.101 scanned 192.168.2.105 - rulegeneration with dump containing a ddos-attack
Reading pcap file
Checking for DDoS
There might be an tcp (D)DoS Attack. The weighted moving average is 5.41770376331, which is below the given border 400.
Detecting PortscansGenerating TCP-Ruleset
Generating UDP-Ruleset
Generating ICMP-Ruleset1 rule for protocol tcp from 4000 tcp connection(s)
pass in proto tcp from any port random to 10.0.0.1 port 22No connections for protocol udp
No connections for protocol icmp
The portscan detection mechanism is a simple “if there are more than x connection/connection-attemps from one host to another host/different ports or other hosts/one port or other hosts/different ports” test.
The ddos detection mechanism is a little bit more complicated. I took it from a paper on ddos-detection [3].I would be happy if the rulegenerator is of some use to someone out there. If you look at the code, remember it’s just a prototype. If you have suggestions or want to make the rulegenerator better, tell me. Maybe, with a little work, it can be more than just a prototype ;).
[1] https://github.com/constanze/rulegen
[2] http://code.google.com/p/dpkt/
[3] http://www.springerlink.com/content/k6436394vn52275h/