|
@@ -465,6 +465,33 @@ function firewall_add_range {
|
465
|
465
|
fi
|
466
|
466
|
}
|
467
|
467
|
|
|
468
|
+function firewall_handle_port_scans {
|
|
469
|
+ if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
|
|
470
|
+ return
|
|
471
|
+ fi
|
|
472
|
+ # only works for high frequency port scanning
|
|
473
|
+
|
|
474
|
+ # flooding of RST packets, smurf attack Rejection
|
|
475
|
+ iptables -A INPUT -p tcp -m tcp --tcp-flags RST RST -m limit --limit 2/second --limit-burst 2 -j ACCEPT
|
|
476
|
+
|
|
477
|
+ # Protecting portscans
|
|
478
|
+ # Attacking IP will be locked for 24 hours (3600 x 24 = 86400 Seconds)
|
|
479
|
+ iptables -A INPUT -m recent --name portscan --rcheck --seconds 86400 -j DROP
|
|
480
|
+ iptables -A FORWARD -m recent --name portscan --rcheck --seconds 86400 -j DROP
|
|
481
|
+
|
|
482
|
+ # Remove attacking IP after 24 hours
|
|
483
|
+ iptables -A INPUT -m recent --name portscan --remove
|
|
484
|
+ iptables -A FORWARD -m recent --name portscan --remove
|
|
485
|
+
|
|
486
|
+ # These rules add scanners to the portscan list, and log the attempt.
|
|
487
|
+ iptables -A INPUT -p tcp -m tcp --dport 139 -m recent --name portscan --set -j LOG --log-prefix "portscan:"
|
|
488
|
+ iptables -A INPUT -p tcp -m tcp --dport 139 -m recent --name portscan --set -j DROP
|
|
489
|
+
|
|
490
|
+ iptables -A FORWARD -p tcp -m tcp --dport 139 -m recent --name portscan --set -j LOG --log-prefix "portscan:"
|
|
491
|
+ iptables -A FORWARD -p tcp -m tcp --dport 139 -m recent --name portscan --set -j DROP
|
|
492
|
+ save_firewall_settings
|
|
493
|
+ mark_completed "${FUNCNAME[0]}"
|
|
494
|
+}
|
468
|
495
|
|
469
|
496
|
function firewall_remove {
|
470
|
497
|
firewall_port=$1
|