Skip to content

Instantly share code, notes, and snippets.

@rutger1140
Created October 2, 2014 13:11
Show Gist options
  • Save rutger1140/a47d2aacab6cb5de68de to your computer and use it in GitHub Desktop.
Save rutger1140/a47d2aacab6cb5de68de to your computer and use it in GitHub Desktop.
ModSecurity - block WordPress brute force hack attempts - Plesk 12
# /etc/httpd/modsecurity.d/wordpress.conf
# This has to be global, cannot exist within a directory or location clause
SecAction phase:1,log,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:1
<Location /wp-login.php>
# Setup brute force detection.
# React if block flag has been set.
SecRule user:bf_block "@gt 0" "deny,status:401,log,msg:'ip address blocked for 60 minutes, more than 15 login attempts in 3 minutes.',id:2"
# Setup Tracking. On a successful login, a 302 redirect is performed, a 200 indicates login failed.
SecRule RESPONSE_STATUS "^302" "phase:5,t:none,log,pass,setvar:ip.bf_counter=0,id:3"
SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,log,pass,setvar:ip.bf_counter=+1,deprecatevar:ip.bf_counter=1/180,id:4"
SecRule ip:bf_counter "@gt 15" "t:none,setvar:user.bf_block=1,expirevar:user.bf_block=3600,setvar:ip.bf_counter=0"
</Location>
@rutger1140
Copy link
Author

This is placed in Plesk -> ModSecurity -> Settings down the bottom of the page.
It will block an IP address for an hour if the user has 15 false login attempts in 3 minutes.

Fail2Ban version:
https://gist.github.com/lekkerduidelijk/f7db76e3e0af8f07f681

@rutger1140
Copy link
Author

In the ModSecurity log file I found this warning:

ModSecurity: Warning. Unconditional match in SecAction. [file "/etc/httpd/conf/plesk.conf.d/modsecurity.conf"] [line "4"] 

It is regarding line 4. I'm not sure how to prevent this yet.

@rcbarnett-zz
Copy link

If you want to get rid of that log Warning message, use "nolog" action to like 4 -

SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment