Cross-Site Request Forgery (CSRF, XSRF)

CSRF攻击是一种常见的web应用程序漏洞,它利用了网站已经授予用户及其浏览器的信任.

2023 Mid-Year Threat Report

什么是CSRF?

Cross-site request forgery (CSRF) attacks are common web application vulnerabilities 利用网站已经授予用户及其浏览器的信任. 在CSRF攻击中, 攻击者通常使用社会工程技术操纵经过身份验证的用户在用户不知情或不同意的情况下执行恶意操作. 只需点击电子邮件或聊天信息中看似合法的链接, 用户可能会在不知情的情况下给攻击者提供窃取其身份和访问权限的能力.

从那时起, 攻击者可以冒充受害者,并使用他们的账户对毫无戒心的用户进行无害的恶作剧,或者非法转账,耗尽受害者的银行账户. If the targeted user is a web administrator with broad access privileges, a CSRF attack can compromise the entire web application. 

当成功, CSRF攻击对运营站点的企业和访问站点的用户都是有害的. 这样的 利用 can negatively impact client relationships, damage customer confidence, 和 result in instances of fraud or theft of financial resources. CSRF攻击已经被用来攻击Gmail和Facebook等主要服务和网站, 等. 

CSRF is also known by a number of other names, 包括XSRF, “海上冲浪,“会议骑行”, cross-site reference forgery, 敌意链接. 微软在其威胁建模过程和在线文档中的许多地方将这种类型的攻击称为一键攻击. CSRF is considered a flaw under the A5 category in the OWASP Top 10.

CSRF是如何工作的?

When users attempt to access a site, 他们的浏览器通常会自动包含与站点相关的任何凭据以及他们的请求,以便登录过程更加方便. These credentials can include the user's session cookie, basic authentication credentials, IP地址, Windows domain credentials, 等等....... Once the user is authenticated to the site, 然而, 该站点无法区分伪造请求和合法用户请求. 

By co-opting the victim’s identity 和 access via a CSRF attack, an attacker can make a user perform unintended actions. 通常, 攻击者通过电子邮件使用社交工程技术说服受害者点击链接, 聊天信息, or a similar form of communication. 用户可能会在不知情的情况下在电子邮件消息中或在加载请求特定任务URL的站点页面后遇到恶意HTML或JavaScript代码. 然后执行任务,可以直接执行,也可以使用跨站点脚本缺陷执行. 用户通常不知道发生了什么,直到发生了恶意操作. 

CSRF攻击通常针对导致服务器状态改变的函数,但也可用于访问敏感数据. Upon performing a successful CSRF attack on a victim’s account, a malicious actor can initiate a transfer of funds, 购买一件物品, place a product in a shopping cart, alter account information such as a shipping address, 修改密码, or use any other function that is available on the vulnerable website. 

Stored CSRF Flaws 和 Their Impact

在某些情况下,可以将CSRF攻击直接存储在易受攻击的站点本身. 这样的 vulnerabilities are called stored CSRF flaws. 攻击者可以通过在接受HTML的字段中存储IMG或IFRAME标记来创建存储的CSRF漏洞, or by conducting a more complex cross-site scripting (XSS) attack. Samy MySpace蠕虫是XSS技术大规模破坏网站的一个著名案例.

如果攻击者能够在目标站点上存储CSRF攻击,则影响可能会严重得多. 在这种情况下, 由于包含恶意负载的页面现在包含在站点内,因此看起来完全合法, 受害者更有可能查看和信任包含攻击的页面,而不是互联网上的随机页面. 鉴于受害者已经通过了现场的身份验证, 攻击者将有更好的机会以CSRF攻击为目标. 

Three Tips for Preventing a CSRF Attack

There are several methods for strengthening your Web应用程序安全性 program so that you will be less vulnerable to a potential CSRF attack. As with other Web应用程序安全性 measures, 最好的防御包括定期扫描和测试web应用程序的安全性:

Make sure your web application has CSRF protection

If your web application does not currently have CSRF protection, it could be vulnerable to this form of attack. Web应用程序安全工具可以帮助您快速确定Web应用程序中是否存在此类漏洞,并为您提供修复该问题的步骤.

Use advanced validation techniques to reduce CSRF

通过为可能访问您站点上页面的任何人设置高级验证技术,您可以帮助降低CSRF攻击的可能性, especially if you are operating a social media or community site. CSRF令牌, 有时也被称为反CSRF令牌,因为它们旨在转移CSRF攻击, 有这样一个例子吗?. 通常 comprised of a large, 对单个会话和用户都唯一的随机数串, 它们使攻击者更难以猜测创建有效请求所需的正确令牌. 

通过在表单提交和副作用url中实现CSRF令牌, 您可以更好地确保每个表单提交或请求都与经过身份验证的用户绑定,并屏蔽潜在的CSRF攻击. In cases involving highly sensitive operations, OWASP 请注意,您可能还需要考虑实现基于用户交互的保护(重新身份验证/一次性令牌)以及基于令牌的缓解技术.

Conduct regular Web应用程序安全性 tests to identify CSRF

即使在您成功解决了web应用程序中可能导致CSRF攻击的漏洞之后, 随着应用程序的更新和对其代码的更改,将来仍然有可能出现漏洞. 出于这个原因, 明智的做法是不断扫描和测试您的web应用程序,以查找它们可能包含的任何安全漏洞, including vulnerabilities associated with CSRF attacks, using Web应用程序安全性 tools. 

尽管CSRF攻击仅针对当前通过站点身份验证的用户, these 利用 can be devastating when successful. 然后,冒充用户的攻击者可以在用户不知情或不同意的情况下继续执行一系列操作, stealing money or committing fraud.

A company can find its reputation severely damaged as a result, 失去客户信任,在某些情况下甚至面临监管罚款. By proactively implementing a comprehensive application security program, your business can reduce the possibility of such an attack.