Fail2ban and firewall problem  [SOLVED]

Discussions about the usage of KeyHelp.
Post Reply
lmarcos
Posts: 84
Joined: Sun 26. Jan 2020, 12:55

Fail2ban and firewall problem

Post by lmarcos »

My server has recently seen an abnormal increase in input and output network traffic (and increasing CPU usage and rendering the sites unusable) and when I was reviewing settings, I've seen that there's only one banned IP in the firewall and nothing on fail2ban, when last time I checked there was a bunch.

But now, Active jails and amount of banned IP addresses: kh-phpmyadmin (0x), sshd (0x)
- No entries available -

Any ideas what can I do for fail2ban to start banning ips again?
User avatar
Daniel
Keyweb AG
Posts: 136
Joined: Mon 25. Jan 2016, 04:42

Re: Fail2ban and firewall problem

Post by Daniel »

Hello,

could you determine at first what type of traffic increased in general?
Do you recognize any hints at the logs?
Mit freundlichen Grüßen / Best regards
Daniel Marckardt

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
https://www.keyweb.de - https://www.keyhelp.de
**************************************************************
lmarcos
Posts: 84
Joined: Sun 26. Jan 2020, 12:55

Re: Fail2ban and firewall problem

Post by lmarcos »

Traffic in general, but unrelated to the main content, since it comes from several different countries (from China to Russia to Sweden) and they're also requesting pages that do not exist. I've shown the log, or part of it, to an acquaintance and he told me somebody might be scrapping the site to train an AI.
User avatar
Daniel
Keyweb AG
Posts: 136
Joined: Mon 25. Jan 2016, 04:42

Re: Fail2ban and firewall problem

Post by Daniel »

Hello,

is there a potential similarity, like user-agent?
"ClaudeBot" e.g. is currently often around with aggressive crawls.

You could limit them or other "unwanted" user-agents using "rewrite" rules at the virtual host of apache. Or if its too much, implement a countryfilter for 80/443 tcp @iptables/ipset.
Mit freundlichen Grüßen / Best regards
Daniel Marckardt

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
https://www.keyweb.de - https://www.keyhelp.de
**************************************************************
lmarcos
Posts: 84
Joined: Sun 26. Jan 2020, 12:55

Re: Fail2ban and firewall problem  [SOLVED]

Post by lmarcos »

Claudebot, Bytespider and facebookexternalhit were the culprits. Thanks for pointing me in the right direction. Still, I don't get why these agressive bots are not jailed by fail2ban. But that is not keyhelp related.
User avatar
Daniel
Keyweb AG
Posts: 136
Joined: Mon 25. Jan 2016, 04:42

Re: Fail2ban and firewall problem

Post by Daniel »

Hello,

there are no rules to turn down legitimate bots that are crawling websites. They are basically seen as normal usertraffic.
Of course its possible to block them with fail2ban, but its very inefficent. Best options are rules according to robots.txt or if they do not comply with, block the user-agents with re-write rules or throttle them with a rate-limit on application layer. WIth nginx done through "limit_req" analogous to apache mod_qos. mod_evasive is not useful since there is no user-agent matching option.
Mit freundlichen Grüßen / Best regards
Daniel Marckardt

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
https://www.keyweb.de - https://www.keyhelp.de
**************************************************************
User avatar
Jolinar
Community Moderator
Posts: 4004
Joined: Sat 30. Jan 2016, 07:11
Location: Weimar (Thüringen)
Contact:

Re: Fail2ban and firewall problem

Post by Jolinar »

lmarcos wrote: Wed 15. May 2024, 09:59 I don't get why these agressive bots are not jailed by fail2ba
You could customize the file /etc/fail2ban/filter.d/apache-badbots.conf to suit your needs.
Wenn jemand inkompetent ist, dann kann er nicht wissen, daß er inkompetent ist. (David Dunning)

Data Collector für Community Support
___
Ich verwende zwei verschiedene Schriftfarben in meinen Beiträgen /
I use two different font colors in my posts:
  • In dieser Farbe schreibe ich als Moderator und gebe moderative Hinweise oder begründe moderative Eingriffe /
    In this color, I write as a moderator and provide moderative guidance or justify moderative interventions
  • In dieser Farbe schreibe ich als Community Mitglied und teile meine private Meinung und persönlichen Ansichten mit /
    In this color, I write as a community member and share my personal opinions and views
User avatar
Ralph
Posts: 1245
Joined: Mon 30. Mar 2020, 16:14

Re: Fail2ban and firewall problem

Post by Ralph »

lmarcos wrote: Wed 15. May 2024, 09:59 Claudebot, Bytespider and facebookexternalhit were the culprits. Thanks for pointing me in the right direction. Still, I don't get why these agressive bots are not jailed by fail2ban. But that is not keyhelp related.

You should use a custom filter and expand it accordingly ... will not be overwritten (F2B updates).
e.g.

Code: Select all

nano /etc/fail2ban/filter.d/my-badbots.conf
# add:

# Fail2Ban configuration file
#
# Regexp to catch specific spambots

[Definition]

failregex = ^<HOST>.*ahrefs\.com.*
            ^<HOST>.*PetalBot.*
            ^<HOST>.*ClaudeBot.*
            ^<HOST>.*claudebot.*
            ^<HOST>.*Bytespider.*
            ^<HOST>.*bytedance\.com.*
            ^<HOST>.*BLEXBot.*
            ^<HOST>.*facebookexternalhit.*

ignoreregex =

Code: Select all

nano /etc/fail2ban/jail.d/my-badbots.local
# add:

[my-badbots]

enabled  = true
port     = http,https
filter   = my-badbots
logpath = /home/users/*/logs/*/access.log
maxretry = 1
findtime  = 1800
bantime  = 48h
lmarcos
Posts: 84
Joined: Sun 26. Jan 2020, 12:55

Re: Fail2ban and firewall problem

Post by lmarcos »

Thanks to all. I didn't see the last two replies until now. What I did after Daniel pointed me to Claudebot was to ban them in robots.txt. At least that's what I think I did.
Post Reply