Go to Networking ⇾ Fail2Ban Intrusion Detector: Filter Action Jails page;
Click Add a new jail button;
Fill the following fields:
6.1. Jail name : wordpress-domain-com;
6.2. Filter to search log for: wordpress;
6.3. Currently enabled? set to Yes;
6.4. Log file paths:
/var/log/virtualmin/domain.com_access_log
6.5. Click Create button;
Enjoy, and please let’s close this thread already!
Note: A backend may need to be manually defined as described in this comment.
Thank you very much Ilia for providing us with that need solution.
Has anybody else implemented it?
After 48 h my wordpress-domain-com jail remains empty even though I have in the logs many xmlrpc.php and wp-login.php lines. I am not sure if the filter-action-jail is reading my logs. I added all my xyz.com_access_log files of all my domains running on this server there, one per line. How can I proof if they are read at all?
Well, all my jails are empty in the UI. When I print the database I can see some dovecot sinners. So I might have another problem.
But I am sure this is the solution. If anybody else can give confirmation of its functionality we can close the thread.
[root@hostname ~]# fail2ban-client status wordpress-domain-com
Status for the jail: wordpress-domain-com
|- Filter
| |- Currently failed: 0
| |- Total failed: 13341
| `- File list: /var/log/virtualmin/domain.com_access_log
`- Actions
|- Currently banned: 0
|- Total banned: 221
`- Banned IP list:
@Ilia
I have added this filter but it doesn’t work correctly with [recidive]
Once the Ip has been banned and found by by [recidive] it errors the wordpress filter for that IP.
2024-05-03 07:52:06,324 fail2ban.actions [790]: NOTICE [recidive] Unban 103.10.44.7
2024-05-03 07:52:06,150 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 198.12.236.217 - 2024-05-03 07:52:06
2024-05-03 07:52:05,373 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 92.205.168.116 - 2024-05-03 07:52:05
2024-05-03 07:52:01,192 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 107.190.135.10 - 2024-05-03 07:52:01
2024-05-03 07:51:57,757 fail2ban.actions [790]: NOTICE [wordpress-ilikebicycles-com] 35.214.190.212 already banned
2024-05-03 07:51:57,731 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 35.214.190.212 - 2024-05-03 07:51:57
2024-05-03 07:51:52,921 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 35.214.190.212 - 2024-05-03 07:51:52
2024-05-03 07:51:50,197 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 194.163.128.165 - 2024-05-03 07:51:50
2024-05-03 07:51:49,032 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 46.229.230.81 - 2024-05-03 07:51:48
2024-05-03 07:51:43,528 fail2ban.actions [790]: ERROR Failed to execute ban jail 'wordpress-ilikebicycles-com' action 'firewallcmd-ipset' info 'ActionInfo({'ip': '35.214.190.212', 'family': 'inet4', 'fid': <function Actions.ActionInfo.<lambda> at 0x7fc9dc20d630>, 'raw-ticket': <function Actions.ActionInfo.<lambda> at 0x7fc9dc20dcf0>})': Error starting action Jail('wordpress-ilikebicycles-com')/firewallcmd-ipset: 'Script error'
2024-05-03 07:51:43,527 fail2ban.utils [790]: ERROR 7fc9dccfb8a0 -- returned 13
2024-05-03 07:51:43,527 fail2ban.utils [790]: ERROR 7fc9dccfb8a0 -- stderr: ''
2024-05-03 07:51:43,527 fail2ban.utils [790]: ERROR 7fc9dccfb8a0 -- stderr: "Try `iptables-restore -h' or 'iptables-restore --help' for more information."
2024-05-03 07:51:43,527 fail2ban.utils [790]: ERROR 7fc9dccfb8a0 -- stderr: 'Error occurred at line: 2'
2024-05-03 07:51:43,527 fail2ban.utils [790]: ERROR 7fc9dccfb8a0 -- stderr: "Error: COMMAND_FAILED: '/usr/sbin/iptables-restore -w -n' failed: iptables-restore v1.8.7 (nf_tables): invalid port/service `0-65535' specified"
2024-05-03 07:51:43,526 fail2ban.utils [790]: ERROR 7fc9dccfb8a0 -- stderr: 'ipset v7.15: Set cannot be created: set with the same name already exists'
firewall-cmd --direct --add-rule ipv4 filter INPUT_direct 0 -p tcp -m multiport --dports "$(echo '0:65535' | sed s/:/-/g)" -m set --match-set f2b-wordpress-ilikebicycles-com src -j REJECT --reject-with icmp-port-unreachable
2024-05-03 07:51:43,524 fail2ban.utils [790]: ERROR 7fc9dccfb8a0 -- exec: ipset create f2b-wordpress-ilikebicycles-com hash:ip timeout 0
2024-05-03 07:51:43,118 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 2a01:4f8:1c1e:4404::1 - 2024-05-03 07:51:43
2024-05-03 07:51:42,992 fail2ban.filter [790]: INFO [recidive] Found 35.214.190.212 - 2024-05-03 07:51:42
2024-05-03 07:51:42,982 fail2ban.actions [790]: NOTICE [wordpress-ilikebicycles-com] Ban 35.214.190.212
2024-05-03 07:51:42,781 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 35.214.190.212 - 2024-05-03 07:51:42
2024-05-03 07:51:42,643 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 35.214.190.212 - 2024-05-03 07:51:42
2024-05-03 07:51:33,114 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 185.141.171.198 - 2024-05-03 07:51:33
2024-05-03 07:51:32,817 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 161.132.40.116 - 2024-05-03 07:51:32
2024-05-03 07:51:29,548 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 103.145.50.69 - 2024-05-03 07:51:29
2024-05-03 07:51:26,045 fail2ban.filter [790]: INFO [wordpress-ilikebicycles-com] Found 194.5.237.145 - 2024-05-03 07:51:25
2024-05-03 07:51:25,029 fail2ban.actions [790]: NOTICE [recidive] Ban 192.3.176.170
2024-05-03 07:51:24,875 fail2ban.filter [790]: INFO [recidive] Found 192.3.176.170 - 2024-05-03 07:51:24
That’s odd, as recidive should check for entries in /var/log/fail2ban.log file, and I can see WordPress bans in fail2ban.log file in our system. I’m not sure what’s wrong on your side; try to increase the log level to get more perspective.
I have re-run tests and sadly, a backend needs to be additionally defined on some OS. For example, if you add to the jail.local file, under [wordpress-domain-com]:
backend = auto
…restart Fail2Ban, then it starts to work as expected!
@Jamie, I’m thinking of adding a backend dropdown (i.e. Check for log file updates using) to the Filter Action Jails page, similarly to what I previously added for the Default Jail Options page.
It has to be manually set to a non-default value in some cases for a jail to work correctly, for example, with custom Apache log files.
Furthermore, we need the port option to also be available from the Filter Action Jails page, to apply a block for specific port(s) only!