需要 IP 表規則來阻止 DoS/DDoS 攻擊(IP 欺騙和 SYN 洪水攻擊)

需要 IP 表規則來阻止 DoS/DDoS 攻擊(IP 欺騙和 SYN 洪水攻擊)

我有一個網路交換機,我試圖在其中安裝 IP 表規則以防止不同類型的 DOS/DDOS 攻擊。下面是網頁佈局。

Laptop-1 ------- router ---- Network switch ---- customer devices
                   |
Laptop-2 -----------

我試圖從 Laptop-1 攻擊交換機,並且交換機將進入掛起狀態。

以下是我試圖阻止的 DoS/DDoS 攻擊。

IP spoofing
    Attack command: hping3 -a 192.168.1.1 -S -p 80 --flood 192.168.22.140
    Result: System hangs
    
SYN flood - half handshake
    Attack command: hping3 -V -c 1000 -d 10 -S -p 80 --flood 192.168.22.140
    Result: System hangs
    
ICMP flood
    Attack command: hping3 -1 --flood -a 192.168.22.140 192.168.22.140
    Attack command: hping3 -1 --flood -a 192.168.22.15 192.168.22.140
    Result: System hangs

對於 ICMP 洪水,我已經制定了規則,但我需要協助來尋找 IP 欺騙和 SYN 洪水攻擊所需的規則。此規則的安裝方式應阻止來自任何子網路的攻擊者。

我正在使用以下 iptables 版本:iptables-1.8.5 (legacy build)

答案1

#!/bin/bash
# Variables
IPTABLES="/sbin/iptables"
RLIMIT="-m limit --limit 10/s --limit-burst 10"
#---------------------------------------------------------------------------
# Drop invalid packets 
$IPTABLES -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP
#----------------------------------------------------------------------------
#  Drop TCP packets that are new and are not SYN 
$IPTABLES -t mangle -A PREROUTING -p tcp ! --syn -m conntrack --ctstate NEW -j DROP
#---------------------------------------------------------------------------------------
#  Drop SYN packets with suspicious MSS value
$IPTABLES -t mangle -A PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP
#-------------------------------------------------------------------------------------------------------
# Block packets with bogus TCP flags
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags FIN,RST FIN,RST -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags FIN,ACK FIN -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags ACK,URG URG -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags ACK,FIN FIN -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags ACK,PSH PSH -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags ALL ALL -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,FIN,PSH,URG -j DROP
$IPTABLES -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
#---------------------------------------------------------------------------------------
# Limit TCP connections per source IP
$IPTABLES -A INPUT -p tcp -m connlimit --connlimit-above 20 -j REJECT --reject-with tcp-reset
#-----------------------------------------------------------------------------------------
# Protection against SYN FLOOD
$IPTABLES -N SYN_FLOOD
$IPTABLES -A INPUT -p tcp --syn -j SYN_FLOOD
$IPTABLES -A SYN_FLOOD $RLIMIT -j RETURN
$IPTABLES -A SYN_FLOOD -j DROP
#-------------------------------------------------------------------------------------------
# Save the rules
/sbin/iptables-save

相關內容