EnableHeaderChecking=true 是否足以防止 Http 标头注入攻击?

发布于 2024-07-20 02:22:58 字数 591 浏览 10 评论 0原文

拥有 [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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

吹泡泡o 2024-07-27 02:22:58

我已经研究这个问题有一段时间了,得出的结论是设置 EnableHeaderCheckingtrue 实际上足以防止 http 标头注入攻击。

查看“反射”的 ASP.NET 代码,我发现:

  1. 只有一种方法可以将自定义 HTTP 标头添加到 HTTP 响应,即使用 HttpResponse.AppendHeader 方法
  2. HttpResponse.AppendHeader 任一
    • 创建 HttpResponseHeader 实例(内部)
    • 或调用HttpResponseHeader.MaybeEncodeHeader(对于IIS7WorkerRequests
    • 或分配其各自的属性(对于已知标头,例如 RedirectLocationContentType)< /里>
  3. HttpResponseHeader 实例在已知之前创建诸如 RedirectLocationContentType (HttpResponse.GenerateResponseHeaders )
  4. HttpResponseHeader 构造函数检查 EnableheaderChecking 设置并在设置为 true 时调用 HttpResponseHeader.MaybeEncodeHeader
  5. 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>"
);

仅当您显式转动 EnableHeaderChecking 关闭:

<httpRuntime enableHeaderChecking="false"/>

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:

  1. There is only one way to add custom HTTP headers to an HTTP response, namely using the HttpResponse.AppendHeader method
  2. HttpResponse.AppendHeader either
    • creates instances of HttpResponseHeader (internal)
    • or calls HttpResponseHeader.MaybeEncodeHeader (for IIS7WorkerRequests)
    • or assigns its respective properties (for known headers like RedirectLocation or ContentType)
  3. HttpResponseHeader instances are created before known headers like RedirectLocation or ContentType are sent (HttpResponse.GenerateResponseHeaders)
  4. The HttpResponseHeader constructor checks the EnableheaderChecking setting and calls HttpResponseHeader.MaybeEncodeHeader when set to true
  5. HttpResponseHeader.MaybeEncodeHeader correctly encodes newline characters which makes HTTP header injection attacks impossible

Here is a snippet to roughly demonstrate how I tested:

// 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>"
);

The above only works if you explicitly turn EnableHeaderChecking off:

<httpRuntime enableHeaderChecking="false"/>

Fortify simply doesn't take configuration into account (setting EnableHeaderChecking explicitly had no effect) and thus always reports these type of issues.

温暖的光 2024-07-27 02:22:58

AFAIK 这已经足够了,它应该默认打开。

我认为 Fortify 只是考虑深度防御,就像您更改部署中的配置等一样。

我假设您没有在配置中严格设置它,如果您有,也许 Fortify 没有那么聪明地认为我们的。

最好的确认方法是利用它:)

  • 只需获取 fiddler 的副本
  • 拦截请求
  • 尝试注入新行
  • 看看您刚刚注入的新行是否在 HTTP 响应中。

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 :)

  • Just get a copy of fiddler
  • Intercept the request
  • Try to inject new line
  • See if the new line you've just injected is in the HTTP response or not.
筱果果 2024-07-27 02:22:58

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.

请爱~陌生人 2024-07-27 02:22:58

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文