Address-List dinamiche — Anti brute-force SSH e Winbox a stadi
Le address-list dinamiche con timeout escalante permettono di bloccare automaticamente gli attacchi brute-force su SSH e Winbox, con punizione progressiva: da 5 minuti fino a 1 giorno di blacklist.
Le address-list in RouterOS possono essere statiche (inserite manualmente) o dinamiche (popolate automaticamente da regole firewall con action=add-src-to-address-list). La tecnica a stadi con timeout escalante è il modo più efficace per bloccare brute-force senza bloccare erroneamente utenti legittimi.
Logica di funzionamento a stadi
Ogni nuova connessione SSH da un IP non ancora in blacklist viene aggiunta alla lista connection1 (5 min). Se entro quei 5 minuti tenta di nuovo, finisce in connection2 (15 min). Al terzo tentativo va in connection3 (1 ora). Al quarto: blacklist per 1 giorno. Questo limita l'attaccante a circa 3 tentativi ogni 5 minuti invece di migliaia al secondo.
# ================================================================ # ANTI BRUTE-FORCE SSH — 4 stadi con timeout crescente # IMPORTANTE: queste regole devono essere PRIMA delle regole accept SSH. # L'ordine conta: le regole vengono valutate dall'alto verso il basso. # ================================================================ # STADIO 1: primo tentativo → connection1 per 5 minuti /ip firewall filter add chain=input protocol=tcp dst-port=22 connection-state=new action=add-src-to-address-list address-list=ssh-stage1 address-list-timeout=5m comment="SSH brute-force: primo tentativo (5 min)" # STADIO 2: secondo tentativo (IP già in stage1) → stage2 per 15 minuti /ip firewall filter add chain=input protocol=tcp dst-port=22 connection-state=new src-address-list=ssh-stage1 action=add-src-to-address-list address-list=ssh-stage2 address-list-timeout=15m comment="SSH brute-force: secondo tentativo (15 min)" # STADIO 3: terzo tentativo (IP in stage2) → stage3 per 1 ora /ip firewall filter add chain=input protocol=tcp dst-port=22 connection-state=new src-address-list=ssh-stage2 action=add-src-to-address-list address-list=ssh-stage3 address-list-timeout=1h comment="SSH brute-force: terzo tentativo (1 ora)" # STADIO 4: IP in stage3 → blacklist definitiva per 24 ore /ip firewall filter add chain=input protocol=tcp dst-port=22 connection-state=new src-address-list=ssh-stage3 action=add-src-to-address-list address-list=ssh-blacklist address-list-timeout=1d log=yes log-prefix="SSH-BLACKLIST" comment="SSH brute-force: blacklist 24 ore" # DROP per tutti gli IP in blacklist /ip firewall filter add chain=input src-address-list=ssh-blacklist action=drop comment="Blocca IP in SSH blacklist" # ACCETTA SSH legittimo (solo da IP admin — vedi ruleset base) /ip firewall filter add chain=input protocol=tcp dst-port=22 src-address-list=admin action=accept comment="SSH: accetta solo da IP admin" # DROP finale SSH da tutti gli altri /ip firewall filter add chain=input protocol=tcp dst-port=22 action=drop comment="SSH: blocca tutto il resto"
# Stesso schema per Winbox — 3 stadi + blacklist /ip firewall filter add chain=input protocol=tcp dst-port=8291 connection-state=new action=add-src-to-address-list address-list=wb-stage1 address-list-timeout=3m comment="Winbox BF: stadio 1 (3 min)" /ip firewall filter add chain=input protocol=tcp dst-port=8291 connection-state=new src-address-list=wb-stage1 action=add-src-to-address-list address-list=wb-stage2 address-list-timeout=10m comment="Winbox BF: stadio 2 (10 min)" /ip firewall filter add chain=input protocol=tcp dst-port=8291 connection-state=new src-address-list=wb-stage2 action=add-src-to-address-list address-list=wb-blacklist address-list-timeout=4h log=yes log-prefix="WB-BLACKLIST" comment="Winbox BF: blacklist 4 ore" /ip firewall filter add chain=input src-address-list=wb-blacklist action=drop comment="Blocca IP in Winbox blacklist" # Gestione manuale delle liste: visualizza chi è in blacklist /ip firewall address-list print where list=ssh-blacklist /ip firewall address-list print where list=wb-blacklist # Rimuovi un IP dalla blacklist (es. se hai bloccato te stesso) /ip firewall address-list remove [find list=ssh-blacklist address=1.2.3.4]
Address-list statiche per whitelist e blacklist permanenti
# Aggiungi IP alla lista admin (whitelist permanente) /ip firewall address-list add list=admin address=203.0.113.50 comment="VPN office - accesso permanente" # Blocco permanente di un range sospetto (senza timeout = permanente) /ip firewall address-list add list=permanent-blacklist address=185.220.0.0/16 comment="Tor exit nodes / rete sospetta" # Regola per bloccare permanentemente in RAW (prima del conntrack) /ip firewall raw add chain=prerouting src-address-list=permanent-blacklist action=drop comment="RAW: blocco permanente IP lista nera" # Visualizza tutte le entry dinamiche con timeout rimanente /ip firewall address-list print where dynamic=yes
admin PRIMA di configurare le regole brute-force. Considera anche di cambiare la porta SSH (es. 2222) tramite /ip ssh set port=2222.Continua con
Configura senza fatica con l'AI
In WispOS l'agente AI genera la configurazione RouterOS dalle tue parole e un tutor ti guida passo passo.
Prova WispOS