wordpress - 有没有办法阻止用户访问所有站点,而不仅仅是 wp-login.php
问题描述
我使用这篇文章中的代码,效果很好,但我想阻止整个网站的访问,而不仅仅是一页,有什么可用的方法吗?
使用 Ubuntu、php7、mod-security2。
代码:
<Locationmatch "/wp-login.php">
# Setup brute force detection.
# React if block flag has been set.
SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000135,msg:'ip address blocked for 5 minutes, more than 10 login attempts in 3 minutes.'"
# Setup Tracking. On a successful login, a 302 redirect is performed, a 200 indicates login failed.
SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.bf_counter=0,id:5000136"
SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,setvar:ip.bf_counter=+1,deprecatevar:ip.bf_counter=1/180,id:5000137"
SecRule ip:bf_counter "@gt 10" "t:none,setvar:user.bf_block=1,expirevar:user.bf_block=300,setvar:ip.bf_counter=0"
</Locationmatch>
当任何站点用户尝试在 3 分钟内使用错误凭据登录 10 次时地点。有没有办法通过这个规则和没有 db/.htaccess 和任何其他功能的 modsec 来做到这一点?
谢谢你的帮助。
解决方案
您可以使用像限制登录尝试这样的插件,它可以处理跟踪失败的登录,并管理被阻止的 IP。但由于插件只会阻止未来的登录,您可以添加一个基本功能,利用插件来阻止对前端的访问。
例如,安装了 Limit Login Attempts 插件后,将以下代码添加到 functions.php 中 - 并进行您想要的任何更改。
add_action('template_redirect', 'checkIfLockedOut');
function checkIfLockedOut(){
if(function_exists('is_limit_login_ok')){
$isNotLockedOut = is_limit_login_ok();
if(!$isNotLockedOut){
// you could wp_redirect here,
// or do what you'd like.
die('Sorry, you cannot access the site, you are locked out!');
}
}
}
推荐阅读
- ios - 线程 1:致命错误:单击 collectionview 项目时索引超出范围
- sql - 建议提高查询性能 (Oracle)
- jq - 如何使用 jq 查找多个输出对象之一的计数
- android - 由于 firebase-auth 依赖,Gradle 构建失败
- ssas - DAX Studio 中的 YTD Measure 未显示多个日期的任何值
- networking - 是否可以通过 OpenvSwitch 识别通过蓝牙连接的设备
- telegram - 如何在电报中获取自定义更新
- android - 在初始化中触发微调器选定的项目更改事件
- qt - QT 优化程序以特定时间间隔执行计算(信号和 QTimer 已过)
- perforce - 如何在 P4v 中更改我的工作区名称?