检测并防范账号盗用

本页面介绍了如何使用 reCAPTCHA Enterprise 检测和防范账号盗用 (ATO)。

当攻击者使用从数据泄露获得的凭据(也称为密码转储)发送登录 API 端点的请求时,通常会发生 ATO 攻击。即使密码转储来自一个不相关的网站,这种类型的攻击也可成功,因为人们倾向于在多个账号之间重用密码。这种类型的攻击不会影响采用适当的密码安全性(例如,使用密码管理器)的用户。

准备工作

为 reCAPTCHA Enterprise 准备好环境

检测和预防 ATO

借助 reCAPTCHA Enterprise,您可以通过以下任一选项检测并阻止 ATO:

使用“进行人机身份验证”复选框

向您的网站添加“我不是机器人”复选框是在一定程度上防范 ATO 的最快速、最简单方法,且无需集成诸如短信或电子邮件验证之类的附加功能。攻击者必须付出一定的代价才能突破此保护,对于某些网站来说,这个方案就已足够。

在您的网页上添加“我不是机器人”复选框

以下代码是受复选框保护的简单登录页面的实际示例:

function onSuccess(token) {
  // The token is included in the POST data in the g-recaptcha-response
  // parameter. The backend must create an Assessment with the token
  // and verify the token is valid.
  console.log(token);
}
<form id="loginForm" action="?" method="POST">
  Username: <input type="text" name="username"/><br/>
  Password: <input type="password" name="password"/><br/>
  <div class="g-recaptcha" data-sitekey="reCATCHA_sitekey"
       data-action="account_login" data-callback="onSuccess"></div>
</form>
<script src="https://www.google.com/recaptcha/enterprise.js" async defer></script>

您可以通过单击代码窗口右上角的 <> 图标,在 JSFiddle 中尝试此代码。

<html>
  <head>
    <title>Account Login - Checkbox</title>
    <script src="https://www.google.com/recaptcha/enterprise.js" async defer></script>
    <script>
    function onSuccess(token) {
      // The token is included in the POST data in the g-recaptcha-response
      // parameter. The backend must create an Assessment with the token
      // and verify the token is valid.
      console.log(token);
    }
    </script>
  </head>
  <body>
    <form id="loginForm" action="?" method="POST">
      Username: <input type="text" name="username"/><br/>
      Password: <input type="password" name="password"/><br/>
      <div class="g-recaptcha" data-sitekey="6LeAkOgUAAAAACcy3uY6N9H9SJMS27n3Zx2OOnYK"
           data-action="account_login" data-callback="onSuccess"></div>
    </form>
  </body>
</html>

使用分数和自定义挑战

要防范 ATO,请使用基于 reCAPTCHA 分数的密钥和多重身份验证 (MFA) 验证,例如通过电子邮件和短信验证的方式,系统会向用户发送动态验证码 (OTP)。

如需使用基于得分的键和自定义验证,请考虑以下选项:

根据您的使用场景,您可以单独使用 MFA,也可以将 MFA 与基于得分的密钥搭配使用。例如,您可能希望仅对低于特定阈值的得分使用 MFA 质询,以减少摩擦。

以下示例展示了如何在登录场景中集成基于得分的密钥。

function submitForm() {
  grecaptcha.enterprise.ready(function() {
    grecaptcha.enterprise.execute(
      'reCAPTCHA_site_key', {action: 'account_login'}).then(function(token) {
       document.getElementById("token").value = token;
       document.getElementByID("loginForm").submit();
    });
  });
}
<form id="loginForm" action="?" method="POST">
  Username: <input type="text" name="username"/><br/>
  Password: <input type="password" name="password"/><br/>
  <input type="hidden" id="token" name="recaptcha_token"/>
  <button onclick="submitForm()">Login</button>
</form>
<script src="https://www.google.com/recaptcha/enterprise.js" async defer></script>

您可以通过单击代码窗口右上角的 <> 图标,在 JSFiddle 中尝试此代码。

<html>
  <head>
    <title>Account Login - Score</title>
    <script src="https://www.google.com/recaptcha/enterprise.js" async defer></script>
    <script>
    function submitForm() {
      grecaptcha.enterprise.ready(function() {
        grecaptcha.enterprise.execute(
          'reCAPTCHA_site_key', {action: 'account_login'}).then(function(token) {
           document.getElementById("token").value = token;
           document.getElementByID("loginForm").submit();
        });
      });
    }
    </script>
  </head>
  <body>
    <form id="loginForm" action="?" method="POST">
      Username: <input type="text" name="username"/><br/>
      Password: <input type="password" name="password"/><br/>
      <input type="hidden" id="token" name="recaptcha_token"/>
      <button onclick="submitForm()">Login</button>
    </form>
  </body>
</html>

后续步骤