Quellcode durchsuchen

Re-introduce rate limits on the firewall

Bob Mottram vor 8 Jahren
Ursprung
Commit
bde41a1f21
2 geänderte Dateien mit 28 neuen und 0 gelöschten Zeilen
  1. 25
    0
      src/freedombone-utils-firewall
  2. 3
    0
      src/freedombone-utils-setup

+ 25
- 0
src/freedombone-utils-firewall Datei anzeigen

482
     mark_completed $FUNCNAME
482
     mark_completed $FUNCNAME
483
 }
483
 }
484
 
484
 
485
+function firewall_rate_limits {
486
+    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
487
+        return
488
+    fi
489
+
490
+    # Limit connections per source IP
491
+    iptables -A INPUT -p tcp -m connlimit --connlimit-above 111 -j REJECT --reject-with tcp-reset
492
+
493
+    # Limit RST packets
494
+    iptables -A INPUT -p tcp --tcp-flags RST RST -m limit --limit 2/s --limit-burst 2 -j ACCEPT
495
+    iptables -A INPUT -p tcp --tcp-flags RST RST -j DROP
496
+
497
+    # Limit new TCP connections per second per source IP
498
+    iptables -A INPUT -p tcp -m conntrack --ctstate NEW -m limit --limit 60/s --limit-burst 20 -j ACCEPT
499
+    iptables -A INPUT -p tcp -m conntrack --ctstate NEW -j DROP
500
+
501
+    # SSH brute-force protection
502
+    iptables -A INPUT -p tcp --dport ssh -m conntrack --ctstate NEW -m recent --set
503
+    iptables -A INPUT -p tcp --dport ssh -m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 10 -j DROP
504
+
505
+    function_check save_firewall_settings
506
+    save_firewall_settings
507
+    mark_completed $FUNCNAME
508
+}
509
+
485
 # NOTE: deliberately no exit 0
510
 # NOTE: deliberately no exit 0

+ 3
- 0
src/freedombone-utils-setup Datei anzeigen

567
     function_check firewall_drop_spoofed_packets
567
     function_check firewall_drop_spoofed_packets
568
     firewall_drop_spoofed_packets
568
     firewall_drop_spoofed_packets
569
 
569
 
570
+    function_check firewall_rate_limits
571
+    firewall_rate_limits
572
+
570
     function_check configure_firewall_for_dns
573
     function_check configure_firewall_for_dns
571
     configure_firewall_for_dns
574
     configure_firewall_for_dns
572
 
575