在ASP.NET身份验证应用程序中留下后门的最佳方式是什么?
我是一个公司内部客户端系统的开发人员,在某些情况下,我必须使用用户帐户登录系统,以检查是否存在bug或其他问题。因为密码是加密的,所以我不能在数据库中查找密码并获得访问权限 我发明的最好的方法是使用一个查询参数标志,比如?Heythissadmin=SojustletMeinWithoanyPasswords,它允许我输入任何密码并登录在ASP.NET身份验证应用程序中留下后门的最佳方式是什么?,asp.net,asp.net-mvc,security,asp.net-identity,.net-security,Asp.net,Asp.net Mvc,Security,Asp.net Identity,.net Security,我是一个公司内部客户端系统的开发人员,在某些情况下,我必须使用用户帐户登录系统,以检查是否存在bug或其他问题。因为密码是加密的,所以我不能在数据库中查找密码并获得访问权限 我发明的最好的方法是使用一个查询参数标志,比如?Heythissadmin=SojustletMeinWithoanyPasswords,它允许我输入任何密码并登录 但我很理解安全问题。你能告诉我一些方法来实现我想要的但更健壮和安全吗?正如你所说,你提出的解决方案根本不安全,因为任何阅读代码或知道秘密的人都会使用神奇的查询字
但我很理解安全问题。你能告诉我一些方法来实现我想要的但更健壮和安全吗?正如你所说,你提出的解决方案根本不安全,因为任何阅读代码或知道秘密的人都会使用神奇的查询字符串来使用这种超能力 更好的解决方案可能是在客户端平台上创建自己的帐户,但上面有一个特殊的标志,允许您模拟用户帐户或只是查看他们看到的内容。当然,这种机制需要一些发展 请注意,即使使用此解决方案,该技巧也只能在您登录后完成。为了提高安全性,您还可能需要第二个因素来验证您的电子邮件、SMS、TOTP 你需要把你想要实现的东西作为你应用程序的一个功能,而不是后门。你应该能够向任何人解释它是如何工作的,而不必公开你的应用程序。因为它的优势在于: 你的密码 你的第二个因素,如果有的话 事实上,你已经在你的帐户上设置了标志
ASP有能力通过隔离处理此问题。您需要实现设置和禁用命令的方法 我实现这一点的方法是只使用[Authorize]属性修饰SetImpersonation操作,以便只允许管理员用户角色模拟用户 以下是MVC的一个示例: 设置模拟
[Authorize(Roles = (AccountController.Permissions.SUPER_USER))]
public ActionResult ImpersonateUser(string userName)
{
string originalUsername = LoggedInUser.Email;
ApplicationUser impersonatedUser = UserManager.FindByNameAsync(userName).Result;
var impersonatedIdentity = UserManager.CreateIdentityAsync(impersonatedUser, DefaultAuthenticationTypes.ApplicationCookie).Result;
impersonatedIdentity.AddClaim(new Claim("UserImpersonation", "true"));
impersonatedIdentity.AddClaim(new Claim("OriginalUsername", originalUsername));
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, impersonatedIdentity);
return RedirectToAction("Index", "Home");
}
要恢复模拟,此操作需要被不受约束的用户访问
public ActionResult RevertImpersonationAsync()
{
if (!HttpContext.User.IsImpersonating())
{
// we could throw an exception here, but it might be more prudent to just silently fail, keeps this feature quiet from snoopers
//throw new Exception("Unable to remove impersonation because there is no impersonation");
return RedirectToAction("Index", "Home");
}
var originalUsername = HttpContext.User.GetOriginalUsername();
var originalUser = UserManager.FindByNameAsync(originalUsername).Result;
var impersonatedIdentity = UserManager.CreateIdentityAsync(originalUser, DefaultAuthenticationTypes.ApplicationCookie).Result;
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, impersonatedIdentity);
return RedirectToAction("Index", "Home");
}