|
嚜
Linux撘瑕之iptables嚗銝槐pt_recentmodule嚗賡餅DDoS餅
6 z4 e* P9 P+ w( K, P: z3 L靘憒嚗雿臭誑啣銝chain嚗 iptables -N WEB_SRV_DOS ":WEB_SRV_DOS - [0:0]"1 r- [) f0 J5 i* s
嗅嚗其誑銝隞歹60蝘吩it port 80/443頞10甈∠IP餅銝西銝靘嚗" y/ ? H* Z4 e+ @# X
- iptables -A INPUT -p tcp -m multiport dports 80,443 -j WEB_SRV_DOS
- iptables -A WEB_SRV_DOS -p tcp --syn -m multiport --dports 80,443 -m recent --rcheck --second 60 --hitcount 10 -j LOG --log-prefix "[Possible DOS Attack]"
- iptables -A WEB_SRV_DOS -p tcp --syn -m multiport --dports 80,443 -m recent --rcheck --second 60 --hitcount 10 -j REJECT
- iptables -A WEB_SRV_DOS -p tcp --syn -m multiport --dports 80,443 -m recent --set
- iptables -A WEB_SRV_DOS -p tcp -m multiport --dports 80,443 -j ACCEPT
銴鋆賭誨蝣 ! p, J- \8 T' @/ G
憒雿dmesg唬憿航炊嚗 , k( d+ Y/ L; |( v/ _0 w" o
hitcount (200) is larger than packets to be remembered (20)
5 q6 \& _5 B1 K$ I$ E8 s銵函內雿閮剖閬閮蝞甈⊥詨之履pt_recent閮剖銝嚗舫隤踵惺pt_recent moduleip_pkt_list_tot訾閫瘙箝! F( K3 H2 }3 e% S8 p
, q2 [5 U0 V$ Q% K; |/ X* E4 Z
皜祈岫銝銝:
( r- F$ T$ \; N* f% B4 a撠皜祈岫site澆箏之 http request [size=13.376px](臭誑撖怎撘靘頝嚗冽雓撌乩犖箸 灸rowser憭TAB嚗銝瑞reload蝬脤)! ^1 D8 C5 o6 Z
臭誑潛曉/var/log/message銝剖箇曆閮荔+ [5 b( J6 ]8 o$ q& C* x. e
May 17 07:12:00 localhost kernel: [Possible DOS Attack]IN=eth0 OUT= MAC=XX:XX:XX:XX:43:77:00:1f:YY:YY:YY:YY SRC=192.168.0.105 DST=192.168.0.102 LEN=64 TOS=0x00 PREC=0x00 TTL=64 ID=45026 DF PROTO=TCP SPT=59437 DPT=80 WINDOW=65535 RES=0x00 SYN URGP=0
0 S$ Z( @, `' C2 s甇斗隞半rowser皜祈岫蝬脤嚗箇遨onnection refused嚗⊥銝(箸閮剖rule爹EJECT). @: e" | S: h% _$ v8 ~
OK嚗iptablesipt_recent module潭桐其
8 p( j. u# Y$ K
" |( L1 y. N) f, E$ j h蝯隢嚗9 N {0 {# o7 ?) m" N4 W3 U7 {$ F
(1) iptables函雯頝臬惜喲餅餅撠嚗撠serverloading敶梢輯撠0 R; u8 I/ P3 [6 t* P8 _
(2) iptables閮剖銝頛敶改舐其脰風80,443隞亙port
4 Z9 w( P5 B" ~(3) iptables航身摰潛函銝餅嚗箏究erver寥脰靽霅瘀臭誑摰其霈餅撠脣叫erver
5 `' K& v2 L! `) v7 q- t$ k憒雿舐決S Windows + IIS嚗亙瑕嚗雿臭誑AQTRONIX WebKnight憟鞎餌web application firewall嚗鋆⊿W單脰風DDoS餅賬7 @) b, W" P, W: g6 M6 ?" e
9 b8 ~5 F% B* D+ |0 A) `4 L, S X5 B' b0 @
: http://blog.eztable.com/2011/05/17/how-to-prevent-ddos/9 v- U0 m" X, j" n
! O+ I2 C$ D! V7 `
================================================
! `' j; _, q% `7 J" y菜葫舐IP 隞:
; F. Q* F7 D Q; X( Vsed 's/ .*//' access.log | sort | uniq -c | sort -n9 A" s& w6 M0 W* H+ K$ [
perl -ne 'print "$1*\n" if m#^((\d+\.){3})#' access.log | sort | uniq -c | sort -n
- k+ r( [- C1 ?2 y: c |
|
|