Configuration firewall - protection DOS

Bonsoir,

je viens de me lancer dans un petit script pour configurer mon firewall avec des services classiques (http/dns/ssh) tout en étant protégé contre les DOS.

Ma configuration doit accepté l’icmp “avec modération” cependant tous les paquets se font jetés ! Une idée ?

$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 6.0.2 (squeeze) Release: 6.0.2 Codename: squeeze $ uname -a Linux kimsufi 2.6.39.1-last-grsec-xxxx-std-ipv6-64 #2 SMP Sat Jun 18 14:53:00 CEST 2011 x86_64 GNU/Linux
Script basé sur

#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
 
# Services que le systèmes offrira au réseau
# SSH : 22
# DNS : 53
# WEB : 80 443 8080
TCP_SERVICES="22 53 80 443 8080"

# DNS 53
# DHCP 67 68
UDP_SERVICES="53 67 68 138"

# Services que le système utilisera du réseau
# DNS 53
# WEB 80 443
REMOTE_TCP_SERVICES="22 53 80 443"

# DNS 31
# DHCP 67 68 138
# ntp
REMOTE_UDP_SERVICES="53 67 68 123 138"
 
if ! [ -x /sbin/iptables ]; then  
    exit 0
fi
 
fw_start () {

# Nettoyage
	/sbin/iptables --flush
 
# Création de la chaine LOGDROP : Suppression+LOG
	/sbin/iptables -N LOGDROP > /dev/null 2> /dev/null
	/sbin/iptables -F LOGDROP
	/sbin/iptables -A LOGDROP -m limit -j LOG --log-prefix "[DROP-IN] "
	/sbin/iptables -A LOGDROP -j DROP

# Création de la chaine LOGDROP : Suppression+LOG
	/sbin/iptables -N DROPFLOOD > /dev/null 2> /dev/null
	/sbin/iptables -F DROPFLOOD
	/sbin/iptables -A DROPFLOOD -m limit -j LOG --log-prefix "[DROP-FLOOD] "
	/sbin/iptables -A DROPFLOOD -j DROP

#############################   TRAFFIC ENTRAN    ################################

# Traffic local	
	sbin/iptables -A INPUT -i lo -j ACCEPT
  
# Session déjà établie
	/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  
# Services TCP
	if [ -n "$TCP_SERVICES" ] ; then
		for PORT in $TCP_SERVICES; do
			/sbin/iptables -A INPUT -p tcp --dport ${PORT} -j ACCEPT
		done
	fi
# Services UDP
	if [ -n "$UDP_SERVICES" ] ; then
		for PORT in $UDP_SERVICES; do
			/sbin/iptables -A INPUT -p udp --dport ${PORT} -j ACCEPT
		done
	fi
 
# A Virer en prod (test vmware)
	/sbin/iptables -A INPUT -s 172.16.52.1 -p udp --dport 17500 -j ACCEPT
  

############ Protection contre le flood
  
# Chaine ICMP flood
	/sbin/iptables -N icmp-flood
# On entre dans la chaine pour l'icmp
	/sbin/iptables -A INPUT  -p icmp -j icmp-flood
# Get out of chain if packet rate for the same IP is below 4 per second with a burst of 8 per second
	/sbin/iptables -A icmp-flood -m limit --limit 4/s --limit-burst 8  -m comment --comment "[DROP-IN-ICMP-FLOOD][Limit ICMP rate] " -j RETURN
# Log as flood when rate is higher
	/sbin/iptables -A icmp-flood -m limit --limit 6/h --limit-burst 1 -j LOG --log-prefix "[DROP-IN-ICMP-FLOOD] "
# Blacklist IP for 3 minutes
	/sbin/iptables -A icmp-flood -m recent --name blacklist_180 --set -m comment --comment "[DROP-IN-ICMP-FLOOD][Blacklist source IP] " -j DROPFLOOD


# Chaine  UDP flood
 	/sbin/iptables -N udp-flood
 	/sbin/iptables -F udp-flood
# Jump to chain if UDP
 	/sbin/iptables -A INPUT  -p  udp -j udp-flood
# Limit UDP rate to 10/sec with burst at 20 (sometimes it is not enough, if you know a better average rate, let me know!)
 	/sbin/iptables -A udp-flood -m limit --limit 5/s --limit-burst 20 -m comment --comment "[DROP-IN-UDP-FLOOD][Limit UDP rate] " -j RETURN
# Log
 	/sbin/iptables -A udp-flood -m limit --limit 6/h --limit-burst 1 -j LOG --log-prefix "[DROP-IN-UDP-FLOOD] "
# 3 minutes ban for flooders
 	/sbin/iptables -A udp-flood -m recent --name blacklist_180 --set -m comment --comment "[DROP-IN-UDP-FLOOD][Blacklist source IP] " -j DROPFLOOD


# Create syn-flood chain
 	/sbin/iptables -N syn-flood > /dev/null 2> /dev/null
 	/sbin/iptables -F syn-flood
# Jump into syn-flood chain when a syn packet is detected
 	/sbin/iptables -A INPUT  -p tcp --syn -j syn-flood
# Limit packet rate to 2 per second with a 6 per second burst
 	/sbin/iptables -A syn-flood -m limit --limit 2/s --limit-burst 6 -m comment --comment "[DROP-IN-UDP-FLOOD][Limit TCP SYN rate] " -j RETURN
# Log flooders
 	/sbin/iptables -A syn-flood -m limit --limit 6/h --limit-burst 1 -j LOG --log-prefix "[DROP-IN-SYN-FLOOD] "
# Ban flooders for 3 minutes
 	/sbin/iptables -A syn-flood -m recent --name blacklist_180 --set  -m comment --comment "[DROP-IN-UDP-FLOOD][Blacklist source IP]" -j DROPFLOOD


 # Log des autres paquets qui seront supprimés
	/sbin/iptables -A INPUT -j LOGDROP
 	/sbin/iptables --policy INPUT DROP

###################################   SORTIE    ################################

	/sbin/iptables -A OUTPUT -j ACCEPT -o lo 
	/sbin/iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# ICMP est permis
	/sbin/iptables -A OUTPUT -p icmp -j ACCEPT

# Ainsi que pour tous les services que nous avons définis
	if [ -n "$REMOTE_TCP_SERVICES" ] ; then
		for PORT in $REMOTE_TCP_SERVICES; do
			/sbin/iptables -A OUTPUT -p tcp --dport ${PORT} -j ACCEPT
		done
	fi

	if [ -n "$REMOTE_UDP_SERVICES" ] ; then
		for PORT in $REMOTE_UDP_SERVICES; do
			/sbin/iptables -A OUTPUT -p udp --dport ${PORT} -j ACCEPT
		done
	fi
  
  
# Toutes les autres connexions sont enregistrées dans syslog
	/sbin/iptables -A OUTPUT -j LOG --log-prefix '[DROP-OUT] '
	/sbin/iptables -A OUTPUT -j REJECT 
	/sbin/iptables --policy OUTPUT DROP

# Autres protections réseau
	echo 1 > /proc/sys/net/ipv4/tcp_syncookies
	echo 0 > /proc/sys/net/ipv4/ip_forward 
	echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts 
	echo 1 > /proc/sys/net/ipv4/conf/all/log_martians 
	echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
	echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
	echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
	echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
}
 
