%20.png)
Ich bin Opfer eines DDOS-Angriffs, der auf einen HTTP-Server abzielt. Ich versuche es mit iptables und anderen Maßnahmen, aber nichts scheint zu funktionieren. Hier ist ein Teil des access_log:
Viele Verbindungen, aber iptables wird den Angriff nicht stoppen. Hier sind meine iptables-Regeln:
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -s 147.135.37.113 -j ACCEPT
iptables -A INPUT -f -j DROP
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
iptables -N LOG_AND_DROP
iptables -N PORT21
iptables -A PORT21 -m recent --set --name lp21
iptables -A PORT21 -m recent --update --seconds 30 --hitcount 3 --name lp21 -j DROP
iptables -A PORT21 -m recent --update --seconds 300 --hitcount 10 --name lp21 -j LOG_AND_DROP
iptables -N PORT22
iptables -A PORT22 -m recent --set --name lp22
iptables -A PORT22 -m recent --update --seconds 30 --hitcount 3 --name lp22 -j DROP
iptables -A PORT22 -m recent --update --seconds 300 --hitcount 10 --name lp22 -j LOG_AND_DROP
iptables -N PORT80
iptables -A PORT80 -m recent --set --name lp80
iptables -A PORT80 -m recent --update --seconds 30 --hitcount 20 --name lp80 -j LOG_AND_DROP
iptables -N PORT443
iptables -A PORT443 -m recent --set --name lp433
iptables -A PORT443 -m recent --update --seconds 30 --hitcount 20 --name lp443 -j LOG_AND_DROP
iptables -N PORT10000
iptables -A PORT10000 -m recent --set --name lp10000
iptables -A PORT10000 -m recent --update --seconds 30 --hitcount 20 --name lp10000 -j LOG_AND_DROP
iptables -N PORT6900
iptables -A PORT6900 -m recent --set --name lp6900
iptables -A PORT6900 -m recent --update --seconds 30 --hitcount 10 --name lp6900 -j LOG_AND_DROP
iptables -A PORT6900 -m recent --update --seconds 50 --hitcount 20 --name lp6900 -j LOG_AND_DROP
iptables -N PORT6121
iptables -A PORT6121 -m recent --set --name lp6121
iptables -A PORT6121 -m recent --update --seconds 30 --hitcount 10 --name lp6121 -j LOG_AND_DROP
iptables -A PORT6121 -m recent --update --seconds 50 --hitcount 20 --name lp6121 -j LOG_AND_DROP
iptables -N PORT5121
iptables -A PORT5121 -m recent --set --name lp5121
iptables -A PORT5121 -m recent --update --seconds 30 --hitcount 10 --name lp5121 -j LOG_AND_DROP
iptables -A PORT5121 -m recent --update --seconds 50 --hitcount 20 --name lp5121 -j LOG_AND_DROP
iptables -A INPUT -p icmp --icmp-type echo-request -m hashlimit --hashlimit-name pings --hashlimit-mode srcip --hashlimit 10/min --hashlimit-burst 10 --hashlimit-htable-expire 30000 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 5/min -j LOG --log-prefix "[Pings]"
iptables -A INPUT -p icmp -j DROP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -m state --state NEW -j PORT21
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j PORT22
iptables -A INPUT -p tcp --dport 80 -m state --state NEW -j PORT80
iptables -A INPUT -p tcp --dport 443 -m state --state NEW -j PORT443
iptables -A INPUT -p tcp --dport 10000 -m state --state NEW -j PORT10000
iptables -A INPUT -p tcp --dport 6900 -m state --state NEW -j PORT6900
iptables -A INPUT -p tcp --dport 6121 -m state --state NEW -j PORT6121
iptables -A INPUT -p tcp --dport 5121 -m state --state NEW -j PORT5121
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -m hashlimit --hashlimit-name p80 --hashlimit-mode srcip --hashlimit 50/min --hashlimit-burst 100 --hashlimit-htable-expire 10000 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -m hashlimit --hashlimit-name p443 --hashlimit-mode srcip --hashlimit 50/min --hashlimit-burst 100 --hashlimit-htable-expire 10000 -j ACCEPT
iptables -A INPUT -p tcp --dport 10000 -m hashlimit --hashlimit-name p10000 --hashlimit-mode srcip --hashlimit 50/min --hashlimit-burst 100 --hashlimit-htable-expire 10000 -j ACCEPT
iptables -A INPUT -p tcp --dport 6900 -j ACCEPT
iptables -A INPUT -p tcp --dport 6121 -j ACCEPT
iptables -A INPUT -p tcp --dport 5121 -j ACCEPT
iptables -A LOG_AND_DROP -m limit --limit 10/min -j LOG --log-prefix "[Log]"
iptables -A LOG_AND_DROP -j DROP
#iptables -A INPUT -m limit --limit 10/min -j LOG --log-prefix "[Default]"
iptables -A INPUT -d 147.135.37.113 -j DROP
Jeder Ratschlag ist willkommen. Ich versuche alles, aber nichts funktioniert.
Antwort1
Sprechen Sie mit Ihrem Anbieter (wahrscheinlich OVH) über den DDoS-Schutz auf Ihrem System. Nicht alle, aber die meisten seriösen Anbieter können Ihnen dabei helfen. Abgesehen davon könnten Sie eine schicke Fail2Ban-Regel in Betracht ziehen, die Ihre Webserver-Protokolle auf jeden Client überwacht, der diese Forum-URL anklickt, und automatisch eine IPTables-Regel für sie hinzufügt. Abgesehen davon können Sie dort etwas ablegen ... vielleicht eine sehr kleine 1-Byte-Datei? Oder stellen Sie Ihren Webserver hinter etwas wie Cloudflare oder einen anderen CDN-Dienst. Der Großteil dieses Datenverkehrs kann auf eine Handvoll Arten bewältigt werden und sollte weder Ihren Server noch Sie so stark belasten. Achten Sie jedoch auf Protokolldateien, die Ihr Dateisystem füllen! Das kann ein ganz anderes Problem verursachen, das niemand will.
Weitere Informationen zur Verwendung von fail2ban zum Schutz von Apache vor DoS-Angriffen finden Sie hier:https://apache.tutorials24x7.com/blog/schützen-sie-apache-vor-brute-force-und-ddos-angriffen-mithilfe-von-fail2ban
Antwort2
Das Problem wurde mit diesem einfachen iptables gelöst (vielleicht waren die anderen Regeln zu chaotisch)
iptables -A INPUT -i eno1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eno1 -m state --state INVALID -j DROP
iptables -A INPUT -i eno1 -p tcp -m tcp --dport 22 -m state --state NEW -j ACCEPT
iptables -A INPUT -i eno1 -p tcp -m tcp --dport 21 -m state --state NEW -j ACCEPT
iptables -A INPUT -i eno1 -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT
iptables -A INPUT -i eno1 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT
iptables -A INPUT -i eno1 -p icmp -j ACCEPT
iptables -A INPUT -i eno1 -j DROP
Die Angriffe gehen weiter, führen aber nicht zum Serverabsturz.
Antwort3
Ein paar Dinge fallen mir ein:
- Sie könnten String-Match mit iptables verwenden:
iptables -A INPUT -m string --algo bm --string "GET /foro" -j DROP
oder wenn möglich in Ihrem System, mit TARPIT
iptables -A INPUT -m string --algo bm --string "GET /foro" -j TARPIT
- Anstatt fail2ban zu verwenden, erstellen Sie Ihr eigenes Skript, das beispielsweise die letzten 1000 Zeilen der Protokolle durchsucht und Übereinstimmungen mit IP-Sets blockiert. Fügen Sie dies zu Ihrem iptables-Skript hinzu:
- ipset zerstört Toilette
- ipset -N Toilette iphash
- ipset Spültoilette
Verwenden Sie dann Ihr Skript, um die IP-Adressen, die Sie blockieren möchten, zur Textdatei hinzuzufügen. Schließlich müssen Sie nur noch alle IP-Adressen in diese Toilettenliste einbinden.
- ipset -Eine Toilette "$ipaddress"
Die Verwendung von IP-Sets und insbesondere Masken ist viel effizienter als das Blockieren von IP-Adressen. Bei mir sind etwa 20.000 Adressen und etwa 200 Netzwerke blockiert.
Mein sehr, sehr chaotisches Skript gibt Ihnen vielleicht eine Idee. https://pastebin.com/4v5se0kh
Ich weiß, dass es chaotisch ist, aber es funktioniert bei mir viel schneller und ist viel einfacher als fail2ban. Ich habe das Skript suc2ban genannt. Sie müssen nur Ihre eigenen Entsprechungen für Ihre Protokolldatei finden (Sie haben wahrscheinlich Apache access.log, statt meines Beispiels, das auth.log verwendet).