原罪的雜記

關閉HTTP TRACE 避免Cross Site Scripting風險 –for Unix/Unix like

From: http://vincent119.blogspot.com/2008/08/apache.html  & http://forum.parallels.com/showthread.php?t=81732

關閉 ServerToken 功能

ServerToken 的功能是在 Apache 1.3 以後的版本才出現的,而 ProductOnly 關鍵字則是在 1.3.12 之後才出現。ServerToken 主要是控制伺服器在表頭區域回應給用戶端的資訊,例如使用何種作業系統或模組。因此,入侵者可能利用這些資訊而採用特定的攻擊方法,來更快速進行滲透或破解。所以提供的資訊越少則越安全。因此可以利用 ServerToken 功能:其語法為: ServerTokens MajorMinorMin[imal]Prod[uctOnly]OSFull 預設為: ServerTokens Full 分別說明: ServerTokens Prod[uctOnly] –> 伺服器可能回傳: Server: Apache

ServerTokens Major –> 伺服器可能回傳: Server: Apache/2

ServerTokens Minor –> 伺服器可能回傳: Server: Apache/2.0

ServerTokens Min[imal] –> 伺服器可能回傳: Server: Apache/2.0.41

ServerTokens OS –> 伺服器可能回傳: Server: Apache/2.0.41 (Unix)

ServerTokens Full (or not specified) –> 伺服器可能回傳:Server sends (e.g.): Server: Apache/2.0.41 (Unix) PHP/4.2.2 MyMod/1.2

因此,若要讓回傳的資訊最少,則可以在 httpd.conf 中加入:

ServerTokens Prod

關閉 HTTP TRACE 功能

HTTP TRACE 是一個 HTTP request method,主要是用來做 debug,此方法會回傳 client 的 HTTP request 內容,並放置於於 TRACE response 中的 entity body。因此,惡意攻擊者可利用此方法取得敏感的伺服器資訊,例如 cookies 或表頭中的認證資料。此方法預設為打開,但為了安全方面的考量,最好將此方法給關閉。

一般來說,您可以利用mod_rewrite來關閉 HTTP TRACE 的功能,首先將 httpd.conf 中的 LoadModule rewrite_module modules/mod_rewrite.so 註解打開,讓 HTTP 有mod_rewrite 的功能,並且在加入下列的規則:

RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]

如果您的 Apache 版本是 2.0 以上,則有比較快速的方法來關閉(因為上述的方法必須開啟 mod_rewrite 的功能):

TraceEnable off

如此則關閉了 HTTP TRACE 的功能。

參考文章: http://wiki.oss.org.tw/index.php/Apache_Tips#.E9.97.9C.E9.96.89_HTTP_TRACE_.E5.8A.9F.E8.83.BD

備註:若apache為2.0版本以上,在httpd.conf加入兩行code:
ServerTokens Prod
TraceEnable off

三月 3rd, 2009 Posted by 原罪 | Linux, freebsd | no comments