fw_stop () {
	/sbin/iptables -F
	/sbin/iptables -t nat -F
	/sbin/iptables -t mangle -F
	/sbin/iptables -P INPUT ACCEPT
	/sbin/iptables -P FORWARD DROP
	/sbin/iptables -P OUTPUT ACCEPT
}
 
fw_clear () {
	/sbin/iptables -F
	/sbin/iptables -t nat -F
	/sbin/iptables -t mangle -F
 	/sbin/iptables -P INPUT ACCEPT
	/sbin/iptables -P FORWARD ACCEPT
	/sbin/iptables -P OUTPUT ACCEPT
}
 
 
case "$1" in
 	start|restart)
 		echo -n "Starting firewall.."
		fw_stop 
		fw_start
    		echo "done."
	;;
	stop)
		echo -n "Stopping firewall.."
		fw_stop
		echo "done."
	;;
	clear)
		echo -n "Clearing firewall rules.."
		fw_clear
		echo "done."
	;;
 	*)
		echo "Usage: $0 {start|stop|restart|clear}"
		exit 1
	;;
	esac
exit 0

iptables -L

$ iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:domain 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:www 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http-alt 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:bootps 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:bootpc 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:netbios-dgm 
ACCEPT     udp  --  172.16.52.1          anywhere            udp dpt:17500 
icmp-flood  icmp --  anywhere             anywhere            
udp-flood  udp  --  anywhere             anywhere            
syn-flood  tcp  --  anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN 
LOGDROP    all  --  anywhere             anywhere            

