Kaynağa Gözat

Mitigate port scanning

Bob Mottram 7 yıl önce
ebeveyn
işleme
ff31ff6961
2 değiştirilmiş dosya ile 30 ekleme ve 0 silme
  1. 27
    0
      src/freedombone-utils-firewall
  2. 3
    0
      src/freedombone-utils-setup

+ 27
- 0
src/freedombone-utils-firewall Dosyayı Görüntüle

@@ -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

+ 3
- 0
src/freedombone-utils-setup Dosyayı Görüntüle

@@ -700,6 +700,9 @@ function setup_firewall {
700 700
     function_check configure_firewall_ping
701 701
     configure_firewall_ping
702 702
 
703
+    function_check firewall_handle_port_scans
704
+    firewall_handle_port_scans
705
+
703 706
     function_check firewall_drop_telnet
704 707
     firewall_drop_telnet
705 708