首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

iptables兑现字符串匹配

2012-07-16 
iptables实现字符串匹配通过string匹配域名来过滤,范例如下:iptables -I OUTPUT -p tcp -m string --strin

iptables实现字符串匹配

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

iptables -I OUTPUT -p tcp -m string --string "qq.com" --algo bm -j DROPiptables -I OUTPUT -p udp -m string --string "qq.com" --algo bm -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)        --from offset              Set the offset from which it starts looking for anymatching. If not passed, default is 0.        --to offset              Set the offset to which it starts looking for anymatching. If not passed, default  is  the              packet size.        --string pattern              Matches the given pattern.  --hex-string patternMatches the given pattern in hex notation.
 
常见的应用程序和有用的示例规则
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

 

热点排行