Since you mention blocking access of scripts to wp-content
's PHP scripts...
It would be quite a valid statement that the majority of good plugins will execute only through WordPress's front controller (/index.php
) and have nice SEO URLs.
A good plugin would not allow its execution from links of sort /wp-content/plugins/<foo>/<foo|bar|blah>.php
. The ones that do, are "bad", or badly coded :-).
So if you keep your plugin base clean, you don't have such plugins and can deem any requests to /wp-content/*.php
malicious.
Blocking those can be done automatically, but Fail2Ban won't be quite a good choice there because it needs to scan through the logs first. Instead, why not route such malicious requests directly to a script which automatically bans such IPs in the firewall. No log scanning, immediate blocking.
I have covered this approach in honeypot blocking and last paragraphs of secure NGINX configuration for WordPress:
location /wp-content/ {
# other PHP files cause automatic ban:
location ~ .php$ {
include includes/honeypot.conf;
}
}
Unfortunately, the honeypot article is for FirewallD but you can easily adopt it to whatever other firewalls there in other distros.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…