On 1/9/20 2:08 AM, Pete Biggs wrote:>> Has anyone created a fail2ban filter for this type of attack? As of >> right now, I have manually banned a range of IP addresses but would >> like to automate it for the future. >> > As far as I can see fail2ban only deals with hosts and not networks - I > suspect the issue is what is a "network": It may be obvious to you > looking at the logs that these are all related, but you run the risk > that getting denied accesses from, say, 1.0.0.1 and 1.1.0.93 and > 1.2.0.124 may be interpreted as a concerted attack and you banning half > the internet - but that may not be a bad thing :-) > > What I've done in times of trouble is to be a bit more aggressive in > why and how hosts are banned. It depends on how you are being attacked, > but setting the threshold to 1 or 2 failures resulting in a ban and > then setting the ban time to something fairly short. Repeat offenders > will then quickly be picked up by the recidive filter and permanently > banned. > > A downside to this is that your firewall filters get very large and > things will inevitably slow down, but it will at least give you the > chance to manually block a whole range but still give you a level of > automated protection. > > P. > > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centosSince you can configure fail2ban to invoke scripts, I would think it would be possible to get it to block CIDRs (variable size subnets, i.e. 12.12.0.0/20).? That said, I don't have a quick and easy implementation on hand. One thing that has proven useful to me in dealing with these kind of attacks is to lookup the route for the specified IP address in the Internet routing tables and then block the entire CIDR block.? You can also determine which autonomous system (AS number) the attack is coming from and block other routes owned by that provider.? Other options include determining the GEOIP location, i.e. country of origin of the attacks and block by country. "whois 12.12.12.12" will also provide useful information about the CIDR block that you are dealing with. To look up routes on the Internet, connect to one of the route views servers, such as this: $ telnet route-server.ip.att.net Follow login instructions provided in login banner, then give the command: show route 12.12.12.12 and it will show you that this IP is part of the larger cidr block 12.12.0.0/20.? So block 12.12.0.0/20 instead of just one IP (assuming your attacks are coming from a particular block. You'll have to consider weather the cidr block that you are considering blocking will impact your users or not. The att route-server is a juniper.? Some route servers are Cisco's and there you would use commands like: show ip route 12.12.12.12 or show ip bgp 12.12.12.12 An example of a cisco based route server would be to: telnet route-views.routeviews.org http://routeviews.org/ lists a bunch of route views servers down near the bottom, which appear to be accessable by telnet.? Note, quagga based route servers are open source immitations of the Cisco command interface and have similar commands to the cisco's. Nataraj
> > > > > As far as I can see fail2ban only deals with hosts and not networks - I > > suspect the issue is what is a "network": It may be obvious to you > > looking at the logs that these are all related, but you run the risk > > that getting denied accesses from, say, 1.0.0.1 and 1.1.0.93 and > > 1.2.0.124 may be interpreted as a concerted attack and you banning half > > the internet - but that may not be a bad thing :-) > > > > Since you can configure fail2ban to invoke scripts, I would think it > would be possible to get it to block CIDRs (variable size subnets, i.e. > 12.12.0.0/20). That said, I don't have a quick and easy implementation > on hand.The OP was looking for an automated way of fail2ban doing it - he had already sorted out the network range and had stopped this particular DoS attack. P.
Joakim Dellrud
2020-Jan-10 07:59 UTC
[CentOS] Blocking attacks from a range of IP addresses
Hi! I usually use a primary ssh jail via f2b, ontop of that I have a reapeat offenders (usually a check on the f2b logs and rotation needs to be modified) over a long time. https://wireflare.com/blog/permanently-ban-repeat-offenders-with-fail2ban/ this could be modified to block bigger pieces of the network. Sadly I have no direct example for you. A suggestion is to look into for instance the ipsets from firehol. Unless you have a more targeted attack using blocklists might be a good option. Thing is, you might be at a point were any automation does more harm then good. It depends on what your service does. If it is your homelab with port 22 exposed, the just add big blocks or import firehol-1 and 99% of the attacks will be dropped. If it is a popular website and you are in need of blocking webbots then more care needs to be taken. My suggestion is: Firehol+change ssh port (if that is the service in question)+ssh tarpit+repeat offenders Regards On Thu, Jan 9, 2020, 20:10 Pete Biggs <pete at biggs.org.uk> wrote:> > > > > > > > As far as I can see fail2ban only deals with hosts and not networks - I > > > suspect the issue is what is a "network": It may be obvious to you > > > looking at the logs that these are all related, but you run the risk > > > that getting denied accesses from, say, 1.0.0.1 and 1.1.0.93 and > > > 1.2.0.124 may be interpreted as a concerted attack and you banning half > > > the internet - but that may not be a bad thing :-) > > > > > > > Since you can configure fail2ban to invoke scripts, I would think it > > would be possible to get it to block CIDRs (variable size subnets, i.e. > > 12.12.0.0/20). That said, I don't have a quick and easy implementation > > on hand. > > The OP was looking for an automated way of fail2ban doing it - he had > already sorted out the network range and had stopped this particular > DoS attack. > > P. > > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos >
On 01/09/2020 02:09 PM, Pete Biggs wrote:>>> As far as I can see fail2ban only deals with hosts and not networks - I >>> suspect the issue is what is a "network": It may be obvious to you >>> looking at the logs that these are all related, but you run the risk >>> that getting denied accesses from, say, 1.0.0.1 and 1.1.0.93 and >>> 1.2.0.124 may be interpreted as a concerted attack and you banning half >>> the internet - but that may not be a bad thing :-) >>> >> Since you can configure fail2ban to invoke scripts, I would think it >> would be possible to get it to block CIDRs (variable size subnets, i.e. >> 12.12.0.0/20). That said, I don't have a quick and easy implementation >> on hand. > The OP was looking for an automated way of fail2ban doing it - he had > already sorted out the network range and had stopped this particular > DoS attack. > > P. > > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centosCorrect. I appreciate all the replies but I used /etc/hosts.deny to deny this network range of attacks. Again, the reason that fail2ban failed to catch it was that the attacks were coming from a wide range of subnet addresses and were only caught by reviewing the log. It would be nice, however, to have a fail2ban expression that allowed me to catch the /16 range of addresses needed here.