Asp.net
EnableHeaderChecking=true 是否足以防止 Http Header 注入攻擊?
將 [
System.Web.Configuration.HttpRuntimeSection.EnableHeaderChecking]( http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableheaderchecking(VS.85).aspx)設置為true(預設)是否足以完全阻止 Http響應拆分等標頭注入攻擊?我之所以問,是因為一個白盒滲透測試工具(fortify)報告了可利用的 http 標頭注入問題
HttpResponse.Redirect和 cookie,但我還沒有找到成功執行攻擊的方法。(編輯:..我們啟用了EnableHeaderChecking ..)
我已經研究了一段時間,並得出結論,將EnableHeaderChecking設置為
true實際上足以防止 http 標頭注入攻擊。查看“反映”的 ASP.NET 程式碼,我發現:
- 只有一種方法可以將自定義 HTTP 標頭添加到 HTTP 響應,即使用HttpResponse.AppendHeader方法
- HttpResponse.AppendHeader要麼
- 創建
HttpResponseHeader(內部)的實例- 或呼叫
HttpResponseHeader.MaybeEncodeHeader(forIIS7WorkerRequests)- 或分配其各自的屬性(對於已知的標頭,如RedirectLocation或ContentType)
HttpResponseHeader在發送RedirectLocation或ContentType等已知標頭之前創建實例(HttpResponse.GenerateResponseHeaders)- 構造
HttpResponseHeader函式檢查EnableheaderChecking設置並HttpResponseHeader.MaybeEncodeHeader在設置為時呼叫trueHttpResponseHeader.MaybeEncodeHeader正確編碼換行符,這使得 HTTP 標頭注入攻擊不可能這是一個大致展示我如何測試的片段:
// simple http response splitting attack Response.AddHeader("foo", "bar\n" + // injected http response, bad if user provided "HTTP/1.1 200 OK\n" + "Content-Length: 19\n" + "Content-Type: text/html\n\n" + "<html>danger</html>" );以上僅在您明確關閉EnableHeaderChecking時才有效:
<httpRuntime enableHeaderChecking="false"/>Fortify 根本不考慮配置(顯式設置EnableHeaderChecking無效),因此總是報告這些類型的問題。