【问题标题】:Privilege Escalation & Session Hijacking in Identity MVC5Identity MVC5 中的权限提升和会话劫持
【发布时间】:2015-09-30 22:40:59
【问题描述】:

我在我的应用程序中使用 asp.net identity 2.0 进行身份验证(Owin 中间件)。 会话劫持: 当我登录身份创建 AspNet.ApplicationCookie.then 时,我复制了 AspNet.ApplicationCookie 值。然后我从应用程序中注销。注销后,我正在手动创建 cookie(AspNet.ApplicationCookie)并进行刷新它重定向我的主页。

权限提升: 同时,我以用户 A 的身份登录。我复制了(AspNet.ApplicationCookie)他的 cookie,然后我退出了。在我以用户 B 的身份登录后,我正在编辑用户 B Cookie 并粘贴用户 A cookie 并保存它。刷新后浏览器我可以获得 UserA 的访问权限和身份验证。

当我注销时,我正在清除所有会话并删除所有 cookie。即使 Asp.Net 身份(Owin)每次都会生成新的 AspNet.ApplicationCookie。但它仍然接受旧 cookie 并给我访问权限。我不知道为什么? 谁能告诉我注销后如何使旧的 AspNet.ApplicationCookie 失效。 这是我在 Startup.Auth.cs 中的代码

 public void ConfigureAuth(IAppBuilder app)
    {
        // Enable the application to use a cookie to store information for the signed in user
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login")
        });
        // Use a cookie to temporarily store information about a user logging in with a third party login provider
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);


    }

//这是注销代码

    public ActionResult LogOff ( )
    {
        //Delete all cookies while user log out
        string[] myCookies = Request.Cookies.AllKeys;
        foreach ( var cookies in myCookies )
        {
            Response.Cookies[ cookies ].Expires = DateTime.Now.AddDays(-1);

        }
        Request.GetOwinContext( ).Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);

        // AuthenticationManager.SignOut( );
        Session.Clear( );
        Session.RemoveAll( );
        Session.Abandon( );
        return RedirectToAction("LoginPage", "Account");
    }

//这是我的登录控制器代码

 public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (ModelState.IsValid)
        {
            var user = await UserManager.FindAsync(model.UserName, model.Password);
            if (user != null)
            {
                await SignInAsync(user, model.RememberMe);
                return RedirectToLocal(returnUrl);
            }
            else
            {
                ModelState.AddModelError("", "Invalid username or password.");
            }
        }

        // If we got this far, something failed, redisplay form
        return View(model);
    }

【问题讨论】:

    标签: c# asp.net cookies owin asp.net-identity-2


    【解决方案1】:

    这是设计使然。允许您从多个浏览器登录并仅在您单击“注销”的浏览器中注销,而不是所有其他浏览器。

    但在注销时,您可以在用户上更新SecurityStamp,然后将安全标记验证期设置为非常短的时间。

    这将更改安全标记:

    await userManager.UpdateSecurityStampAsync(user.Id);
    

    把它放在你的注销方法中。

    并且在你的Startup.Auth.cs中修改UseCookieAuthentication这样:

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login")
        Provider = new CookieAuthenticationProvider
        {
            // Enables the application to validate the security stamp when the user logs in.
            // This is a security feature which is used when you change a password or add an external login to your account.  
            OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                validateInterval: TimeSpan.FromMinutes(1), // set this low enough to optimise between speed and DB performance
                regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
        }
    });            
    

    这种方法的唯一缺点 - 当未执行注销过程时 - 什么也没有发生。当注销发生时,它会注销所有其他会话。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 2012-04-17
      相关资源
      最近更新 更多