Iptables防火墻string模塊擴(kuò)展匹配規(guī)則
Iptables防火墻string模塊擴(kuò)展匹配規(guī)則
String模塊的作用是來匹配請(qǐng)求報(bào)文中指定的字符串,經(jīng)常應(yīng)用于攔截用戶訪問某些網(wǎng)站的場(chǎng)景,將防火墻當(dāng)做路由器使用,例如上班時(shí)間不允許用戶訪問淘寶網(wǎng)站等等場(chǎng)景。
String模塊的常用參數(shù):
--string pattern
:指定要匹配的字符串。
! --string pattern
:反向匹配。
--algo
:指定匹配的查詢算法,有bm和kmp兩種算法。
可以在參數(shù)前面加!號(hào)表示去反。
案例:當(dāng)用戶請(qǐng)求的數(shù)據(jù)報(bào)文中包含taobao.com,則拒絕通行,其余的正常放行。
用戶通過防火墻流出然后訪問目標(biāo)端,因此需要在OUTPUT鏈添加規(guī)則。
1)首先來準(zhǔn)備含有taobao.com數(shù)據(jù)報(bào)文的WEB網(wǎng)站。
1.安裝httpd [root@jxl-1 ~]# yum -y install httpd [root@jxl-1 ~]# echo hahaha > /var/www/html/ha.html [root@jxl-1 ~]# echo taobao.com > /var/www/html/taobao.html [root@jxl-1 ~]# systemctl restart httpd 2.正常的兩個(gè)頁面 [root@jxl-1 ~]# curl 127.0.0.1/ha.html hahaha [root@jxl-1 ~]# curl 127.0.0.1/taobao.html taobao.com
2)編寫防火墻規(guī)則,拒絕數(shù)據(jù)包中包含taobao.com內(nèi)容的數(shù)據(jù)包。
[root@jxl-1 ~]# iptables -t filter -I OUTPUT -p tcp -m string --string "taobao.com" --algo bm -j DROP
3)查看設(shè)置的防火墻規(guī)則。
[root@jxl-1 ~]# iptables -L -n -v --line-number Chain INPUT (policy ACCEPT 7011 packets, 6693K bytes) num pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 7310 packets, 11M bytes) num pkts bytes target prot opt in out source destination 1 0 0 DROP tcp -- * * 0.0.0.0/0 0.0.0.0/0 STRING match "taobao.com" ALGO name bm TO 65535
4)測(cè)試效果,發(fā)現(xiàn)hahaha的頁面可以正常訪問,taobao.com頁面的請(qǐng)求將被攔截。
以上就是Iptables防火墻string模塊擴(kuò)展匹配規(guī)則的詳細(xì)內(nèi)容,更多關(guān)于Iptables防火墻string模塊的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
SA 沙盤模式下不用恢復(fù)xp_cmdshell和xplog70.dll也執(zhí)行命令
sa下刪除xp_cmdshell和xplog70.dll時(shí)候的一種辦法,不算新的了, 也被一些人不斷的再次提出來,為了方便自己記憶再寫出來, 在這種情況下,要執(zhí)行命令,條件是要有xp_regwrite。2011-01-01當(dāng)網(wǎng)站不允許上傳asp cer cdx htr文件時(shí)的一個(gè)解決方法!
當(dāng)網(wǎng)站不允許上傳asp cer cdx htr文件時(shí)的一個(gè)解決方法!...2006-12-12關(guān)于動(dòng)網(wǎng)的cookie瀉露站點(diǎn)絕路徑的問題
關(guān)于動(dòng)網(wǎng)的cookie瀉露站點(diǎn)絕路徑的問題...2006-09-09