EnableHeaderChecking=true 是否足以防止 Http 标头注入攻击?
拥有 [System.Web.Configuration.HttpRuntimeSection.EnableHeaderChecking
](http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableheaderchecking(VS.85)。 aspx) 设置为 true
(默认)以完全防止 Http 标头注入攻击,例如响应拆分等?
我之所以这么问,是因为白盒渗透测试工具 (fortify) 报告了 HttpResponse.Redirect
和 cookie 的可利用 http 标头注入问题,但我还没有找到成功执行攻击的方法。 (编辑:..并且我们打开了 EnableHeaderChecking..)
Is it sufficient to have [System.Web.Configuration.HttpRuntimeSection.EnableHeaderChecking
](http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableheaderchecking(VS.85).aspx) set to true
(default) to fully prevent Http Header Injection attacks like Response Splitting etc.?
I'm asking because a white box penetration testing tool (fortify) reports exploitable http header injection issues with HttpResponse.Redirect
and cookies but I haven't found a way to successfully perform an attack. (edit:..and we have EnableHeaderChecking turned on..)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我已经研究这个问题有一段时间了,得出的结论是设置 EnableHeaderChecking 为
true
实际上足以防止 http 标头注入攻击。查看“反射”的 ASP.NET 代码,我发现:
HttpResponseHeader
实例(内部)HttpResponseHeader.MaybeEncodeHeader
(对于IIS7WorkerRequests
)HttpResponseHeader
实例在已知之前创建诸如 RedirectLocation 或 ContentType (HttpResponse.GenerateResponseHeaders
)HttpResponseHeader
构造函数检查 EnableheaderChecking 设置并在设置为true
时调用HttpResponseHeader.MaybeEncodeHeader
HttpResponseHeader.MaybeEncodeHeader
正确编码换行符这使得 HTTP 标头注入攻击不可能这是一个片段,粗略地演示了我的测试方式:
仅当您显式转动 EnableHeaderChecking 关闭:
Fortify 根本不考虑配置(设置 EnableHeaderChecking 明确没有效果),因此总是 报告此类问题。
I've been looking at this for some time now and draw the conclusion that setting EnableHeaderChecking to
true
is in fact good enough to prevent http header injection attacks.Looking at 'reflected' ASP.NET code, I found that:
HttpResponseHeader
(internal)HttpResponseHeader.MaybeEncodeHeader
(forIIS7WorkerRequests
)HttpResponseHeader
instances are created before known headers like RedirectLocation or ContentType are sent (HttpResponse.GenerateResponseHeaders
)HttpResponseHeader
constructor checks the EnableheaderChecking setting and callsHttpResponseHeader.MaybeEncodeHeader
when set totrue
HttpResponseHeader.MaybeEncodeHeader
correctly encodes newline characters which makes HTTP header injection attacks impossibleHere is a snippet to roughly demonstrate how I tested:
The above only works if you explicitly turn EnableHeaderChecking off:
Fortify simply doesn't take configuration into account (setting EnableHeaderChecking explicitly had no effect) and thus always reports these type of issues.
AFAIK 这已经足够了,它应该默认打开。
我认为 Fortify 只是考虑深度防御,就像您更改部署中的配置等一样。
我假设您没有在配置中严格设置它,如果您有,也许 Fortify 没有那么聪明地认为我们的。
最好的确认方法是利用它:)
AFAIK it's enough and it should be turned on by default.
I think Fortify is just thinking about defence in depth as if you change the configuration in the deployment etc.
I assume you did not strictly set it on in your configuration, if you have maybe Fortify is not that smart to figure that our.
Best way to confirm is exploiting it :)
EnableHeaderChecking 仅适用于不受信任的数据。 如果您将数据直接从 cookie 传递到重定向,则生成的标头可能会被视为受信任,并且 \r\n 值不会被转义。
EnableHeaderChecking is only for untrusted data. If you're passing data directly from a cookie into a Redirect, maybe the resulting headers are considered trusted and \r\n values aren't escaped.
Josef,HttpResponse.AppendHeader() 并不是不受信任的数据可以进入 HTTP 响应标头的唯一位置。
如果数据包含回车符(或任何被解释为回车符的内容),则来自攻击者的任何最终出现在 Cookie 或 HTTP 重定向中的数据都可以写入新标头。
一般来说,利用时间来验证数据比坐下来尝试找出漏洞要好得多。 黑客很可能比你我更擅长这一点。
Josef, HttpResponse.AppendHeader() is not the only place where untrusted data can enter the HTTP Response Headers.
Any data from the attacker that ends up in Cookies or HTTP redirects can write new headers if the data contains a carriage return (or anything that is interpreted as a carriage return).
In general, it's a much better use of your time to validate your data than to sit around and try to work out exploits. Chances are, the hackers are going to be better at this than you or I are.