首页 > 解决方案 > 有没有办法阻止用户访问所有站点,而不仅仅是 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 来做到这一点?

谢谢你的帮助。

标签: wordpressubuntuauthenticationmod-security

解决方案


您可以使用像限制登录尝试这样的插件,它可以处理跟踪失败的登录,并管理被阻止的 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!');
    }
  }
}

https://wordpress.org/plugins/limit-login-attempts/


推荐阅读