網(wǎng)站首頁 編程語言 正文
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
相關(guān)推薦
- 2022-08-17 Python連接數(shù)據(jù)庫并批量插入包含日期記錄的操作_python
- 2023-10-14 C/C++ 批量梯度下降法實(shí)現(xiàn)一元線性回歸
- 2022-11-09 Python數(shù)據(jù)庫sqlite3圖文實(shí)例詳解_python
- 2023-03-23 Rust應(yīng)用調(diào)用C語言動(dòng)態(tài)庫的操作方法_Rust語言
- 2021-12-12 Redis實(shí)現(xiàn)分布式鎖的實(shí)例講解_Redis
- 2022-06-14 Go操作redis與redigo的示例解析_Golang
- 2022-10-26 Go?語言數(shù)據(jù)結(jié)構(gòu)之雙鏈表學(xué)習(xí)教程_Golang
- 2023-01-28 Flutter框架解決盒約束widget和assets里加載資產(chǎn)技術(shù)_Android
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支