Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(): Failed opening '/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24
mod_evasive – unethost無限空間虛擬主機 技術分享部落格

什麼是mod_evasive?

mod_evasive是Apache伺服器的一個第三方模組,可以回避HTTP DoS或DDoS攻擊。它在設計上,是網路檢測和網絡管理工具, 可以很容易地配置與iptables以及諸如此類的防火牆模組溝通。 mod_evasive可以透過電子郵件或syslog程序來回報網路檢測 的結果。

工作原理
通過建立內部動態的IP地址和URI hash表,如果下列的任一條件滿足,就會阻擋某一IP地址對網站的存取:
(1) 對同一網頁每秒超過某個次數的請求。
(2 )每秒針對同一個apache的子程序,送出超過50個請求。
(3) 當某個IP地址被暫時列入黑名單時,依然送出請求。

mod_evasive對於單一伺服器的腳本攻擊或是分布式攻擊,都相當有效。然而就和其它迴避的方法一樣,如果伺服器的頻寬或 是記憶体已經被攻擊的流量佔用,伺服器依然會變慢。所以使用mod_evasive時,將其與iptables這類的防火牆整合,可以更有效地發揮它的功效。

這個模塊會在每個apache子程序中,產生獨立的監聽者(listener),因此mod_evasive有內建的記憶体清理機制和縮放 (scaling)的能力。由於這種在每一個apache子程序中獨立計算攻擊的機制,正常的http請求,幾乎不會被誤判為攻擊。只有 腳本攻擊會被判定為攻擊。就算正在瀏覽網頁的使用者,不停地按F5,使網頁重新載入,也不會被mod_evasive誤判為攻擊。

如何安裝:
(1) 下載
(2) tar zxvf  mod_evasive_1.10.1.tar.gz
(3) cd mod_evasive_1.10.1
(4) ./configure
(5) make && make install
(6) 重新啟動 apache

接下來,是設定檔的部分:

APACHE v1.3
   -----------
   <IfModule mod_evasive.c>
       DOSHashTableSize    3097
       DOSPageCount        2
       DOSSiteCount        50
       DOSPageInterval     1
       DOSSiteInterval     1
       DOSBlockingPeriod   10
   </IfModule>
APACHE v2.0
   -----------
   <IfModule mod_evasive20.c>
       DOSHashTableSize    3097
       DOSPageCount        2
       DOSSiteCount        50
       DOSPageInterval     1
       DOSSiteInterval     1
       DOSBlockingPeriod   10
   </IfModule>

根據敝公司的實務經驗,調節上述的參數,對於阻擋的效果,並沒有很大的影響。但是,有兩點需要特別注意:
(1) apache的keep-alive要設定為true, 否則,mod_evasive的效果會很差。
(2) 安裝完畢之後,務必使用mod_evasive隨安裝包附的 test.pl 程式,來驗証是否mod_evasive被正確的設定了。

附註:防禦DDoS是很複雜困難的技術,如果mod_evasive你無法獨立安裝,或是你安裝了mod_evasive還是無法解決DDoS的問題,請你參考unethost的WAF解決方案