l7-filter是一个定义在应用层上的来过滤数据包的。
它可以按照不同的应用进行过滤,比如过滤聊天工具
QQ、MSN、eDonkey等应用
详细信息可以查看http://l7-filter.sourceforge.net/
接下来讲述l7-filter的编译安装和使用:
内核:linux-2.6.28.10.tar.gz
l7协议:l7-protocols-2009-05-28.tar.gz
l7过滤包:netfilter-layer7-v2.22.tar.gz
# tar zxvf linux-2.6.28.10.tar.gz -C /usr/src
# tar zxvf netfilter-layer7-v2.22.tar.gz -C /usr/src
# ln –s /usr/src/linux-2.6.28.10/ /usr/src/linux
# cd /usr/src/linux/
# patch -p1 < ../netfilter-layer7-v2.22/kernel-2.6.25-2.6.28-layer7-2.22.patch
# cp /boot/config-2.6.18-164.el5 /usr/src/linux/.config
# make menuconfig
如图所示:
找到这个位置Networking support → Networking Options →
Network packet filtering framework →Code Netfilter Configuration
,选中以下几个模块:
<M> Netfilter connection tracking support
<M> “layer7” match support
<M> “string” match support
<M> “time” match support
<M> “iprange” match support
<M> “connlimit” match support
<M> “state” match support
<M> “conntrack” connection match support
<M> “mac” address match support
<M> "multiport" Multiple port match support
然后在Networking support → Networking Options →
Network packet filtering framework → IP: Netfilter Configuration下
选择如下几个模块:
<M>IPv4 connection tracking support (required for NAT)
<M>Full NAT
<M>MASQUERADE target support
<M>NETMAP target support
<M>REDIRECT target support
当然可以根据自己的需要,进行定制自己的内核。
内核定制完成之后就可以进入编辑的阶段了
# make
# make modules_install
# make install
然后打开/boot/grub/grub.conf 把默认的启动项设置为新内核
重新启动系统
# cp /etc/init.d/iptables ~/iptables 备份iptables脚本,方便后面应用
# cp /etc/sysconfig/iptables-config . 备份iptables的配置文件
# rpm -e iptables-ipv6 iptables iptstate --nodeps
# tar jxvf iptables-1.4.6.tar.bz2 –C /usr/src
# cd /usr/src/iptables-1.4.6
# cp ../netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel \
-2.6.20forward/libxt_layer7.* ./extensions/
# ./configure --prefix=/usr --with-ksource=/usr/src/linux
# make
# make install
编译完成
# tar zxvf l7-protocols-2009-05-28.tar.gz
# cd l7-protocols-2009-05-28
# make install
# vim ~/iptables
修改内容
:%s#/sbin/$IPTABLES#/usr/sbin/$IPTABLES#g 全局替换内容
# mv ~/iptables /etc/rc.d/init.d/
# service iptables start
这样整个环境的设置就算是完成,接下来就是应用了。
#iptables -A FORWARD -p tcp -s 192.168.1.12 -d 192.168.1.13 -o eth0 -j DROP(禁止IP)
#iptables -A FORWARD -p tcp -s 192.168.1.11/24 -d www.qq.com -o eth0 -j DROP(禁止网段)
#iptables -A INPUT -p tcp –-dport 1:1024 -j DROP
#iptables -A INPUT -p udp –-dport 1:1024 -j DROP 这两条可以防止nmap探测
防止同步包洪水(Sync Flood)
# iptables -A FORWARD -p tcp –-syn -m limit –-limit 1/s -j ACCEPT
也可以写作
#iptables -A INPUT -p tcp –-syn -m limit –-limit 1/s -j ACCEPT
–-limit 1/s 限制syn并发数每秒1次,可以根据自己的需要修改
防止各种端口扫描
# iptables -A FORWARD -p tcp –-tcp-flags SYN,ACK,FIN,RST RST -m limit –-limit 1/s -j ACCEPT
Ping洪水攻击(Ping of Death)
# iptables -A FORWARD -p icmp –-icmp-type echo-request -m limit –-limit 1/s -j ACCEPT
# Null Scan(possibly)XiKc.om
iptables -A INPUT -i eth0 -p tcp –-tcp-flags ALL NONE -j DROP
#iptables -t nat -A PREROUTING -p tcp --dport 80 -d $INTERNET_ADDR -j DNAT –-to-destination 192.168.100.2
#iptables -A Filter -d www.3322.org -j ACCEPT
#iptables -A Filter -d img.cn99.com -j ACCEPT
#iptables -A Filter -p tcp -m multiport –-source-port 22,53,80,110 -s 192.168.20.3 -j REJECT
#iptables -A Filter -p tcp –source-port 2:80 -s 192.168.20.3 -j REJECT
#iptables -A Filter -s 10.10.10.253 -m time –-timestart 6:00 –-timestop 11:00 –-days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j DROP
#iptables -A Filter -m time –-timestart 12:00 –-timestop 13:00 –-days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT
#iptables -A Filter -m time –-timestart 17:30 –-timestop 8:30 –-days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT
#iptables -I Filter -m mac –-mac-source 00:0A:EB:97:79:A1 -j DROP
#iptables -I Filter -m mac -–mac-source 00:0A:EB:97:79:A1 -p tcp --dport 25 -j ACCEPT
#iptables -I Filter -m mac –-mac-source 00:0A:EB:97:79:A1 -p tcp --dport 110 -j ACCEPT