* nftables: drop ssh brute force with ip block
@ 2016-06-19 18:24 Irwin L.
2016-06-23 10:34 ` Pablo Neira Ayuso
0 siblings, 1 reply; 6+ messages in thread
From: Irwin L. @ 2016-06-19 18:24 UTC (permalink / raw)
To: netfilter
As subject says.
tcp dport {22} counter limit rate 3/minute counter accept comment "avoid
brute force"
I've tried something like this, but it seems to limit ALL ips.
I would prefer to block the ip address for 24 hours or something.
Please suggest
Irwin
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: nftables: drop ssh brute force with ip block 2016-06-19 18:24 nftables: drop ssh brute force with ip block Irwin L. @ 2016-06-23 10:34 ` Pablo Neira Ayuso 2016-06-23 10:39 ` Irwin L. 0 siblings, 1 reply; 6+ messages in thread From: Pablo Neira Ayuso @ 2016-06-23 10:34 UTC (permalink / raw) To: Irwin L.; +Cc: netfilter On Mon, Jun 20, 2016 at 02:24:11AM +0800, Irwin L. wrote: > As subject says. > > tcp dport {22} counter limit rate 3/minute counter accept comment "avoid > brute force" > > I've tried something like this, but it seems to limit ALL ips. > I would prefer to block the ip address for 24 hours or something. Try something like: # nft add rule x y tcp dport 22 \ flow table ssh-bruteforce { ip saddr limit rate 3/minute } \ accept comment \"avoid brute force\" This is ratelimiting based on the source IP address. You can consult the content of this flow table via: # nft list flow table x ssh-bruteforce ... The current output of this specific command is not stable, You require a relatively recent kernel and nft 0.6 to get this working. BTW, please don't use: tcp dport { 22} The curly braces have very specific semantics, ie. they are requesting the kernel to create a set. In this specific case, this is overkill since this will create a set with *only one single element*. Thus: tcp dport 22 is better. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: nftables: drop ssh brute force with ip block 2016-06-23 10:34 ` Pablo Neira Ayuso @ 2016-06-23 10:39 ` Irwin L. 2016-06-23 10:48 ` Pablo Neira Ayuso 0 siblings, 1 reply; 6+ messages in thread From: Irwin L. @ 2016-06-23 10:39 UTC (permalink / raw) To: Pablo Neira Ayuso; +Cc: netfilter On 2016-06-23 18:34, Pablo Neira Ayuso wrote: > On Mon, Jun 20, 2016 at 02:24:11AM +0800, Irwin L. wrote: >> As subject says. >> >> tcp dport {22} counter limit rate 3/minute counter accept comment "avoid >> brute force" >> >> I've tried something like this, but it seems to limit ALL ips. >> I would prefer to block the ip address for 24 hours or something. > Try something like: > > # nft add rule x y tcp dport 22 \ > flow table ssh-bruteforce { ip saddr limit rate 3/minute } \ > accept comment \"avoid brute force\" > > This is ratelimiting based on the source IP address. > > You can consult the content of this flow table via: > > # nft list flow table x ssh-bruteforce > ... > > The current output of this specific command is not stable, > > You require a relatively recent kernel and nft 0.6 to get this > working. > > BTW, please don't use: > > tcp dport { 22} > > The curly braces have very specific semantics, ie. they are requesting > the kernel to create a set. In this specific case, this is overkill > since this will create a set with *only one single element*. Thus: > > tcp dport 22 > > is better. I currently use: tcp dport {22222,40022,42222} ct state new counter flow table bruteforce { ip saddr limit rate 3/minute } counter accept comment "limit bruteforce" Is this ok? I wanted to ban spamming ips altogether, but I've since learned that this is the job of 'fail2ban' Thanks! ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: nftables: drop ssh brute force with ip block 2016-06-23 10:39 ` Irwin L. @ 2016-06-23 10:48 ` Pablo Neira Ayuso 2016-06-23 10:55 ` Irwin L. 0 siblings, 1 reply; 6+ messages in thread From: Pablo Neira Ayuso @ 2016-06-23 10:48 UTC (permalink / raw) To: Irwin L.; +Cc: netfilter On Thu, Jun 23, 2016 at 06:39:46PM +0800, Irwin L. wrote: > I currently use: > tcp dport {22222,40022,42222} ct state new counter flow table bruteforce { > ip saddr limit rate 3/minute } counter accept comment "limit bruteforce" > > Is this ok? Looks good to me. I would probably check for ct state new in first place, given that this only matches the first packet a new TCP connections. It will save you the tcp dport set lookup. Note that you can even limit this per port, ie. ct state new tcp dport {22222,40022,42222} counter \ flow table bruteforce { ip saddr . tcp dport limit rate 3/minute } \ counter accept comment "limit bruteforce" using the 'ip saddr . tcp dport' concatenation. But I guess you want globally ban anyone spamming you to those ports anyway. > I wanted to ban spamming ips altogether, but I've since learned that this is > the job of 'fail2ban' fail2ban is nice to have to simplify this administrative hassle, but I think it is still using iptables (it's been a while a I didn't look at that code), we can do much better now with nft to resolve this problem. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: nftables: drop ssh brute force with ip block 2016-06-23 10:48 ` Pablo Neira Ayuso @ 2016-06-23 10:55 ` Irwin L. 2016-06-23 11:01 ` Pablo Neira Ayuso 0 siblings, 1 reply; 6+ messages in thread From: Irwin L. @ 2016-06-23 10:55 UTC (permalink / raw) To: Pablo Neira Ayuso; +Cc: netfilter On 2016-06-23 18:48, Pablo Neira Ayuso wrote: > On Thu, Jun 23, 2016 at 06:39:46PM +0800, Irwin L. wrote: >> I currently use: >> tcp dport {22222,40022,42222} ct state new counter flow table bruteforce { >> ip saddr limit rate 3/minute } counter accept comment "limit bruteforce" >> >> Is this ok? > Looks good to me. I would probably check for ct state new in first > place, given that this only matches the first packet a new TCP > connections. It will save you the tcp dport set lookup. > > Note that you can even limit this per port, ie. > > ct state new tcp dport {22222,40022,42222} counter \ > flow table bruteforce { ip saddr . tcp dport limit rate 3/minute } \ > counter accept comment "limit bruteforce" > > using the 'ip saddr . tcp dport' concatenation. But I guess you want > globally ban anyone spamming you to those ports anyway. > >> I wanted to ban spamming ips altogether, but I've since learned that this is >> the job of 'fail2ban' > fail2ban is nice to have to simplify this administrative hassle, but I > think it is still using iptables (it's been a while a I didn't look at > that code), we can do much better now with nft to resolve this problem. By that do you mean "counter ct state new" instead of "counter flow table" ? Thing is with this method, it only limits, I wonder if nft can blacklist the ip for 1 day or even 1 week with the option of manually removing blacklisted ips manually. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: nftables: drop ssh brute force with ip block 2016-06-23 10:55 ` Irwin L. @ 2016-06-23 11:01 ` Pablo Neira Ayuso 0 siblings, 0 replies; 6+ messages in thread From: Pablo Neira Ayuso @ 2016-06-23 11:01 UTC (permalink / raw) To: Irwin L.; +Cc: netfilter On Thu, Jun 23, 2016 at 06:55:31PM +0800, Irwin L. wrote: > On 2016-06-23 18:48, Pablo Neira Ayuso wrote: > >On Thu, Jun 23, 2016 at 06:39:46PM +0800, Irwin L. wrote: > >>I currently use: > >>tcp dport {22222,40022,42222} ct state new counter flow table bruteforce { > >>ip saddr limit rate 3/minute } counter accept comment "limit bruteforce" > >> > >>Is this ok? > >Looks good to me. I would probably check for ct state new in first > >place, given that this only matches the first packet a new TCP > >connections. It will save you the tcp dport set lookup. > > > >Note that you can even limit this per port, ie. > > > > ct state new tcp dport {22222,40022,42222} counter \ > > flow table bruteforce { ip saddr . tcp dport limit rate 3/minute } \ > > counter accept comment "limit bruteforce" > > > >using the 'ip saddr . tcp dport' concatenation. But I guess you want > >globally ban anyone spamming you to those ports anyway. > > > >>I wanted to ban spamming ips altogether, but I've since learned that this is > >>the job of 'fail2ban' > > >fail2ban is nice to have to simplify this administrative hassle, but I > >think it is still using iptables (it's been a while a I didn't look at > >that code), we can do much better now with nft to resolve this problem. > > By that do you mean "counter ct state new" instead of "counter flow table" ? > > Thing is with this method, it only limits, I wonder if nft can blacklist the > ip for 1 day or even 1 week with the option of manually removing blacklisted > ips manually. > I mean, instead of: tcp dport {22222,40022,42222} ct state new counter use this: ct state new tcp dport {22222,40022,42222} counter so just place the 'ct state new' check in first place, as most packets will not go further in the rule evaluation, given that the rule evaluation happens from left to right. If one of the statements evaluates false, we stop evaluating and look at the next rule. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-06-23 11:01 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-06-19 18:24 nftables: drop ssh brute force with ip block Irwin L. 2016-06-23 10:34 ` Pablo Neira Ayuso 2016-06-23 10:39 ` Irwin L. 2016-06-23 10:48 ` Pablo Neira Ayuso 2016-06-23 10:55 ` Irwin L. 2016-06-23 11:01 ` Pablo Neira Ayuso
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.