网站安全测试显示Response.Redirect易受攻击

时间:2013-09-24 14:16:16

标签: c# asp.net security http

使用Acunetix扫描我的Web应用程序后,结果显示9个“重定向页面中找到HTML表单”的实例。用于重现测试攻击的HTTP标头如下:

Request
GET /entities/add HTTP/1.1
Pragma: no-cache
Referer: https://test.mysite.com/entities/view
Acunetix-Aspect: enabled
Acunetix-Aspect-Password: 082119f75623eb7abd7bf357698ff66c
Acunetix-Aspect-Queries: filelist;aspectalerts
Cookie: __AntiXsrfToken=97c0a6bb164d4121b07327df405f9db4; mysitecookie=
Host: test.mysite.com
Connection: Keep-alive
Accept-Encoding: gzip,deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Acunetix-Product: WVS/8.0 (Acunetix Web Vulnerability Scanner - NORMAL)
Acunetix-Scanning-agreement: Third Party Scanning PROHIBITED
Acunetix-User-agreement: http://www.acunetix.com/wvs/disc.htm
Accept: */*

Response
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Location: /login
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Set-Cookie: mysitecookie=; expires=Mon, 11-Oct-1999 22:00:00 GMT; path=/; HttpOnly
X-Powered-By: ASP.NET
Date: Tue, 24 Sep 2013 10:38:12 GMT
Content-Length: 9447

响应的Location: /login部分让我相信,如果我在将用户重定向到登录页面后结束了响应,则会堵塞漏洞。所以我改变了这段代码的所有实例:

protected void Page_Load(object sender, EventArgs e)
{
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Response.Redirect("/login");
    }
    else
    {
        // etc
    }
}

为:

protected void Page_Load(object sender, EventArgs e)
{
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Response.Redirect("/login", true);
    }
    else
    {
        // etc
    }
}

它仍然表现为脆弱的原因是什么?

3 个答案:

答案 0 :(得分:1)

正在引发该标志,因为页面中有一个HTML表单,以及响应头中的重定向。我认为这是一个漏洞,因为它可以让未经身份验证的用户深入了解您的应用程序的工作方式。你可以做些什么来阻止这个标志被引发是在重定向之前清除你的响应。

尝试以下方法:

protected void Page_Load(object sender, EventArgs e)
{
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Response.Clear();
        Response.Redirect("/login", true); // btw true is the default...
    }
    else
    {
        // etc
    }
}

如果您正在设置会话变量,Cookie等,那么您需要对其进行一些调整,以确保所有内容都能进入响应,例如:使用endResponse = false,Response.End();返回;等

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.clear.aspx

答案 1 :(得分:0)

Response.Redirect向客户端发送额外的往返行程(响应代码302)。这意味着客户端必须调用“新”URL。这通常是你不想做的事情。

在.Net中,您还可以直接在服务器上进行重定向,这意味着无需额外的往返。

而不是Response.Redirect,而是要调用Server.Transfer或Server.TransferRequest(这是需要集成应用程序池的新方法)。

http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.transferrequest.aspx

如果您的上下文中没有Server,您还会在HttpServerUtility中找到HttpContext.Current的实例。

答案 2 :(得分:0)

我不能说什么标准Acunetix计算漏洞,但我建议您使用response.redirect("url",false)重载 - check here

如果为endResponse参数指定true,则此方法为原始请求调用End方法,该方法在完成时抛出ThreadAbortException异常。此异常对Web应用程序性能有不利影响,这就是建议为endResponse参数传递false的原因。

protected void Page_Load(object sender, EventArgs e)
{
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        Response.Clear();
        Response.Redirect("/login", false);
        Context.ApplicationInstance.CompleteRequest();
    }
    else
    {
        // etc
    }
}

Context.ApplicationInstance.CompleteRequest(); 导致ASP.NET绕过HTTP管道执行链中的所有事件和过滤,并直接执行EndRequest事件。 它会绕过导致ThreadAbortException.

的事件