AWS WAF是否支持captcha验证, 使用场景如下:
保护某些敏感页面。例如/admin,/login
等
对某些国家的请求进行图形验证码认证
限制频率,比如每分钟访问频率超过N次则触发验证码机制
其他规则也可以根据需求自定义
假如公司网站上有一个简单的 Web 表单,允许用户订购该公司的软件。我们要保护该表单免遭机器人提交,同时仍然为网站访问者提供填写表单和订购的简单选项。
我们将使用AWS WAF Captcha
功能以确保只有正常用户才能访问托管在/form.php
的表单。一旦用户解决了验证码挑战,他们应该有 15 分钟的时间填写并提交表格。
为WebACL添加一条自定义规则:
规则详情:
当请求match statement时:
然后操作选择captcha:
在网页中访问form.php
, 然后将看到一个页面,要求您确认您是人类。单击开始:
显示captcha,需要进行验证:
验证成功后,会有提示:
然后将被重定向到表单页面:
如果我们使用curl直接访问form.php
会返回405:
结果中包含:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Human Verification</title>
<style>
body {
font-family: "Arial";
}
</style>
<script type="text/javascript">
window.awsWafCookieDomainList = [];
window.gokuProps = {
"key":"AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AEXzte4brnDnSysJrxEPhBnAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMyICkOyAVzcQNGCS1AgEQgDtvte97S/wtNehvevDJYkfJW1iWY0xpwfFJSmbINPA6xdkhSr+OXqm5DY0Egmf87eU6gv2F8lRmoT8v7A==",
"iv":"CgAA2DJfksAAAAIC",
"context":"TyRj3ETe441K3EOgAerPS2d7ngTTtQT08QBNmC6xFa4MlU0qXl4psuGGNHeyXX3dajnClYpnqxYr2odW1v1bzIppXc97ouwyKgAUCgNYQ1f+xge/bgU8Zgw9aFaR4c1QuIa5+iEXr5M2Wd7TqsZqCQGpf3bwiJVIZWRfdoeQLdSYZ0L2ez/4gJuxzcswSJnyoZoLC/IX+2XshY4zTrnSTTtp6e6qBHnZ7wuPuhuMYAluN5WweuyDOI3Bz4Xs6nspU5adfAnlRTglQ5e6BTEUhJqJI7osY5LILhglv0d/K32LB73etvcQ1gBKXBQHOAYTzZosuABnj7eaS83CFsjea2f3ZKAvm8IyEQ=="
};
</script>
<script src="https://d38beae4b2e0.8d80c9ff.us-east-1.token.awswaf.com/d38beae4b2e0/f4b47a4f1dd9/3b5ade700223/challenge.js"></script>
<script src="https://d38beae4b2e0.8d80c9ff.us-east-1.captcha.awswaf.com/d38beae4b2e0/f4b47a4f1dd9/3b5ade700223/captcha.js"></script>
</head>
<body>
<div id="captcha-container"></div>
<script type="text/javascript">
AwsWafIntegration.saveReferrer();
window.addEventListener("load", function() {
const container = document.querySelector("#captcha-container");
CaptchaScript.renderCaptcha(container, async (voucher) => {
await ChallengeScript.submitCaptcha(voucher);
window.location.reload(true);
}
);
});
</script>
<noscript>
<h1>JavaScript is disabled</h1>
In order to continue, you need to verify that you're not a robot by solving a CAPTCHA puzzle.
The CAPTCHA puzzle requires JavaScript. Enable JavaScript and then reload the page.
</noscript>
参考:
https://docs.aws.amazon.com/waf/latest/developerguide/waf-captcha-challenge.html