![Precisa de regras de tabelas de IP para bloquear ataques DoS/DDoS (IP Spoofing e ataque de inundação SYN)](https://rvso.com/image/191798/Precisa%20de%20regras%20de%20tabelas%20de%20IP%20para%20bloquear%20ataques%20DoS%2FDDoS%20(IP%20Spoofing%20e%20ataque%20de%20inunda%C3%A7%C3%A3o%20SYN).png)
Eu tenho um switch de rede onde estou tentando instalar as regras das Tabelas IP para evitar diferentes tipos de ataques DOS/DDOS. Abaixo está o layout da rede.
Laptop-1 ------- router ---- Network switch ---- customer devices
|
Laptop-2 -----------
Estou tentando atacar o switch do Laptop-1 e o switch está travado.
Abaixo estão os ataques DoS/DDoS que estou tentando prevenir.
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
Para inundação de ICMP, já tenho uma regra em vigor, mas preciso de ajuda para encontrar a regra desejada para falsificação de IP e ataque de inundação de SYN. A regra deve ser instalada de forma a bloquear o invasor de qualquer sub-rede.
Estou usando a seguinte versão do iptables:iptables-1.8.5 (legacy build)
Responder1
#!/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