当前位置: 代码网 > it编程>编程语言>安全编程 > Iptables防火墙string模块扩展匹配规则

Iptables防火墙string模块扩展匹配规则

2024年05月15日 安全编程 我要评论
iptables防火墙string模块扩展匹配规则string模块的作用是来匹配请求报文中指定的字符串,经常应用于拦截用户访问某些网站的场景,将防火墙当做路由器使用,例如上班时间不允许用户访问淘宝网站

iptables防火墙string模块扩展匹配规则

string模块的作用是来匹配请求报文中指定的字符串,经常应用于拦截用户访问某些网站的场景,将防火墙当做路由器使用,例如上班时间不允许用户访问淘宝网站等等场景。

string模块的常用参数:

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

! --string pattern:反向匹配。

--algo:指定匹配的查询算法,有bm和kmp两种算法。

可以在参数前面加!号表示去反。

案例:当用户请求的数据报文中包含taobao.com,则拒绝通行,其余的正常放行。

用户通过防火墙流出然后访问目标端,因此需要在output链添加规则。

1)首先来准备含有taobao.com数据报文的web网站。

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)编写防火墙规则,拒绝数据包中包含taobao.com内容的数据包。

[root@jxl-1 ~]# iptables -t filter -i output -p tcp -m string --string "taobao.com" --algo bm -j drop

3)查看设置的防火墙规则。

[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)测试效果,发现hahaha的页面可以正常访问,taobao.com页面的请求将被拦截。

以上就是iptables防火墙string模块扩展匹配规则的详细内容,更多关于iptables防火墙string模块的资料请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com