有没有办法阻止用户访问所有站点,而不仅仅是wp-login.php

时间:2019-01-24 09:41:24

标签: wordpress ubuntu authentication mod-security

我正在使用this article中的代码,效果很好,但是我想阻止整个网站的访问,不仅限于一页,有没有可用的方法?

使用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次时,此用户(通过IP)和仅此页面(sitename / wp-login.php)使用的mod-security阻止访问权限,但是我需要禁止整个网站。有没有办法通过此规则和modsec在没有db / .htaccess和任何其他功能的情况下做到这一点?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您可以使用限制登录尝试之类的插件,该插件将处理跟踪失败的登录并管理IP被阻止的情况。但是由于该插件只会阻止以后的登录,因此您可以添加一个基本功能,利用该插件阻止对前端的访问。

例如,在安装了“限制登录尝试”插件的情况下,将以下代码添加到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/