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