setup_flood() { if [ "$FLOOD" != "0" ]; then echo "Uruchamiam ochronę przed floodami icmp i syn od strony LAN'u" #utworz łańcuch jeśli nie istnieje check=`$IPTABLES -t raw -nL LAN-IN|grep "FLOOD"` if [ "$check" == "" ]; then $IPTABLES -t raw -N FLOOD 2>/dev/null $IPTABLES -t raw -A LAN-IN -j FLOOD fi $IPTABLES -t raw -F FLOOD check=`$IPTABLES -t raw -nL|grep "ICMP_DST"` if [ "$check" == "" ]; then $IPTABLES -t raw -N ICMP_DST fi $IPTABLES -t raw -F ICMP_DST $IPTABLES -t raw -A ICMP_DST -p icmp -m hashlimit --hashlimit 20/sec --hashlimit-burst 30 \ --hashlimit-mode dstip --hashlimit-name limit_icmp_dst -j RETURN $IPTABLES -t raw -A ICMP_DST -m limit --limit 5/minute --limit-burst 5 \ -j LOG --log-level info --log-prefix "ICMP DST Flood: " $IPTABLES -t raw -A ICMP_DST -p icmp -m recent --name icmp-dst-flood --rdest --set -j DROP check=`$IPTABLES -t raw -nL|grep "ICMP_SRC"` if [ "$check" == "" ]; then $IPTABLES -t raw -N ICMP_SRC fi $IPTABLES -t raw -F ICMP_SRC $IPTABLES -t raw -A ICMP_SRC -p icmp -m hashlimit --hashlimit 20/sec --hashlimit-burst 30 \ --hashlimit-mode srcip --hashlimit-name limit_icmp_src -j RETURN $IPTABLES -t raw -A ICMP_SRC -m limit --limit 5/minute --limit-burst 5 \ -j LOG --log-level info --log-prefix "ICMP SRC Flood: " $IPTABLES -t raw -A ICMP_SRC -p icmp -m recent --name icmp-src-flood --rsource --set -j DROP check=`$IPTABLES -t raw -nL|grep "SYN_DST"` if [ "$check" == "" ]; then $IPTABLES -t raw -N SYN_DST fi $IPTABLES -t raw -F SYN_DST $IPTABLES -t raw -A SYN_DST -p tcp --syn -m hashlimit --hashlimit 10/sec --hashlimit-burst \ 20 --hashlimit-mode dstip --hashlimit-name limit_syn_dst -j RETURN $IPTABLES -t raw -A SYN_DST -m limit --limit 5/minute --limit-burst 5 \ -j LOG --log-level info --log-prefix "SYN DST Flood: " $IPTABLES -t raw -A SYN_DST -p tcp -m recent --name syn-dst-flood --rdest --set -j DROP check=`$IPTABLES -t raw -nL|grep "SYN_SRC"` if [ "$check" == "" ]; then $IPTABLES -t raw -N SYN_SRC fi $IPTABLES -t raw -F SYN_SRC $IPTABLES -t raw -A SYN_SRC -p tcp --syn -m hashlimit --hashlimit 10/sec --hashlimit-burst \ 20 --hashlimit-mode srcip --hashlimit-name limit_syn_src -j RETURN $IPTABLES -t raw -A SYN_SRC -m limit --limit 5/minute --limit-burst 5 \ -j LOG --log-level info --log-prefix "SYN SRC Flood: " $IPTABLES -t raw -A SYN_SRC -p tcp -m recent --name syn-src-flood --rsource --set -j DROP check=`$IPTABLES -t raw -nL|grep "UDP_DST"` if [ "$check" == "" ]; then $IPTABLES -t raw -N UDP_DST fi $IPTABLES -t raw -F UDP_DST $IPTABLES -t raw -A UDP_DST -p udp -m hashlimit --hashlimit 1250/sec --hashlimit-burst \ 1250 --hashlimit-mode dstip --hashlimit-name limit_udp_dst -j RETURN $IPTABLES -t raw -A UDP_DST -m limit --limit 5/minute --limit-burst 5 \ -j LOG --log-level info --log-prefix "UDP DST Flood: " $IPTABLES -t raw -A UDP_DST -p udp -m recent --name udp-dst-flood --rdest --set -j DROP check=`$IPTABLES -t raw -nL|grep "UDP_SRC"` if [ "$check" == "" ]; then $IPTABLES -t raw -N UDP_SRC fi $IPTABLES -t raw -F UDP_SRC $IPTABLES -t raw -A UDP_SRC -p udp -m hashlimit --hashlimit 250/sec --hashlimit-burst \ 250 --hashlimit-mode srcip --hashlimit-name limit_udp_src -j RETURN $IPTABLES -t raw -A UDP_SRC -m limit --limit 5/minute --limit-burst 5 \ -j LOG --log-level info --log-prefix "UDP SRC Flood: " $IPTABLES -t raw -A UDP_SRC -p udp -m recent --name udp-src-flood --rsource --set -j DROP $IPTABLES -t raw -A FLOOD -p icmp -j ICMP_DST $IPTABLES -t raw -A FLOOD -p icmp -j ICMP_SRC $IPTABLES -t raw -A FLOOD -p tcp --syn -j SYN_DST $IPTABLES -t raw -A FLOOD -p tcp --syn -j SYN_SRC $IPTABLES -t raw -A FLOOD -p udp -j UDP_DST $IPTABLES -t raw -A FLOOD -p udp -j UDP_SRC $TC filter del dev $IMQ0 parent 1: protocol ip prio 1 u32 match ip protocol 1 0xff flowid 1: 2>/dev/null $TC filter del dev $IMQ1 parent 1: protocol ip prio 1 u32 match ip protocol 1 0xff flowid 1: 2>/dev/null else $IPTABLES -t raw -F ICMP_DST 2>/dev/null $IPTABLES -t raw -F ICMP_SRC 2>/dev/null $IPTABLES -t raw -F SYN_DST 2>/dev/null $IPTABLES -t raw -F SYN_SRC 2>/dev/null $IPTABLES -t raw -F UDP_DST 2>/dev/null $IPTABLES -t raw -F UDP_SRC 2>/dev/null $TC filter add dev $IMQ0 parent 1: protocol ip prio 1 u32 match ip protocol 1 0xff flowid 1: 2>/dev/null $TC filter add dev $IMQ1 parent 1: protocol ip prio 1 u32 match ip protocol 1 0xff flowid 1: 2>/dev/null echo "Ochrona przed floodami icmp i syn z LAN'u wyłączona" fi }