iptables系列之layer7
多张网卡IP,如果设置网关和转发功能,则该网卡连接到多个不同网段的主机。可通信不同网段的主机。 地址属于主机,不属于网卡。 内网:只要求公网,拒绝公网上任何主机的请求。利用网关防火墙转换源地址。 服务器:接受公网的请求,利用网关防火墙进行目的地址转换。 注:由于服务器在公共网络上接受任何主机的响应,安全性较低,因此将使用服务器作为跳板,然后控制内部网络主机,以达到窃取数据的目的。 可在网关防火墙上设置三张网卡,将内网主机与服务器隔离,即使服务器被击,内网主机也不受影响。
DMZ:非军事化区 三宿主主机 内网客户端<------------>网卡1 | ---|网卡3<------> 服务器<---------------->网卡2 DMZ 网关防火墙 内网 外网 背靠背模式: 内网客户端<----->网卡2:内防火墙:网卡1<-----------交换机--------->网卡2:外防火墙:网卡1<————————>公网 | \|/ 服务器
般通过ISA Server防火墙结构分为防火墙结构Edge Firewall(边缘防火墙),3-Leg Perimeter Firewall(3)Back-to-Back Perimeter Firewall(背对背外围防火墙)和四种单网络适配器(网卡)。 DNS view 内核编译: 2.6---->3.0 单核:模块化(文件系统,驱动,安全) 微内核: 编译内核: 配置 .config (/proc/cpuinfo,lsusb,lspci,hal-device) make menuconfig make gconfig make kconfig make config make oldconfig 编译 make 只编译部分源码 make SUBDIR=arch/ make drivers/net/pcnet32.ko make dir 转存编译结果 make o=/path/to/somdir 内核模块的安装 make modules_install 安装内核 make install make clean 清除以前的编译 make mrproper /boot busybox kernel = linux ulibc
iptables :二,三,四 string 过滤层次越高,资源消耗越多。 p2p,qq,msn netfilter:(补丁后)http,smtp, netfilter:框架,过滤是通过的rules /|\ iptables:语法正确。 注意:要对netfilter和iptables补丁,匹配。 uname -r layer7 -- l7 应用:xunlei, qq, netfilter<--patch -m layer7 --l7proto xunlei -j DROP 1.补丁内核,重新编译内核 2、给iptables源码补丁,并重新编译iptables 3、安装l7proto kernel, patch iptables, patch
Kernel Patch # tar zxvf linux-2.6.28.10.tar.gz -C /usr/src # tar zxvf netfilter-layer7-v2.22.tar.gz -C /usr/src # cd /usr/src # ln –s linux-2.6.28.10 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 →Core 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 Compiles iptables : # cp /etc/init.d/iptables ~/iptables # cp /etc/sysconfig/iptables-config ~/ # 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 # mv ~/iptables /etc/rc.d/init.d/ # service iptables start l7-filter uses the standard iptables extension syntax # iptables [specify table & chain] -m layer7 --l7proto [protocol name] -j [action] linux-2.6.18 iptables-1.4.6.tar.bz2 l7-protocols-2009-05-28.tar.gz netfilter-layer7-v2.22.tar.bz2 tar xvf linux-2.6.28.110.tzr.gz -C /usr/src tar xvf netfilter-layer7-v2.22 -C /usr/src cd /usr/src ln linux-2.6.28.10 linux cd linux patch -p1 < ../netfilter-layer7-v2.22 /kernel-2.6.25-2.6.28-layer7-2.22.patch cp /boot/config-2.6.18-308.el5 .config yum grouplst
make menuconfig
Networking support → Networking Options →Network packet filtering framework →Core Netfilter Configuration
make
make install_modules
make install
vim /etc/grub.conf
default=0
reboot
uname -r
ipt---->xt_
编译iptables
cp /etc/init.d/iptbales ~/
cp /etc/sysconfig/iptables-config ~/
cp /etc/sysconfig/iptables ~/iptables.rules
servcie iptables stop
chkconfig iptables off
rpm -e iptables-ipv6 iptables iptables --nedeps
cd /usr/src
tar xvf iptables-1.4.6.tar.gz
cd iptables
ls
cp ../netfilter-layer7-v2/iptables-1.1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.* ./extensions/
./configure --prefix=/usr --with-ksource=/usr/src/linux
make
mkae install
which iptables
cp ~
vim iptables
/usr/sbin/
cp iptables /etc/init.d/
chkconfig --add iptables
chkconfig iptables on
chkconfig --list iptables
cp iptables-config /etc/sysconfig/iptables
vim iptables.rules
cp iptables.rules /etc/sysconfig/iptables
service iptables start
lsmod
cd /usr/src
tar I7-protocols-2009-05-28.tar.gz
cd I7-protocols-2009-05-28
make install
service iptables restart
l7-filter使用语法:
iptables [specify tables & chain] -m layer7 --l7proto [protocol name] -j [action]
ls /etc/I7-protocols/protocols/
172.16.100.7
192.168.10.6
iptables -t nat -A POSTRUTING -s 192.168.10.0/24 -j SNAT --to-source 172.16.100.7
iptables -t filter -A FORWARD -s 192.168.10.0/24 -m layer7 --l7proto qq -j DROP
qq:udp
iptables
-m time
--datestart --datestop
--timestart --timestop
iptables -A FORWARD -s 192.168.10.0/24 -m tme --timestart 08:10:00 --timestop 12:00:00 -j DROP
iptables -A FORWARD -s 192.168.10.0/24 -m time --tmiestart 14:30:00 --timestop 18:20:00 -j DROP
service iptables save
iptables-save >/etc/sysconfig/iptables.tus
iptables-restore < /etc/sysconfig/iptables.tus
iptables脚本:
#!/bin/bash
#
ipt=/usr/sbin/iptables
einterface=eth1
iinterface=eth0
eip=172.16.100.7
iip=192.168.10.6
$ipt -t nat -F
$ipt -t filter -F
$ipt -t mangle -F
$ipt -N clean_up
$ipt -A clean_up -d 255.255.255.255 -p icmp -j DROP
$ipt -A claen_up -j REJECT
pOST--->MBR(bootloader)--->Kernael(initrd)--->init(/etc/inittab)
1.设定默认级别
2.系统初始化脚本
3.运行指定级别
IDS:
nids:snort + iptables =NIPS
hids:
xen,kum:iptables:虚拟
IDS是英文“Intrusion Detection Systems”的缩写,中文意思是“入侵检测系统”。专业上讲就是依照一定的安全策略,通过软、硬件,对网络、系统的运行状况进行监视,尽可能发现各种攻击企图、攻击行为或者攻击结果,以保证网络系统资源的机密性、完整性和可用性。做一个形象的比喻:假如防火墙是一幢大楼的门锁,那么IDS就是这幢大楼里的监视系统。一旦小偷爬窗进入大楼,或内部人员有越界行为,只有实时监视系统才能发现情况并发出警告。
按入侵检测的手段、IDS的入侵检测模型可分为基于网络和基于主机两种。
在1998年,Martin Roesch先生用C语言开发了开放源代码(Open Source)的入侵检测系统Snort.直至今天,Snort已发展成为一个多平台(Multi-Platform),实时(Real-Time)流量分析,网络IP数据包(Pocket)记录等特性的强大的网络入侵检测/防御系统(Network Intrusion Detection/Prevention System),即NIDS/NIPS.Snort符合通用公共许可(GPL——GNU General Pubic License),在网上可以通过免费下载获得Snort,并且只需要几分钟就可以安装并开始使用它。snort基于libpcap。
Snort有三种工作模式:嗅探器、数据包记录器、网络入侵检测系统。嗅探器模式仅仅是从网络上读取数据包并作为连续不断的流显示在终端上。数据包记录器模式把数据包记录到硬盘上。网络入侵检测模式是最复杂的,而且是可配置的。我们可以让snort分析网络数据流以匹配用户定义的一些规则,并根据检测结果采取一定的动作。
Snort能够对网络上的数据包进行抓包分析,但区别于其它嗅探器的是,它能根据所定义的规则进行响应及处理。Snort 通过对获取的数据包,进行各规则的分析后,根据规则链,可采取Activation(报警并启动另外一个动态规则链)、Dynamic(由其它的规则包调用)、Alert(报警),Pass(忽略),Log(不报警但记录网络流量)五种响应的机制。
Snort有数据包嗅探,数据包分析,数据包检测,响应处理等多种功能,每个模块实现不同的功能,各模块都是用插件的方式和Snort相结合,功能扩展方便。例如,预处理插件的功能就是在规则匹配误用检测之前运行,完成TIP碎片重组,http解码,telnet解码等功能,处理插件完成检查协议各字段,关闭连接,攻击响应等功能,输出插件将得理后的各种情况以日志或警告的方式输出。