Evening all,
I've been tinkering with fail2ban on my RasPi server. I'd like to use it with a WordPress plugin called "WP fail2ban" so that login attempts are written to a log file and fail2ban can monitor them.
The problem is: successful login attempts are logged, but unsuccessful attempts are not!
Here's an example:
...and here's the plugin's PHP code.
I looked up syslog in the PHP manual (here) which says that LOG_NOTICE has a higher priority than LOG_INFO. If anything, based on the PHP above I'd expect only the unsuccessful logins to appear in /var/log/auth.log if the log level was set to ignore the lower priority stuff.
I've also checked syslog to see if there was anything in there... no dice.
Can anyone with a little knowledge of PHP help me out?
Thanks,
Feathers
I've been tinkering with fail2ban on my RasPi server. I'd like to use it with a WordPress plugin called "WP fail2ban" so that login attempts are written to a log file and fail2ban can monitor them.
The problem is: successful login attempts are logged, but unsuccessful attempts are not!
Here's an example:
Code:
#/var/log/auth.log Jan 17 18:57:37 samhobbs wordpress(www.samhobbs.co.uk)[18819]: Accepted password for USERNAME from 192.168.1.1
Code:
<?php /* Plugin Name: WP fail2ban Plugin URI: https://charles.lecklider.org/wordpress/wp-fail2ban/ Description: Write all login attempts to syslog for integration with fail2ban. Version: 2.1.0 Author: Charles Lecklider Author URI: https://charles.lecklider.org/ License: GPL2 */ /* Copyright 2012-13 Charles Lecklider (email : wordpress@charles.lecklider.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace org\lecklider\charles\wp_fail2ban; function openlog() { \openlog('wordpress('.$_SERVER['HTTP_HOST'].')', LOG_NDELAY|LOG_PID, defined(WP_FAIL2BAN_LOG) ? WP_FAIL2BAN_LOG : LOG_AUTH); } function bail() { ob_end_clean(); header('HTTP/1.0 403 Forbidden'); header('Content-Type: text/plain'); exit('Forbidden'); } function remote_addr() { if (defined('WP_FAIL2BAN_PROXIES')) { if (array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER)) { $ip = ip2long($_SERVER['REMOTE_ADDR']); foreach(explode(',',WP_FAIL2BAN_PROXIES) as $proxy) { if (2 == count($cidr = explode('/',$proxy))) { $net = ip2long($cidr[0]); $mask = ~ ( (2 ^ (32 - $cidr[1])) - 1 ); } else { $net = ip2long($proxy); $mask = -1; } if ($net == $ip & $mask) { return (false===($len = strpos($_SERVER['HTTP_X_FORWARDED_FOR'],','))) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : substr($_SERVER['HTTP_X_FORWARDED_FOR'],0,$len); } } } } return $_SERVER['REMOTE_ADDR']; } if (defined('WP_FAIL2BAN_BLOCKED_USERS')) { add_action( 'authenticate', function($user, $username, $password) { if (!empty($username) && preg_match('/'.WP_FAIL2BAN_BLOCKED_USERS.'/i', $username)) { openlog(); \syslog(LOG_NOTICE,"Blocked authentication attempt for $username from ".remote_addr()); bail(); } return $user; },1,3); } if (defined('WP_FAIL2BAN_BLOCK_USER_ENUMERATION')) { add_filter( 'redirect_canonical', function($redirect_url, $requested_url) { if (intval(@$_GET['author'])) { openlog(); \syslog(LOG_NOTICE,'Blocked user enumeration attempt from '.remote_addr()); bail(); } return $redirect_url; },10,2); } add_action( 'wp_login', function($user_login, $user) { openlog(); \syslog(LOG_INFO,"Accepted password for $user_login from ".remote_addr()); },10,2); add_action( 'wp_login_failed', function($username) { openlog(); \syslog(LOG_NOTICE,"Authentication failure for $username from ".remote_addr()); });
I've also checked syslog to see if there was anything in there... no dice.
Can anyone with a little knowledge of PHP help me out?
Thanks,
Feathers
Comment