Fehler in der iptables-Firewall-Konfiguration kann nicht gefunden werden

Fehler in der iptables-Firewall-Konfiguration kann nicht gefunden werden

Ich habe mit einem Firewall-Problem auf meinem Centos-Server.

Ich habe die folgende Konfiguration. Wenn ich sie mit einem Dienst „iptables restart“ verwende und versuche, per SSH mit Putty auf den Server zuzugreifen, kann ich nicht auf den Server zugreifen. Ich erhalte lediglich eine Fehlernachricht mit dem Verbindungstimeout.

Wenn ich jedoch die letzte REJECT-Zeile weglasse, ist das möglich.

Ich habe die Ports für SSH geöffnet, also Port 22. Was mache ich falsch? Mache ich einen Anfängerfehler? Für jede Hilfe wäre ich dankbar.

*filter
:INPUT ACCEPT [5:9090]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [3:372]
-A INPUT -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 10050 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 10051 -j ACCEPT 
-A OUTPUT -p tcp -m tcp --dport 10051 -j ACCEPT 
-A OUTPUT -p tcp -m tcp --dport 10050 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22   -j ACCEPT -m comment --comment  \" ssh port\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25   -j ACCEPT -m comment --comment  \" email\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 53   -j ACCEPT -m comment --comment  \" DNS large queries\"
-A INPUT -m state --state NEW -m udp -p udp --dport 53   -j ACCEPT -m comment --comment  \" DNS small queries\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80   -j ACCEPT -m comment --comment  \" Apache\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 110  -j ACCEPT -m comment --comment  \" POP3\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443  -j ACCEPT -m comment --comment  \" Apache ssl\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 953  -j ACCEPT -m comment --comment  \" DNS Internal\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 993  -j ACCEPT -m comment --comment  \" imaps\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3128 -j ACCEPT -m comment --comment  \" Squid\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -m comment --comment  \" MySQL\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT -m comment --comment  \" Jenkins\"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9090 -j ACCEPT -m comment --comment  \" Pmta\"

-A INPUT -m set --match-set blacklist src -j DROP -m comment --comment \"IPSET drop ips on blacklist\"
-A INPUT -p tcp --dport 8080 -j SET --add-set blacklist src

-A INPUT -i ${PREFIX} -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 5 --rttl --name SSH -j DROP 
-A INPUT -p tcp --tcp-flags ALL NONE -j DROP                 -m comment --comment \"Deny all null packets\"
-A INPUT -p tcp --tcp-flags ALL ALL -j DROP                  -m comment --comment \"Deny all recon packets\"
-A INPUT -p tcp --tcp-flags ALL FIN -j DROP                  -m comment --comment \"nmap FIN stealth scan\"
-A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP          -m comment --comment \"SYN + FIN\"
-A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP          -m comment --comment \"SYN + RST\"
-A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j DROP          -m comment --comment \"FIN + RST\"
-A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP          -m comment --comment \"FIN + URG + PSH\"
-A INPUT -p tcp --tcp-flags ALL URG,ACK,PSH,RST,SYN,FIN -j DROP -m comment --comment \"XMAS\"
-A INPUT -p tcp --tcp-flags ACK,FIN FIN -j DROP              -m comment --comment \"FIN without ACK\"
-A INPUT -p tcp --tcp-flags ACK,PSH PSH -j DROP              -m comment --comment \"PSH without ACK\"
-A INPUT -p tcp --tcp-flags ACK,URG URG -j DROP              -m comment --comment \"URG without ACK\"
-A INPUT -p tcp ! --syn -m state --state NEW -j DROP         -m comment --comment \"Deny SYN flood attack\"
-A INPUT -m state --state ESTABLISHED -m limit --limit 50/second --limit-burst 50 -j ACCEPT -m comment --comment \"Accept traffic with ESTABLISHED flag set (limit - DDoS prevent)\"
-A INPUT -m state --state RELATED -m limit --limit 50/second --limit-burst 50 -j ACCEPT   -m comment --comment \"Accept traffic with RELATED flag set (limit - DDoS prevent)\"
-A INPUT -m state --state INVALID -j DROP                    -m comment --comment \"Deny traffic with the INVALID flag set\"

-A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW -m limit --limit 30/minute --limit-burst 200 -j ACCEPT -m comment --comment \"Protection DDoS attacks\"

-A INPUT -j REJECT                               -m comment --comment \"Close up firewall. All else blocked.\"

COMMIT

Antwort1

Sie verwenden das aktuelle Modul, um für jeden Verbindungsversuch mit Port 22 dynamisch eine Liste mit IP-Adressen zu verwalten und IPs abzulehnen, die mehr als viermal pro Minute eine Verbindung herstellen wollen oder wechselnde TTLs verwenden (Hinweis: Diese letzte Prüfung kann in manchen Fällen auch bei legitimen Verbindungen zu Problemen führen).

Sie machen es jedoch falsch, weil Sie sie nirgendwo zu einer Liste hinzufügen, indem Sie eine frühere Regel verwenden, die eine --setOption enthält. Ihre Regel, die das --updateZiel verwendet, gibt also jedes Mal „false“ zurück, da Sie gegen eine leere Liste testen SSHund Pakete schließlich durch Ihre letzte Regel verworfen werden, sodass das letzte ACKPaket des Drei-Wege-Handshakes vom Server verworfen wird.

Sie suchen stattdessen nach so etwas:

-A INPUT -m recent --update --name SSH --seconds 60 --hitcount 5 --rttl -j DROP 
-A INPUT -i <iface> -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH 

Dies sollten die einzigen Regeln sein, die sich auf SSH beziehen, und in dieser Reihenfolge von iptables analysiert werden, wenn eine Übereinstimmung gefunden wird (d. h. entfernen Sie die Regel mit dem Kommentar „SSH-Port“ und stellen Sie sicher, dass die Reihenfolge eingehalten wird).

Auch eine globale Anmerkung: Sie versuchen, gängige TCP-Angriffsmuster abzulehnen, tun dies jedoch nach einer Menge Regeln. Sie sollten dies nach oben verschieben: Es bedeutet nutzlose Tests, bevor Pakete tatsächlich verworfen werden. Erstellen Sie bei Bedarf zur Verdeutlichung benutzerdefinierte Ketten.

verwandte Informationen