iptables實現字串匹配

來源:互聯網
上載者:User

標籤:字串   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實現字串匹配

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.