標籤:字串 iptables kmp matching hex
iptables實現字串匹配
分類: SHELL&linux命令2012-07-03 18:25 3172人閱讀 評論(0) 收藏 舉報
stringinputtcpoutputhexlinux
通過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 -helpstring 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 DROPiptables -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 DROP3:防止電子郵件欺騙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
本文出自 “ComeFrom二龍山下/七道門” 部落格,請務必保留此出處http://zj1991.blog.51cto.com/1847949/1605816
iptables實現字串匹配