日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

Iptables防火墻string模塊擴(kuò)展匹配規(guī)則_安全相關(guān)

作者:jiangxl ? 更新時(shí)間: 2022-10-05 編程語言

Iptables防火墻string模塊擴(kuò)展匹配規(guī)則

String模塊的作用是來匹配請求報(bào)文中指定的字符串,經(jīng)常應(yīng)用于攔截用戶訪問某些網(wǎng)站的場景,將防火墻當(dāng)做路由器使用,例如上班時(shí)間不允許用戶訪問淘寶網(wǎng)站等等場景。

String模塊的常用參數(shù):

--string pattern:指定要匹配的字符串。

! --string pattern:反向匹配。

--algo:指定匹配的查詢算法,有bm和kmp兩種算法。

可以在參數(shù)前面加!號表示去反。

案例:當(dā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)測試效果,發(fā)現(xiàn)hahaha的頁面可以正常訪問,taobao.com頁面的請求將被攔截。

原文鏈接:https://juejin.cn/post/7130084759115399198

欄目分類
最近更新