SSH Dictionary Attack Prevention in MK

Hi,

I have a problem to secure a SSH connection, I don’t want to put a static ip in the ssh service but but I want secure it from dictionary attacks. I think that the next iptables rules can work well in the box but I don’t know what is the equivalent in MK

iptables -N SSH_CHECK
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j SSH_CHECK
iptables -A SSH_CHECK -m recent --set --name SSH
iptables -A SSH_CHECK -m recent --update --seconds 60 --hitcount 4 --name SSH -j DROP


Best regards,

Kiket

if i understood you correctly then this is cannot be achieved in any “sane” configuration

instead i can point you to different other solution:

  1. trusted address address list - you create address list that are trusted, and connect from these ip addresses only (limiting only external interface)

  2. you block everything, but to connect to your router you create tunnel to your router and then login in router through tunnel which is allowed, every os is supporting, at least, PPTP tunnel

  3. you use port knocking - you send packet to sequence of ports and that gets your ip address into address list that is allowed to connect to router remotely.

Not entirely sure if I understood the original post correctly, but this should be possible by using the connection-limiting parameters of the firewall to allow only 4 TCP connections to port 22 every 60 seconds?!

Best regards,
Christian Meis

Thanks janisk and cmit,

I don’t want to limit a list of trusted IP (janisk) I want to limit the access in a minute from the same IP.Add this Ip to an address list and if it acces 3 times in a minute, drop.

Cmit you are right, this is that I want.

I go to see the connection-limiting option.

Thanks.

Hi all,

I test with limit-connection but this option work when an IP make some connection but not if they close a connection and then make a new.

I solve my problem with this:

;;; DROP trafico SSH + 3 conexiones/min.
chain=input protocol=tcp dst-port=22 connection-state=new
src-address-list=3 conexion action=drop

chain=input protocol=tcp dst-port=22 connection-state=new
src-address-list=2 conexion action=add-src-to-address-list
address-list=3 conexion address-list-timeout=1m

chain=input protocol=tcp dst-port=22 connection-state=new
src-address-list=1 conexion action=add-src-to-address-list
address-list=2 conexion address-list-timeout=1m

chain=input protocol=tcp dst-port=22 connection-state=new
action=add-src-to-address-list address-list=1 conexion
address-list-timeout=1m

It’s not very elegant but work. If someone have another form to make it work more elegant please say me it.

Thanks for all.

Kiket

In my whole network I have changed ssh port to something else than 22, so since than I’m OK with that.

Regards.

Faton