偵測並防範帳戶盜用

本頁說明如何使用 reCAPTCHA 偵測及防範帳戶盜用 (ATO) 行為。

發生帳戶盜用攻擊時,攻擊者通常會使用從資料侵害事件取得的憑證 (也稱為密碼傾印),向 API 端點傳送登入要求。即使密碼傾印來自不相關的網站,這類攻擊仍可能成功,因為使用者往往會在多個帳戶中重複使用密碼。只要使用者養成良好的密碼習慣 (例如使用密碼管理工具),就不會受到這類攻擊影響。

事前準備

準備 reCAPTCHA 環境

偵測並防範帳戶盜用

您可以透過 reCAPTCHA 偵測及防範帳戶盜用,方法如下:

使用「我不是機器人」核取方塊

在網站上新增「我不是機器人」核取方塊,是防範帳戶盜用的最快速簡單方法,不必整合簡訊或電子郵件驗證等額外功能。攻擊者必須付出代價才能破解這項防護機制,因此對某些網站來說,這個選項可能就已足夠。

在網頁上新增「我不是機器人」核取方塊

以下程式碼是受核取方塊保護的登入頁面即時範例:

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,也可以搭配根據分數的密鑰。舉例來說,您可能只想針對低於特定門檻的分數使用多重驗證挑戰,以減少阻力。

以下範例說明如何在登入情境中整合以分數為準的索引鍵。

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>

後續步驟