如果您使用 ASP.NET 表单例份验证,您可能熟悉像这样的 URL:
https://Example.com/Banking/login.aspx?ReturnUrl=%2fBanking%2fBalances.aspx
只要您在没有表单例份验证 cookie 的情况下访问“Balances.aspx”,您就会得到这个。 ASP.NET 会将您跳转到登录页面,但会在查询字符串中提供 ReturnUrl,以便它可以将您重定向回来。
不幸的是,这引入了一个未经验证的转发,这是对 OWASP A10 的违规行为.
跨域漏洞
想象一下,如果我制作了一封电子邮件并将其发送出去......该电子邮件看起来就像来自您银行的电子邮件,并且具有如下 URL:
https://Example.com/Banking/login.aspx?ReturnUrl=https://Example.org/Banking/login.aspx
请注意,我巧妙地将 Example.com
切换为 Example.org
,您可能不会注意到。如果我很聪明,我什至可以使用十六进制代码对整个 ReturnUrl 进行 URL 编码,这样您就看不到它的到来。顺便说一句,我有一个 Example.org
的 EV 证书,这意味着您不会收到网络钓鱼错误,甚至会得到一个漂亮的绿色地址栏。不幸的是,您不会进入您认为自己所在的网站!在我的登录页面版本(看起来就像真实的一样)上,我会告诉你密码错误,你可以重新输入,瞧,我刚刚得到你的密码。
同域漏洞
同样的情况...我发送了一封看起来像是来自您的银行的电子邮件。但是您的银行不允许跨域重定向。不过,我可以使用此 URL 发起攻击:
https://Example.com/Banking/login.aspx?ReturnUrl=https://Example.com/Banking/Transfer.aspx?FromAcct=Checking&ToAcct=6273826&ToCountry=Nigeria&Amount=5000.00
上面看起来很糟糕,但请记住我可以使用 URL 编码来屏蔽整个内容,所以它看起来就像十六进制垃圾。
当您单击该链接时,系统会提示您登录您的网站,然后它会立即向我的尼日利亚帐户发出转账。
在我看来,ASP.NET 表单例份验证非常普遍。开发人员如何缓解此漏洞?
最佳答案
如何使用它来将用户重定向到登录页面:
FormsAuthentication.RedirectFromLoginPage
框架中似乎已经内置了保护措施:
By default, the ReturnUrl variable must refer to a page within the current application. If ReturnUrl refers to a page in a different application or on a different server, the RedirectFromLoginPage methods redirects to the URL in the DefaultUrl property. If you want to allow redirects to a page outside the current application, you must set the EnableCrossAppRedirects property to true using the enableCrossAppRedirects attribute of the configuration element.
示例代码:
FormsAuthentication.SetAuthCookie(user.UserName, false);
FormsAuthentication.RedirectFromLoginPage(user.UserName, false);
关于c# - 如何保护内置于表单例份验证中的 OWASP A10?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41817260/