Well, I never really ‘got’ the block editor (Gutenberg – wordpress block editor) – probably due to a lack of use … so I’ve moved this site over to ClassicPress
( thank you LWN – ClassicPress article )
Linux, PHP, geeky stuff … boring man.
Well, I never really ‘got’ the block editor (Gutenberg – wordpress block editor) – probably due to a lack of use … so I’ve moved this site over to ClassicPress
( thank you LWN – ClassicPress article )
I used to have a fail2ban filter etc setup to look for POST requests to wp-login.php; but the size of the Apache log files on one server made this infeasible (it took fail2ban too long to parse/process the files). Also, doing a filter on the Apache log file looking for POST /wp-login … means you are also catching someone successfully logging in.
Perhaps this is a better approach :
Assumptions
error_log = /var/log/php.log
Put this in … /path/to/your/site/wp-content/mu-plugins/log-auth-failures.php
(It must be wp-content/mu-plugins … )
<?php
add_action( ‘wp_login_failed’, ‘login_failed’ );
function login_failed( $username ) {
error_log(“WORDPRESS LOGIN FAILURE {$_SERVER[‘REMOTE_ADDR’]} – user $username from ” . __FILE__);
}
(Yes, obviously you don’t have to use error_log, you could do something else, and there’s a good argument not to log $username as it’s ultimately user supplied data that might just mess things up)
Then in /etc/fail2ban/jail.d/wordpress-login.conf :
[wordpress-login]
enabled = true
filter = wordpress-login
action = iptables-multiport[name=wp, port="80,443", protocol=tcp]
logpath = /var/log/php.log
maxretry = 5
If you have PHP logging somewhere else, change the logpath appropriately.
Finally in /etc/fail2ban/filter.d/wordpress-login.conf put :
[Definition]
# PHP error_log is logging to /var/log/php.log something like :
#[31-Jan-2024 20:34:10 UTC] WORDPRESS LOGIN FAILURE 1.2.3.4 - user admin.person from /var/www/vhosts/mysite/httpdocs/wp-content/mu-plugins/log-auth-failures.php
failregex = WORDPRESS LOGIN FAILURE <HOST> - user
ignoreregex =
Extra bonus points for making the failregex stricter, or stop including $username in the log output (which perhaps makes it vulnerable to some sort of injection attack).
There’s probably a good argument for using a different file (not the PHP error_log) so other random error messages can’t confuse fail2ban, which might also allow you to specify a more friendly date format for fail2ban etc….
Restart fail2ban and watch it’s log file (and /var/log/php.log).
service fail2ban restart
Just a random post about a WordPress plugin (hotel booking).
For the site in question, I have a script running which alerts me to any long running (>600s) MySQL queries (or causes of deadlock) and attempts to kill them. When it does this it emails me….
So, the site/MySQL was trying to run queries like this :
DELETE FROM wp_mphb_sync_logs WHERE queue_id IN (SELECT queue_id FROM wp_mphb_sync_queue WHERE queue_name < '1639573980');
which I did an explain, it showed there were > 5 million rows to examine (none of which are actually deleted by the query, so I assume the 5 million rows are all for now invalid queue_id entries).
Adding an index on the wp_mphb_sync_logs.queue_id field didn’t really help speed up the delete … and googling around and checking the plugin’s source code, led me to think it was safe (enough) to do a ‘TRUNCATE wp_mphb_sync_logs
‘.
Now that’s done the table has remained empty 12 hours later; so I think everything’s fine.
This post is mostly because the plugin’s forum requires a paid membership to contribute; and I’m not paying $400 just to post “doing this worked for me”.
Arbitrary tweets made by TheGingerDog up to 22 November 2020
Continue reading “Automated twitter compilation up to 22 November 2020”
Arbitrary tweets made by TheGingerDog up to 21 January 2018
Continue reading “Automated twitter compilation up to 21 January 2018”
Arbitrary tweets made by TheGingerDog up to 24 July 2016
Continue reading “Automated twitter compilation up to 24 July 2016”
Fed up installing updates to WordPress sites? Stick this in a cron job somewhere, and cross your fingers (a little)…. Continue reading “Lazy wordpress updating using wp-cli.phar”
I came across the varnish throttle module the other day – which seems quite useful – and certainly gives better control over abusive requests than using fail2ban (in that, only specific URLs/request types can be targeted and blocked with the throttle module, while fail2ban tends to trigger the blocking of any traffic from a client which can be more painful).
Continue reading “varnish throttling”
WordPress seems to like hiding a load of ‘transient’ (cacheable) stuff in it’s wp_options table. Unfortunately for one site, it seems it didn’t bother to clean up the transient stuff, leaving behind about 750,000 records… which made a WP version upgrade painful, as MySQL locks the wp_option table which causes all other page loads to get stuck waiting (and the site to stop working).
Fix / hacky solution after the ‘more’…
Continue reading “Cleaning up a lot of WordPress _transients”
Arbitrary tweets made by TheGingerDog up to 18 January 2015
Continue reading “Automated twitter compilation up to 18 January 2015”