Chain FORWARD (policy DROP)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:domain 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:www 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:bootps 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:bootpc 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:ntp 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:netbios-dgm 
LOG        all  --  anywhere             anywhere            LOG level warning prefix `[DROP-OUT] ' 
REJECT     all  --  anywhere             anywhere            reject-with icmp-port-unreachable 

Chain DROPFLOOD (3 references)
target     prot opt source               destination         
LOG        all  --  anywhere             anywhere            limit: avg 3/hour burst 5 LOG level warning prefix `[DROP-FLOOD] ' 
DROP       all  --  anywhere             anywhere            

Chain LOGDROP (1 references)
target     prot opt source               destination         
LOG        all  --  anywhere             anywhere            limit: avg 3/hour burst 5 LOG level warning prefix `[DROP-IN] ' 
DROP       all  --  anywhere             anywhere            

Chain icmp-flood (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            limit: avg 4/sec burst 8 /* [DROP-IN-ICMP-FLOOD][Limit ICMP rate]  */ 
LOG        all  --  anywhere             anywhere            limit: avg 6/hour burst 1 LOG level warning prefix `[DROP-IN-ICMP-FLOOD] ' 
DROPFLOOD  all  --  anywhere             anywhere            recent: SET name: blacklist_180 side: source /* [DROP-IN-ICMP-FLOOD][Blacklist source IP]  */ 

