拥有[就足够了吗?System.Web.Configuration.HttpRuntimeSection.EnableHeaderChecking
](http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableheaderchecking(VS.85).aspx) http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableheaderchecking(VS.85).aspx) set to true
(默认)完全防止 Http 标头注入攻击,例如响应拆分等?
我问这个问题是因为白盒渗透测试工具(fortify)报告了可利用的http标头注入问题HttpResponse.Redirect
和 cookies,但我还没有找到成功执行攻击的方法。 (edit:..并且我们打开了 EnableHeaderChecking..)
我已经研究这个有一段时间了,得出的结论是设置启用标头检查 http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableheaderchecking(VS.85).aspx to true
事实上足以防止 http 标头注入攻击。
查看“反射”的 ASP.NET 代码,我发现:
- 只有一种方法可以将自定义 HTTP 标头添加到 HTTP 响应,即使用HttpResponse.AppendHeader http://msdn.microsoft.com/en-us/library/system.web.httpresponse.appendheader.aspx method
-
HttpResponse.AppendHeader http://msdn.microsoft.com/en-us/library/system.web.httpresponse.appendheader.aspx either
- 创建实例
HttpResponseHeader
(内部的)
- 或致电
HttpResponseHeader.MaybeEncodeHeader
(for IIS7WorkerRequests
)
- 或分配其各自的属性(对于已知的标头,例如重定向位置 http://msdn.microsoft.com/en-us/library/system.web.httpresponse.redirectlocation.aspx or 内容类型 http://msdn.microsoft.com/en-us/library/system.web.httpresponse.contenttype.aspx)
-
HttpResponseHeader
实例是在已知标头之前创建的,例如重定向位置 http://msdn.microsoft.com/en-us/library/system.web.httpresponse.redirectlocation.aspx or 内容类型 http://msdn.microsoft.com/en-us/library/system.web.httpresponse.contenttype.aspx已发送(HttpResponse.GenerateResponseHeaders
)
- The
HttpResponseHeader
构造函数检查启用标头检查 http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableheaderchecking(VS.85).aspx设置和通话HttpResponseHeader.MaybeEncodeHeader
当设置为true
-
HttpResponseHeader.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>"
);
仅当您明确转向时,上述内容才有效启用标头检查 http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableheaderchecking(VS.85).aspx off:
<httpRuntime enableHeaderChecking="false"/>
Fortify 根本不考虑配置(设置启用标头检查 http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableheaderchecking(VS.85).aspx明确没有效果),因此always报告此类问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)