MikroTik password guessing and port scan protection
Block addresses that guess passwords to Winbox, SSH and forwarded servers, and port scanners.
A RouterOS 7 script with an allow list, verification and rollback.
Block addresses that guess passwords to Winbox, SSH and forwarded servers, and port scanners.
A RouterOS 7 script with an allow list, verification and rollback.
Addresses that connect to Winbox, SSH or forwarded servers many times in a row go on a block list for a set time. Scanners are caught on trap ports. A RouterOS 7 script with verification, unblocking and rollback.
The script is built in your browser; addresses are not sent anywhere.
Password guessers connect to open ports again and again — to Winbox, SSH, RDP behind a forward. The MikroTik firewall cannot count failed logins, but it does see new connections. Each new connection from the internet moves the source address one stage up, into a list with a short timeout. If the address gets through all stages while the pauses between connections stay shorter than the window, it goes on the pasw-bf-block list for hours or weeks and all its packets are dropped.
/import, then test from mobile internet.New connections to the protected ports go to separate chains, pasw-bf-in (router) and pasw-bf-fwd (forwarded servers). There your own addresses return at once, and the rest pass through the stages pasw-bf-in1, pasw-bf-in2… Blocked addresses are dropped in /ip firewall raw before connection tracking. All rules carry the comment pasw-bf, so a re-run or rollback touches only them. The best protection is not to expose Winbox and SSH to the internet at all: MikroTik basic hardening does that, and the configuration check finds exposed services.
It can happen if you connect many times in a row — Winbox opens several connections when logging in. Add your addresses to the allow list. If you do get blocked, connect from the local network or via Winbox by MAC address and run the unblock command from the Verification block.
The firewall cannot see whether the password was right; it only sees new connections. That is why the threshold is above the usual number of logins and the allow list protects your addresses. A guesser makes hundreds of connections, and the stages catch it quickly.
There, protection is only for forwards made in that generator. Here it covers the router's own services, any forwarded ports, trap ports and scans, with one shared block list and an allow list.
/ip firewall address-list print where list=pasw-bf-block shows the addresses and the remaining block time. Rule counters: /ip firewall filter print stats where comment~"pasw-bf". With logging on, blocks show up in /log print where message~"pasw-bf".