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 grouplist
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解碼等功能,處理插件完成檢查協議各字段,關閉連接,攻擊響應等功能,輸出插件將得理后的各種情況以日志或警告的方式輸出。