2012年10月7日 星期日

再論 ModSecurity (如何保護 Apache )


前二篇文章我是透過 滲透測試 & 弱點掃描去探討,如何去保護Apache這個議題,
以 Apache 來說,它可以在 Windows(WAMP)及Linux(LAMP)或 BSD等其它 UNIX
平台上運作,當然它只需要有 C compiler 或 gcc compiler 的開發環境,只需取得官
網上的 Tarball(Source Code),自然可以透過 Compiler 、 Make 、 Make install將
ModSecurity(Apache module)安裝於該系統的平台之上,再透過設定  ModSecurity
Config & Rule 即可讓 Apache 得到一定的保護!

相關文章請自行參閱我之前寫的相關文章!
滲透測試 & 弱點掃描 w3af + WAF for Apache (Part 1)
http://xrcd2.blogspot.tw/2012/07/w3af-waf-for-apache.html
滲透測試 & 弱點掃描 w3af + WAF for Apache (Part 2)
http://xrcd2.blogspot.tw/2012/07/modsecurity-waf-for-apache.html

除此之外也可以透過修改 Apache config,啟用一些預設機置去做一些基本的保護.
如在設定檔內設定 ServerTokens Prod 、 ServerSignature Off 、 TraceEnable Off  等等(不顯示相關資本資訊,關閉除錯)

以 CVE-2011-3192  (Apache HTTP Server CVE-2011-3192 Denial Of Service Vulnerability) 為例
http://www.securityfocus.com/bid/49303
參考 http://wiki.apache.org/httpd/CVE-2011-3192 即可得到解法.

Apaache 2.2.x DoS 解法 (httpd.conf)

LoadModule headers_module modules/mod_headers.so
LoadModule rewrite_module modules/mod_rewrite.so
ServerTokens Prod
ServerSignature Off
SetEnvIf Range (?:,.*?){5,5} bad-range=1
RequestHeader unset Range env=bad-range
RequestHeader unset Request-Range
RewriteEngine on
RewriteCond %{HTTP:range} !(^bytes=[^,]+(,[^,]+){0,4}$|^$) [NC]
RewriteRule .* - [F]
RequestHeader unset Request-Range

圖一為某台主機經由 Nessus 找到的 Apache 弱點 (初掃)
圖二為加上  ServerTokens Prod & ServerSignature Off (第一次複掃的弱點)
圖三為啟用  headers_module  & rewrite_module (第二次複掃的弱點)
當然再上以  TraceEnable Off 或 透過
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
圖中的 HTTP Trace/Track Methods Allowed 這個中風險也應該會被排除才是.

WAMP 的使用環境  ModSecurity 可透過安裝 mod_security win32.zip 進行更進階的保護.
Download的URL可參考 http://www.apachelounge.com/download/
LAMP 的使用環境  ModSecurity 可透過安裝 modsecurity-apache_x.x.x.tar.gz 進行更進階的保護.
Download的URL可參考 http://www.modsecurity.org/download/

如果您是 IIS 的使用者 請參考 http://www.modsecurity.org/projects/modsecurity/iis/index.html
http://blogs.technet.com/b/srd/archive/2012/07/26/announcing-the-availability-of-modsecurity-extension-for-iis.aspx
相關內容應該可以得到相關的資訊..
如果您是 LNMP 的使用環境請參考  http://www.modsecurity.org/projects/modsecurity/nginx/index.html

滲透測試
w3af
http://w3af.sourceforge.net/
弱點掃描
dragonsoft ( http://www.dragonsoft.com.tw/ ) or
nessus ( http://www.nessus.org/products/nessus ) or
openvas ( http://www.openvas.org/ )

WAF for Apache  [WAF (Web Application Firewall)]
ModSecurity
http://www.modsecurity.org/
WANP (Windows、Apache、MySQL、PHP)
LAMP (Linux、Apache、MySQL、PHP)
LNMP (Linux、Nginx、MySQL、PHP)

沒有留言:

張貼留言