Iptables防火墻string模塊擴展匹配規(guī)則
Iptables防火墻string模塊擴展匹配規(guī)則
String模塊的作用是來匹配請求報文中指定的字符串,經(jīng)常應(yīng)用于攔截用戶訪問某些網(wǎng)站的場景,將防火墻當做路由器使用,例如上班時間不允許用戶訪問淘寶網(wǎng)站等等場景。
String模塊的常用參數(shù):
--string pattern:指定要匹配的字符串。
! --string pattern:反向匹配。
--algo:指定匹配的查詢算法,有bm和kmp兩種算法。
可以在參數(shù)前面加!號表示去反。
案例:當用戶請求的數(shù)據(jù)報文中包含taobao.com,則拒絕通行,其余的正常放行。
用戶通過防火墻流出然后訪問目標端,因此需要在OUTPUT鏈添加規(guī)則。
1)首先來準備含有taobao.com數(shù)據(jù)報文的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.正常的兩個頁面 [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)測試效果,發(fā)現(xiàn)hahaha的頁面可以正常訪問,taobao.com頁面的請求將被攔截。

以上就是Iptables防火墻string模塊擴展匹配規(guī)則的詳細內(nèi)容,更多關(guān)于Iptables防火墻string模塊的資料請關(guān)注腳本之家其它相關(guān)文章!

