iptables系列之layer7
一塊網卡多個IP溶锭,這張網卡上連接一個交換機冗尤,交換機上連接了多個不同網段的主機,如果設置網關驰凛,以及轉發(fā)功能邻储。不同網段主機可以通信。
地址是屬于主機的少梁,不屬于網卡的考杉。
內網:只是向公網請求,且是拒絕公網上任何主機的請求揭斧。利用網關防火墻就行源地址轉換莱革。
服務器:接受公網的請求,利用網關防火墻進行目的地址轉換讹开。
注意:由于服務器是接受公網上任何主機進行響應的盅视,故安全性低,所以就會有利用服務器當做跳板旦万,進而去控制內網主機闹击,已達到竊取數據的目的。
可以在網關防火墻上設置三張網卡纸型,使內網主機和服務器隔離開來拇砰,即時服務器被攻陷,內網主機也不受影響狰腌。
DMZ:非軍事化區(qū)
三宿主的主機
內網客戶端<------------>網卡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
單內核:模塊化(文件系統(tǒng)瑰枫,驅動,安全)
微內核:
編譯內核:
配置 .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> “l(fā)ayer7” 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.系統(tǒng)初始化腳本
3.運行指定級別
IDS:
nids:snort + iptables =NIPS
hids:
xen,kum:iptables:虛擬
IDS是英文“Intrusion Detection Systems”的縮寫苛谷,中文意思是“入侵檢測系統(tǒng)”辅鲸。專業(yè)上講就是依照一定的安全策略,通過軟腹殿、硬件独悴,對網絡例书、系統(tǒng)的運行狀況進行監(jiān)視,盡可能發(fā)現各種攻擊企圖绵患、攻擊行為或者攻擊結果雾叭,以保證網絡系統(tǒng)資源的機密性、完整性和可用性落蝙。做一個形象的比喻:假如防火墻是一幢大樓的門鎖织狐,那么IDS就是這幢大樓里的監(jiān)視系統(tǒng)。一旦小偷爬窗進入大樓筏勒,或內部人員有越界行為移迫,只有實時監(jiān)視系統(tǒng)才能發(fā)現情況并發(fā)出警告。
按入侵檢測的手段管行、IDS的入侵檢測模型可分為基于網絡和基于主機兩種厨埋。
在1998年,Martin Roesch先生用C語言開發(fā)了開放源代碼(Open Source)的入侵檢測系統(tǒng)Snort.直至今天捐顷,Snort已發(fā)展成為一個多平臺(Multi-Platform),實時(Real-Time)流量分析荡陷,網絡IP數據包(Pocket)記錄等特性的強大的網絡入侵檢測/防御系統(tǒng)(Network Intrusion Detection/Prevention System),即NIDS/NIPS.Snort符合通用公共許可(GPL——GNU General Pubic License),在網上可以通過免費下載獲得Snort,并且只需要幾分鐘就可以安裝并開始使用它。snort基于libpcap迅涮。
Snort有三種工作模式:嗅探器废赞、數據包記錄器、網絡入侵檢測系統(tǒng)叮姑。嗅探器模式僅僅是從網絡上讀取數據包并作為連續(xù)不斷的流顯示在終端上唉地。數據包記錄器模式把數據包記錄到硬盤上。網絡入侵檢測模式是最復雜的传透,而且是可配置的耘沼。我們可以讓snort分析網絡數據流以匹配用戶定義的一些規(guī)則,并根據檢測結果采取一定的動作朱盐。
Snort能夠對網絡上的數據包進行抓包分析群嗤,但區(qū)別于其它嗅探器的是,它能根據所定義的規(guī)則進行響應及處理兵琳。Snort 通過對獲取的數據包骚烧,進行各規(guī)則的分析后,根據規(guī)則鏈闰围,可采取Activation(報警并啟動另外一個動態(tài)規(guī)則鏈)、Dynamic(由其它的規(guī)則包調用)既峡、Alert(報警)羡榴,Pass(忽略),Log(不報警但記錄網絡流量)五種響應的機制运敢。
Snort有數據包嗅探校仑,數據包分析忠售,數據包檢測,響應處理等多種功能迄沫,每個模塊實現不同的功能稻扬,各模塊都是用插件的方式和Snort相結合,功能擴展方便羊瘩。例如泰佳,預處理插件的功能就是在規(guī)則匹配誤用檢測之前運行,完成TIP碎片重組尘吗,http解碼逝她,telnet解碼等功能,處理插件完成檢查協(xié)議各字段睬捶,關閉連接黔宛,攻擊響應等功能,輸出插件將得理后的各種情況以日志或警告的方式輸出擒贸。