本页面介绍了如何使用 Google Cloud Fraud Defense 检测和防范账号入侵 (ATO)。
ATO 攻击通常发生在攻击者使用从数据泄露(也称为密码转储)中获取的凭据向登录 API 端点发送请求时。即使密码转储来自一个不相关的网站,这种类型的攻击也可成功,因为人们倾向于在多个账号之间重用密码。此类攻击不会影响采取适当密码安全措施(例如使用密码管理工具)的用户。
准备工作
为 Google Cloud Fraud Defense 准备好环境。
检测并防范 ATO
借助 Fraud Defense,您可以使用以下选项之一检测和防范 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,请使用基于 Fraud Defense 得分的密钥,并使用多重身份验证 (MFA) 质询,例如电子邮件和短信质询(其中一次性验证码 [OTP] 会发送给用户)。
如需使用基于得分的密钥和自定义挑战,请考虑以下选项:
安装基于得分的密钥,以检测大规模 ATO 中的自动化操作。
如需在网页上安装基于得分的密钥,请参阅在网页上安装基于得分的密钥。
如需在移动应用上安装基于得分的密钥,请参阅将 Fraud Defense 与 Android 应用集成或将 Fraud Defense 与 iOS 应用集成。
使用 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>后续步骤
- 如需了解其他账号保护功能,请参阅用户账号保护功能。