iptables实现字符串匹配,URL过滤,安全策略

通过string匹配域名来过滤,范例如下:

iptables -I OUTPUT -p tcp -m string --string "qq.com" --algo bm -j DROP
iptables -I OUTPUT -p udp -m string --string "qq.com" --algo kmp -j DROP

这样就无法访问与QQ相关的业务了,但是代理好像还是可以

系统要求:

1:内核在2.6.18以上

2:iptables在1.3.5以上

3:内核中包含字符串匹配模块。在.config文件中应有

CONFIG_NETFILTER_XT_MATCH_STRING=m 

man手册

iptables -m string -help
string

         This  modules  matches  a  given string by using somepattern matching strategy. It requires a linux kernel >= 2.6.14.

        --algo  bm|kmp

              Select the pattern matching strategy. (bm = Boyer-Moore, kmp = Knuth-Pratt-Morris)
	      设置字符匹配的查询算法,一般默认使用bm算法效果就可以了,另外还可以设置kmp算法,那是一种更复杂的算法,详细内容可自行参见高等数学里的资料。(bm = Boyer-Moore, kmp = Knuth-Pratt-Morris)

        --from offset

              Set the offset from which it starts looking for any matching. If not passed, default is 0.

        --to offset

              Set the offset to which it starts looking for any matching. If not passed, default  is  the

              packet size.

        --string pattern

              Matches the given pattern.  --hex-string pattern Matches the given pattern in hex notation.
              定义字符串内容,可以是URL里任意字符,如果是需要block下载某些类型的文件或请求,这个有很大的发挥空间,可自由想象喔。

常见的应用程序和有用的示例规则

1:防止入侵的方法
iptables -I INPUT 1 -p tcp --dport 80 -m string --string "cmd.exe" --algo bm -j DROP

iptables -I INPUT -j DROP -p tcp -s 0.0.0.0/0 -m string --algo kmp --string "cmd.exe"

2:保护DDOS服务
iptables -I INPUT 1 -p tcp --dport 80 -m string --string "domain.com" --algo kmp -j DROP
3:防止电子邮件欺骗
iptables -I INPUT -p tcp --dport 25 -m string --string "Subject" --algo bm -j DROP
做个最优规则
iptables -I INPUT -p tcp --dport 25 -m string --string "Subject"  --algo bm --to 15000 -j DROP

 

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值