How to test your Linux-Distro FIREWALL !
Recently, I wrote an article about How to scan your Linux-Distro for Root Kits.
Now that the machine is... clean! I think, a good thing TO-DO, is to test my Firewall (AGAIN !!!)
The good news are that we can use the free tool FTester.
The bad news are that FTester needs to be configured right...
So... Let's get to work !
The tool consists of two perl scripts, a packet injector (ftest) and the listening sniffer (ftestd).
The first script injects custom packets, defined in ftest.conf, with a signature in the data part while the sniffer listens for such marked packets.
The scripts both write a log file which is in the same form for both scripts.
A diff of the two produced files (ftest.log and ftestd.log) shows the packets that were unable to reach the sniffer due to filtering rules if these two scripts are ran on hosts placed on two different sides of a firewall.
Stateful inspection firewalls are handled with the 'connection spoofing' option.
A script called freport is also available for automatically parse the log files.
The IDS (Intrusion Detection System) testing feature can be used either with ftest only or with the additional support of ftestd for handling stateful inspection IDS, ftest can also use common IDS evasion techniques.
Instead of using the configuration syntax currently the script can also process snort rule definition file.
- firewall testing
- IDS testing
- simulation of real tcp connections for stateful inspection firewalls and IDS
- connection spoofing
- IP fragmentation / TCP segmentation
- IDS evasion techniques
The following perl modules are required: Net::RawIP, Net::PcapUtils, NetPacket
So... we will need the Net::RawIP , Net::PcapUtils, and NetPacket Perl modules. We may also need the Net::Pcap module if it is not already installed, because the Net::PcapUtils module depends on it.
If we have the CPAN Perl module, we may install these modules with the following commands from shell:
# perl -MCPAN -e "install Net::RawIP"
# perl -MCPAN -e "install Net::Pcap"
# perl -MCPAN -e "install Net::PcapUtils"
# perl -MCPAN -e "install NetPacket"
... and we are done with the perl modules.
The most recent release is ftester-1.0.tar.gz (2006-Feb-13). From shell run...
<br /># wget http://dev.inversepath.com/ftester/ftester-1.0.tar.gz<br />
All releases at available at http://dev.inversepath.com/ftester.
Use tar to... unzip the source code. From shell run...
<br /># tar -xzf ftester-1.0.tar.gz<br />
We have installed a few perl modules required, we have downloaded ftester-1.0.tar.gz (2006-Feb-13) and we have extracted the file and made the directory ftester-1.0.
Well done !!!
We will need to create a configuration file to tell ftest what packets it should generate.
The definition of the packets we want to send for test if they can traverse the firewall is mainly specified in a configuration file (ftest.conf), the main syntax is:
<br />Source Address:Source Port:Destination Address:Destination Port:Flags:Protocol:Type of Service<br />
for TCP and UDP packets,
<br />Source Address:Source Port:Destination Address:Destination Port:Flags:ICMP:icmp_type:icmp_code<br />
for ICMP packets.
a few examples:
<br /># SYN packet to 10.1.7.1 port 80 <br />192.168.0.10:1024:10.1.7.1:80:S:TCP:0<br /># PSH,ACK reply from 192.168.0.10<br />192.168.0.10:20:10.1.7.1:1022:AP:TCP:22<br /># UDP packet<br />192.168.0.10:53:10.1.7.1:53::UDP:0<br /># ICMP packet type 3 code 5<br />192.168.0.10::10.1.7.1:::ICMP:3:5<br /># ranges are allowed for source address, source port, destination port<br /># source address can also be specified in CIDR form<br />192.168.0.1-255:1024:10.1.7.1:22:S:TCP:0<br />192.168.0.1:1024:10.1.7.1:1-65535:S:TCP:0<br />192.168.0.1:1-1024:10.7.0.1:20-25:S:TCP:22<br />192.168.3.0/24:1-1024:10.7.0.1:20-25:S:TCP:0<br />192.168.0.0/22:1024:10.7.0.1:80:S:TCP:0<br />
A stop signal is necessary for telling ftestd that our test is completed, so use the following syntax:
<br />stop_signal=192.168.0.1:666:10.1.7.1:666:S:TCP:<br />
the stop_signal can be a TCP, UDP or ICMP packet, this packet will cause the termination of the sniffer so every packet specified after the stop_signal directive wont be seen by ftestd.
Now from shell...
<br /># vi ftest.conf<br />
You will see a lot of stuff in there... Just comment anything you don't need !!! I used...
<br /># checking privileged ports (<1025)<br />192.168.0.10:1025:10.1.7.1:1-1025:S:TCP:0<br /># checking proxy port<br />192.168.0.10:1025:10.1.7.1:3128:S:TCP:0<br />stop_signal=192.168.0.10:80:10.1.7.1:1025:AP:TCP:0<br />
Before starting ftest, we should be root and then start ftestd, from shell:
<br /># ./ftestd -i eth0<br />
Run ftest from shell:
<br /># ./ftest -f ftest.conf<br />
Finally we copy the two log files on the same host and we compare them using freport from shell:
<br /># ./freport ftest.log ftestd.log<br />
You will see something like...
<br />Authorized packets:<br />-------------------------------<br />21 - 192.168.0.10:1025 > 10.1.7.1:21 S TCP 0<br />22 - 192.168.0.10:1025 > 10.1.7.1:22 S TCP 0<br />23 - 192.168.0.10:1025 > 10.1.7.1:23 S TCP 0<br />25 - 192.168.0.10:1025 > 10.1.7.1:25 S TCP 0<br />80 - 192.168.0.10:1025 > 10.1.7.1:80 S TCP 0<br />110 - 192.168.0.10:1025 >