Chain syn-flood (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            limit: avg 2/sec burst 6 /* [DROP-IN-UDP-FLOOD][Limit TCP SYN rate]  */ 
LOG        all  --  anywhere             anywhere            limit: avg 6/hour burst 1 LOG level warning prefix `[DROP-IN-SYN-FLOOD] ' 
DROPFLOOD  all  --  anywhere             anywhere            recent: SET name: blacklist_180 side: source /* [DROP-IN-UDP-FLOOD][Blacklist source IP] */ 

Chain thyl-icmp-flood (0 references)
target     prot opt source               destination         

Chain thyl-syn-flood (0 references)
target     prot opt source               destination         

Chain thyl-udp-flood (0 references)
target     prot opt source               destination         

Chain udp-flood (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            limit: avg 5/sec burst 20 /* [DROP-IN-UDP-FLOOD][Limit UDP rate]  */ 
LOG        all  --  anywhere             anywhere            limit: avg 6/hour burst 1 LOG level warning prefix `[DROP-IN-UDP-FLOOD] ' 
DROPFLOOD  all  --  anywhere             anywhere            recent: SET name: blacklist_180 side: source /* [DROP-IN-UDP-FLOOD][Blacklist source IP]  */ 

Paquets jetés :

Jul 14 19:53:59 kimsufi kernel: [DROP-IN] IN=eth0 OUT= MAC=00:0c:29:10:8f:de:00:50:56:c0:00:08:08:00 SRC=172.16.52.1 DST=172.16.52.128 LEN=84 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=3334 SEQ=1 Jul 14 19:54:00 kimsufi kernel: [DROP-IN] IN=eth0 OUT= MAC=00:0c:29:10:8f:de:00:50:56:c0:00:08:08:00 SRC=172.16.52.1 DST=172.16.52.128 LEN=84 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=3334 SEQ=2

P.S : Oui mon post est une fois de plus long :mrgreen:

Tu confonds ICMP et ping. Le ping n’est qu’un type ICMP parmi d’autres. En fait deux, puisqu’il y a un type de requête (echo request, 8 ) et un type de réponse (echo reply, 0 ). Pour information, les types ICMP les plus importants sont ceux qui signalent des erreurs relatives à d’autres paquets émis ou reçus, et ceux-là sont normalement classés dans l’état RELATED par le suivi de connexion. La réponse à un ping émis ou reçu est pour sa part classée dans l’état ESTABLISHED.

Pour en revenir à ton script, plusieurs remarques :

  • Les règles qui limitent les paquets se terminent par RETURN, les paquets non bloqués retournent donc dans la chaîne principale, d’où ils sont envoyés illico dans la chaîne LOGDROP. Pas étonnant que ça coince.

  • Les règles de soi-disant protection anti-flood sont placées après les règles qui acceptent les paquets vers les ports autorisés. La protection est donc sans effet sur ces ports. Et elle est inutile sur les autres ports puisque les paquets sont in fine bloqués de toute façon.

  • La mise au ban est sans effet puisque nulle part ton jeu de règle ne vérifie si une adresse source est dans la blacklist.

Ok, merci pour ces conseils.

Voici une petite MAJ pour les services TCP :

#############################   TRAFFIC ENTRANT    ############################

# Traffic local	
	/sbin/iptables -A INPUT -i lo -j ACCEPT
  
# Session déjà établie
	/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j 

############ Protection contre le flood #######################################
 
# Création d'une chaine de BlackList
	/sbin/iptables -N BLACKLIST > /dev/null 2> /dev/null
	/sbin/iptables -F BLACKLIST
	# Quand le paquet arrive, on le LOG
	/sbin/iptables -A BLACKLIST -m limit -j LOG --log-prefix "[DROP-BLACKLIST] "
	# Puis on le DROP
	/sbin/iptables -A BLACKLIST -m recent --name BLACKLIST --set -j DROP
	# Et on bloque les autres paquets de cette source pendant 600s
	/sbin/iptables -A INPUT -m recent --update --name BLACKLIST --seconds 600 --rttl -j DROP

# SSH 
	/sbin/iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --name COUNTER_SSH --set
	/sbin/iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --name COUNTER_SSH --update --seconds 10 --hitcount 2 --rttl -j BLACKLIST 
	/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# DNS (et il y a aussi l'UDP bien sur...)
	/sbin/iptables -A INPUT -p tcp --dport 53 -m state --state NEW -m recent --name COUNTER_DNS --set
	/sbin/iptables -A INPUT -p tcp --dport 53 -m state --state NEW -m recent --name COUNTER_DNS --update --seconds 10 --hitcount 10 --rttl -j BLACKLIST 
	/sbin/iptables -A INPUT -p tcp --dport 53 -j ACCEPT

On est déjà mieux ? (mes tests sont concluants)

Et hop, le script complet qui fonctionne d’après quelques tests rapide. Je suis ouvert à tous commentaires !

[code]#!/bin/sh

BEGIN INIT INFO

Provides: firewall

Required-Start: mountkernfs ifupdown $local_fs

X-Start-Before: networking

Default-Start: 2 3 4 5

Required-Stop:

Default-Stop: 0 1 6

Short-Description: Configure the ip(6)tables firewall.

Description: Configure the ip(6)tables firewall.

END INIT INFO

Exemple de configuration de pare-feu

Défauts :

- Cette configuration s’applique à toutes les interfaces réseau.

Si vous voulez ne restreindre cela qu’à une interface donnée,

utilisez ‘-i INTERFACE’ dans les appels iptables.

- L’accès à distance pour les services TCP/UDP est accordé à tout

hôte, vous voudrez probablement restreindre cela en utilisant

‘–source’

chkconfig: 2345 9 91

description: Active/Désactive le pare-feu au démarrage

Vous pouvez tester ce script avant de l’appliquer avec l’extrait de

shell suivant, si vous ne tapez rien pendant 20 secondes, les

règles de pare-feu seront effacées.

#---------------------------------------------------------------

while true; do test=""; read -t 60 -p “OK pour 1 min ?” test ; \

[ -z “$test” ] && /etc/init.d/firewall clear ; done

#---------------------------------------------------------------

PATH=/bin:/sbin:/usr/bin:/usr/sbin

DNS 53

DHCP 67 68

UDP_SERVICES=“53 67 68 138”

Services que le système utilisera du réseau

DNS 53

WEB 80 443

REMOTE_TCP_SERVICES=“22 53 80 443”

DNS 31

DHCP 67 68 138

ntp

REMOTE_UDP_SERVICES=“53 67 68 123 138”

if ! [ -x /sbin/iptables ]; then
exit 0
fi

fw_start () {

Nettoyage

/sbin/iptables --flush

############################# TRAFFIC ENTRANT ############################

Création de la chaine LOGDROP : Suppression+LOG

/sbin/iptables -N LOGDROP > /dev/null 2> /dev/null
/sbin/iptables -F LOGDROP
/sbin/iptables -A LOGDROP -m limit -j LOG --log-prefix "[DROP-IN] "
/sbin/iptables -A LOGDROP -j DROP

Traffic local

/sbin/iptables -A INPUT -i lo -j ACCEPT

Session déjà établie

/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

###################### Protection contre les scans #############################
/sbin/iptables -N SCANS
/sbin/iptables -A SCANS -p tcp --tcp-flags FIN,URG,PSH FIN,URG,PSH -j DROP
/sbin/iptables -A SCANS -p tcp --tcp-flags ALL ALL -j DROP
/sbin/iptables -A SCANS -p tcp --tcp-flags ALL NONE -j DROP
/sbin/iptables -A SCANS -p tcp --tcp-flags SYN,RST SYN,RST -j DROP

/sbin/iptables -A INPUT -m state --state INVALID -j DROP

###################### Protection contre le flood ##############################

Création d’une chaine de BlackList

/sbin/iptables -N BLACKLIST > /dev/null 2> /dev/null
/sbin/iptables -F BLACKLIST
# Quand le paquet arrive, on le LOG
/sbin/iptables -A BLACKLIST -m limit -j LOG --log-prefix "[DROP-BLACKLIST] "
# Puis on le DROP
/sbin/iptables -A BLACKLIST -m recent --name BLACKLIST --set -j DROP
# Et on bloque les autres paquets de cette source pendant 600s
/sbin/iptables -A INPUT -m recent --update --name BLACKLIST --seconds 600 --rttl -j DROP

Création d’une chaine pour limiter le syn flood

/sbin/iptables -N syn-flood 
/sbin/iptables -A syn-flood -m limit --limit 10/s --limit-burst 25 -j RETURN
/sbin/iptables -A syn-flood -m limit --limit 1/s -j LOG --log-prefix "[SYN FLOOD]" 
/sbin/iptables -A syn-flood -j DROP

Création d’une chaine pour limiter l’icmp flood

/sbin/iptables -N icmp-flood 
/sbin/iptables -A icmp-flood -m limit --limit 1/s -j LOG --log-prefix "[ICMP FLOOD]" 
/sbin/iptables -A icmp-flood -j ACCEPT

SSH

/sbin/iptables -A INPUT -p tcp --dport 22 --syn -j syn-flood 
/sbin/iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --name COUNTER_SSH --set
/sbin/iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --name COUNTER_SSH --update --seconds 10 --hitcount 2 --rttl -j BLACKLIST 
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT

DNS

/sbin/iptables -A INPUT -p tcp --dport 53 -m state --state NEW -m recent --name COUNTER_DNS --set
/sbin/iptables -A INPUT -p tcp --dport 53 -m state --state NEW -m recent --name COUNTER_DNS --update --seconds 10 --hitcount 10 --rttl -j BLACKLIST 
/sbin/iptables -A INPUT -p tcp --dport 53 -j ACCEPT

HTTP

/sbin/iptables -A INPUT -p tcp --dport 80 -m state --state NEW -m recent --name COUNTER_HTTP --set
/sbin/iptables -A INPUT -p tcp --dport 80 -m state --state NEW -m recent --name COUNTER_HTTP --update --seconds 5 --hitcount 50 --rttl -j BLACKLIST 
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT

HTTPS

/sbin/iptables -A INPUT -p tcp --dport 443 -m state --state NEW -m recent --name COUNTER_HTTP --set
/sbin/iptables -A INPUT -p tcp --dport 443 -m state --state NEW -m recent --name COUNTER_HTTP --update --seconds 5 --hitcount 20 --rttl -j BLACKLIST 
/sbin/iptables -A INPUT -p tcp --dport 443 -j ACCEPT

ICMP

/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j icmp-flood
/sbin/iptables -A INPUT -p icmp --icmp-type echo-reply -m limit --limit 1/s -j icmp-flood

Fragments

/sbin/iptables -A INPUT -f -j LOG --log-prefix "[DROP FRAGMENT] " 
/sbin/iptables -A INPUT -f -j DROP

Création d’une chaine pour limiter le flood udp

/sbin/iptables -N udp-flood 
/sbin/iptables -A udp-flood -m limit --limit 1/s --limit-burst 5 -j RETURN
/sbin/iptables -A udp-flood -m limit --limit 1/s -j LOG --log-prefix "[UDP FLOOD]" 
/sbin/iptables -A udp-flood -j DROP

Inspection de tous les paquets UDP

/sbin/iptables -A INPUT  -p udp -j udp-flood 

Services UDP

if [ -n "$UDP_SERVICES" ] ; then
	for PORT in $UDP_SERVICES; do
		/sbin/iptables -A INPUT -p udp --dport ${PORT} -j ACCEPT
	done
fi

A Virer en prod (test vmware)

/sbin/iptables -A INPUT -s 172.16.52.1 -p udp --dport 17500 -j ACCEPT

Log des autres paquets qui seront supprimés

/sbin/iptables -A INPUT -j LOGDROP
/sbin/iptables --policy INPUT DROP

################################### SORTIE ################################

Création de la chaine LOGDROPOUT : Suppression+LOG

/sbin/iptables -N LOGDROPOUT > /dev/null 2> /dev/null
/sbin/iptables -F LOGDROPOUT
/sbin/iptables -A LOGDROPOUT -m limit -j LOG --log-prefix "[DROP-OUT] "
/sbin/iptables -A LOGDROPOUT -j DROP


/sbin/iptables -A OUTPUT -j ACCEPT -o lo 
/sbin/iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

ICMP est permis

/sbin/iptables -A OUTPUT -p icmp -j ACCEPT

Ainsi que pour tous les services que nous avons définis

if [ -n "$REMOTE_TCP_SERVICES" ] ; then
	for PORT in $REMOTE_TCP_SERVICES; do
		/sbin/iptables -A OUTPUT -p tcp --dport ${PORT} -j ACCEPT
	done
fi

if [ -n "$REMOTE_UDP_SERVICES" ] ; then
	for PORT in $REMOTE_UDP_SERVICES; do
		/sbin/iptables -A OUTPUT -p udp --dport ${PORT} -j ACCEPT
	done
fi

Toutes les autres connexions sont enregistrées dans syslog

/sbin/iptables -A OUTPUT -j LOG --log-prefix '[DROP-OUT] '
/sbin/iptables -A OUTPUT -j REJECT 
/sbin/iptables --policy OUTPUT DROP

Autres protections réseau

echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo 0 > /proc/sys/net/ipv4/ip_forward 
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts 
echo 1 > /proc/sys/net/ipv4/conf/all/log_martians 
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route

}

fw_stop () {
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -t mangle -F
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P OUTPUT ACCEPT
}

fw_clear () {
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -t mangle -F
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
}

case “$1” in
start|restart)
echo -n "Starting firewall…"
fw_stop
fw_start
echo “done.”
;;
stop)
echo -n "Stopping firewall…"
fw_stop
echo “done.”
;;
clear)
echo -n "Clearing firewall rules…"
fw_clear
echo “done.”
;;
*)
echo "Usage: $0 {start|stop|restart|clear}"
exit 1
;;
esac
exit 0
[/code]

EDIT : Auto commentaire : Ajouter ip6tables…