par tetack » 06 Nov 2002 15:16
voila mes regles :
<BR>
<BR>a titre d'info : gun serveur Edonkey dans mon reseau privé, qui est aussi la machine ou je joue a warcraft.
<BR>
<BR>ma DMZ est située sur un autre reseau ( eth1)
<BR>
<BR><!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-2>En réponse à:</font><HR></TD></TR><TR><TD><FONT SIZE=-2><BLOCKQUOTE> #!/bin/sh
<BR>
<BR>
<BR>echo ""
<BR>echo "* Demarrage/Arret du Firewall *"
<BR>echo ""
<BR>
<BR>######## Chemin vers Iptables
<BR> IPT="/sbin/iptables"
<BR>
<BR>case "$1" in
<BR> start)
<BR>
<BR> echo "Start Iptables rules ..."
<BR>
<BR>
<BR>######## Definition des interfaces
<BR># echo "Define interfaces ..."
<BR>
<BR> DMZ_IF="eth1"
<BR> DMZ_AD="192.168.10.100"
<BR>
<BR> BAD_IF="ppp0"
<BR> BAD_AD="0.0.0.0/4"
<BR>
<BR> PRV_IF="eth0"
<BR> PRV_AD="192.168.0.0/24"
<BR>
<BR> SRV_EXT="192.168.10.1"
<BR> SRV_DONKEY="192.168.0.1"
<BR>
<BR> LO_IF="lo"
<BR> LO_AD="127.0.0.1"
<BR>
<BR>######## Vidage des chaines
<BR># echo "Flush tables ..."
<BR>
<BR> $IPT -P INPUT ACCEPT
<BR> $IPT -P FORWARD ACCEPT
<BR> $IPT -P OUTPUT ACCEPT
<BR> $IPT -t nat -P PREROUTING ACCEPT
<BR> $IPT -t nat -P POSTROUTING ACCEPT
<BR> $IPT -t nat -P OUTPUT ACCEPT
<BR> $IPT -t mangle -P PREROUTING ACCEPT
<BR> $IPT -t mangle -P OUTPUT ACCEPT
<BR>
<BR># echo "Flush all rules and chains ..."
<BR>
<BR> $IPT -F
<BR> $IPT -X
<BR> $IPT -t nat -F
<BR> $IPT -t nat -X
<BR> $IPT -t mangle -F
<BR> $IPT -t mangle -X
<BR>
<BR>
<BR>######## Affectation des regles par defaut (DROP)
<BR># echo "Set Policies ..."
<BR>
<BR> $IPT -P INPUT DROP
<BR> $IPT -P OUTPUT DROP
<BR> $IPT -P FORWARD DROP
<BR>
<BR>######## Creation de chaines personnelles
<BR> # Une chaine par direction
<BR> # bad = ppp0 pour l acces internet
<BR> # dmz = eth0 pour l acces au reseau local
<BR># echo "Create non-default chains ..."
<BR>
<BR> $IPT -N commun
<BR> $IPT -N bad-dmz
<BR> $IPT -N prv-dmz
<BR> $IPT -N dmz-bad
<BR> $IPT -N prv-bad
<BR> $IPT -N bad-prv
<BR> $IPT -N dmz-prv
<BR> $IPT -N icmp-acc
<BR> $IPT -N log-n-drop
<BR> $IPT -F commun
<BR> $IPT -F bad-dmz
<BR> $IPT -F prv-dmz
<BR> $IPT -F dmz-bad
<BR> $IPT -F prv-bad
<BR> $IPT -F bad-prv
<BR> $IPT -F dmz-prv
<BR> $IPT -F icmp-acc
<BR> $IPT -F log-n-drop
<BR>
<BR>
<BR>######## Chaine speciale pour logguer les paquets
<BR># echo "Create log chains ..."
<BR>#
<BR># $IPT -A log-n-drop -m limit --limit 5/m -j LOG --log-prefix "IPT DROP : "
<BR> $IPT -A log-n-drop -j DROP
<BR>
<BR>######## Definition des regles
<BR> echo "Define rules ..."
<BR>
<BR>######## Elimination des paquets de demande de connection n ayant pas le flag SYN active
<BR># echo "Define protection rules ..."
<BR>
<BR> $IPT -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
<BR> $IPT -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
<BR>
<BR>######## Elimination des paquets avec aucun ou tous les flags TCP actives
<BR> # (Protection contre les tests de port furtif)
<BR> $IPT -A FORWARD -p tcp --tcp-flag ALL ALL -j DROP
<BR> $IPT -A FORWARD -p tcp --tcp-flag ALL NONE -j DROP
<BR> $IPT -A INPUT -p tcp --tcp-flag ALL ALL -j DROP
<BR> $IPT -A INPUT -p tcp --tcp-flag ALL NONE -j DROP
<BR>
<BR>######## Protection syn-flood
<BR> $IPT -A FORWARD -p tcp --syn -m limit --limit 5/m -j ACCEPT
<BR> $IPT -A INPUT -p tcp --syn -m limit --limit 5/m -j ACCEPT
<BR>
<BR>######## Activation du masquerading
<BR># echo "Define MASQUERADE rules ..."
<BR>
<BR> $IPT -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
<BR>
<BR>######## Redirection des connexions destinees au serveurs HTTP et FTP
<BR># echo "Define PREROUTING rules ..."
<BR>
<BR> $IPT -t nat -A PREROUTING -p tcp --dport 80 -i $BAD_IF -j DNAT --to $SRV_EXT:80
<BR> $IPT -t nat -A PREROUTING -p tcp --dport 20 -i $BAD_IF -j DNAT --to $SRV_EXT:20
<BR> $IPT -t nat -A PREROUTING -p tcp --dport 21 -i $BAD_IF -j DNAT --to $SRV_EXT:21
<BR> $IPT -t nat -A PREROUTING -p tcp --dport 4661 -i $BAD_IF -j DNAT --to $SRV_DONKEY:4661
<BR> $IPT -t nat -A PREROUTING -p tcp --dport 4662 -i $BAD_IF -j DNAT --to $SRV_DONKEY:4662
<BR> $IPT -t nat -A PREROUTING -p udp --dport 4665 -i $BAD_IF -j DNAT --to $SRV_DONKEY:4665
<BR>###### Warcraft 3 !
<BR> $IPT -t nat -A PREROUTING -p tcp --dport 6111 -i $BAD_IF -j DNAT --to $SRV_DONKEY:6111
<BR> $IPT -t nat -A PREROUTING -p tcp --dport 6112 -i $BAD_IF -j DNAT --to $SRV_DONKEY:6112
<BR> $IPT -t nat -A PREROUTING -p udp --dport 6112 -i $BAD_IF -j DNAT --to $SRV_DONKEY:6112
<BR> $IPT -t nat -A PREROUTING -p udp --dport 6111 -i $BAD_IF -j DNAT --to $SRV_DONKEY:6111
<BR>
<BR>
<BR>
<BR>
<BR>######## Blocage des paquets avec classes d adresses reservees ainsi que le multicast
<BR># echo "Define FORWARD rules ..."
<BR>
<BR> $IPT -A FORWARD -i $BAD_IF -s 224.0.0.0/4 -j DROP
<BR> $IPT -A FORWARD -i $BAD_IF -s 192.168.0.0/16 -j DROP
<BR> $IPT -A FORWARD -i $BAD_IF -s 10.0.0.0/8 -j DROP
<BR> $IPT -A FORWARD -i $PRV_IF ! -s $PRV_AD -j DROP
<BR> $IPT -A FORWARD -i $DMZ_IF ! -s $DMZ_AD -j DROP
<BR>
<BR>######## On accepte les connexions deja etablies on log et drop les invalides
<BR># echo "Define STATE rules ..."
<BR>
<BR> $IPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
<BR> $IPT -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
<BR> $IPT -A FORWARD -m state --state INVALID -j DROP
<BR> $IPT -A INPUT -m state --state INVALID -j DROP
<BR> $IPT -A INPUT -p tcp -j DROP
<BR>
<BR>######## Transmission a la chaine correspondant au sens d arrivee des paquets
<BR>
<BR> # En provenance de la DMZ vers internet
<BR> $IPT -A FORWARD -s $DMZ_AD -i $DMZ_IF -o $BAD_IF -j dmz-bad
<BR>
<BR> # En provenance du reseau local vers internet
<BR> $IPT -A FORWARD -s $PRV_AD -i $PRV_IF -o $BAD_IF -j prv-bad
<BR>
<BR> # En provenance d internet vers le reseau local
<BR> $IPT -A FORWARD -i $BAD_IF -o $PRV_IF -j bad-prv
<BR>
<BR> # En provenance de la DMZ vers le reseau local
<BR> $IPT -A FORWARD -s $DMZ_AD -i $DMZ_IF -o $PRV_IF -j dmz-prv
<BR>
<BR> # En provenance d internet vers la DMZ
<BR> $IPT -A FORWARD -i $BAD_IF -o $DMZ_IF -j bad-dmz
<BR>
<BR> # En provenance du reseau local vers la DMZ
<BR> $IPT -A FORWARD -s $PRV_AD -i $PRV_IF -o $DMZ_IF -j prv-dmz
<BR>
<BR>
<BR> # On log et drop le reste
<BR># $IPT -A FORWARD -j log-n-drop
<BR> $IPT -A FORWARD -j DROP
<BR>
<BR>######## On log et accepte les requetes ICMP
<BR># echo "Define ICMP rules ..."
<BR>
<BR># $IPT -A icmp-acc -p icmp --icmp-type echo-request -m limit --limit 5/m -j LOG --log-prefix "IPT ICMP : "
<BR> $IPT -A icmp-acc -p icmp --icmp-type destination-unreachable -j ACCEPT
<BR> $IPT -A icmp-acc -p icmp --icmp-type source-quench -j ACCEPT
<BR> $IPT -A icmp-acc -p icmp --icmp-type time-exceeded -j ACCEPT
<BR> $IPT -A icmp-acc -p icmp --icmp-type echo-request -j ACCEPT
<BR> $IPT -A icmp-acc -p icmp --icmp-type echo-reply -j ACCEPT
<BR># $IPT -A icmp-acc -p icmp --icmp-type echo-request -m limit --limit 20/m -j ACCEPT
<BR># $IPT -A icmp-acc -p icmp --icmp-type echo-reply -m limit --limit 20/m -j ACCEPT
<BR>
<BR>######## On drop et log le reste
<BR># $IPT -A icmp-acc -j log-n-drop
<BR> $IPT -A icmp-acc -j DROP
<BR>
<BR>######## Chaine commun
<BR> # On accepte les services mail, DNS, HTTP(S), SSH et FTP
<BR># echo "Define commun rules ..."
<BR>
<BR> $IPT -A commun -p tcp --dport smtp -j ACCEPT
<BR> $IPT -A commun -p tcp --dport domain -j ACCEPT
<BR> $IPT -A commun -p udp --dport domain -j ACCEPT
<BR> $IPT -A commun -p tcp --dport www -j ACCEPT
<BR> $IPT -A commun -p tcp --dport https -j ACCEPT
<BR> $IPT -A commun -p tcp --dport 20:21 -j ACCEPT
<BR> $IPT -A commun -p tcp --dport ssh -j ACCEPT
<BR> $IPT -A commun -p icmp -j icmp-acc
<BR>
<BR>######## Chaine BAD --> DMZ
<BR> # On accepte les services commun
<BR># echo "Define BAD --> DMZ rules ..."
<BR>
<BR> $IPT -A bad-dmz -j commun
<BR> $IPT -A bad-dmz -j log-n-drop
<BR>
<BR>######## Chaine DMZ --> BAD
<BR> # On accepte les services commun
<BR># echo "Define DMZ --> BAD rules ..."
<BR>
<BR> $IPT -A dmz-bad -j commun
<BR> $IPT -A dmz-bad -j log-n-drop
<BR>
<BR>######## Chaine DMZ --> PRV
<BR> # On accepte les services commun
<BR># echo "Define DMZ --> PRV rules ..."
<BR>
<BR> $IPT -A dmz-prv -j commun
<BR> $IPT -A dmz-prv -j log-n-drop
<BR>
<BR>######## Chaine PRV --> DMZ
<BR> # On accepte les services commun
<BR># echo "Define DMZ --> PRV rules ..."
<BR>
<BR> $IPT -A prv-dmz -j commun
<BR> $IPT -A prv-dmz -j log-n-drop
<BR>
<BR>######## Chaine DMZ --> PRV
<BR># On accepte les services commun
<BR># echo "Define BAD --> PRV rules ..."
<BR>
<BR> $IPT -A bad-prv -j commun
<BR> $IPT -A bad-prv -m multiport -p tcp --dport 4661,4662 -j ACCEPT
<BR> $IPT -A bad-prv -p udp --dport 4665 -j ACCEPT
<BR>###### warcraft 3
<BR> $IPT -A bad-prv -m multiport -p tcp --dport 6111,6112 -j ACCEPT
<BR> $IPT -A bad-prv -m multiport -p udp --dport 6111,6112 -j ACCEPT
<BR> $IPT -A bad-prv -j log-n-drop
<BR>
<BR>######## Chaine PRV --> BAD
<BR> # On accepte en plus le donkey
<BR># echo "Define PRV --> BAD rules ..."
<BR>
<BR> $IPT -A prv-bad -j commun
<BR> $IPT -A prv-bad -m multiport -p tcp --sport 4661,4662 -j ACCEPT
<BR> $IPT -A prv-bad -p udp --sport 4665 -j ACCEPT
<BR>###### warcraft 3
<BR> $IPT -A prv-bad -m multiport -p tcp --dport 6111,6112 -j ACCEPT
<BR> $IPT -A prv-bad -m multiport -p udp --dport 6111,6112 -j ACCEPT
<BR>
<BR># $IPT -A prv-bad -j log-n-drop
<BR> $IPT -A prv-bad -j DROP
<BR>
<BR>######## Chaine pour la passerelle elle meme
<BR> $IPT -N bad-if
<BR> $IPT -N dmz-if
<BR> $IPT -N prv-if
<BR>
<BR>######## Chaine INPUT
<BR># echo "Define INPUT rules ..."
<BR>
<BR> $IPT -A INPUT -i $BAD_IF -j bad-if
<BR> $IPT -A INPUT -i $DMZ_IF -j dmz-if
<BR> $IPT -A INPUT -i $PRV_IF -j prv-if
<BR> #$IPT -A INPUT -p ALL -i $LO_IF -j commun
<BR>
<BR>######## Chaine OUTPUT
<BR># echo "Define OUTPUT rules ..."
<BR>
<BR> $IPT -A OUTPUT -m state -p icmp --state INVALID -j log-n-drop
<BR> $IPT -A OUTPUT -o $BAD_IF -j bad-if
<BR> $IPT -A OUTPUT -o $DMZ_IF -j dmz-if
<BR> $IPT -A OUTPUT -o $PRV_IF -j prv-if
<BR> #$IPT -A OUTPUT -p ALL -o $LO_IF -j commun
<BR>
<BR>######## Interface interne DMZ
<BR># echo "Define DMZ interface rules ..."
<BR>
<BR> $IPT -A dmz-if -p icmp -j icmp-acc
<BR> $IPT -A dmz-if -p ALL -j ACCEPT
<BR>
<BR>######## Interface externe Internet
<BR> # On accepte que les pings et SSH
<BR># echo "Define BAD interface rules ..."
<BR>
<BR> $IPT -A bad-if -p icmp -j icmp-acc
<BR> $IPT -A bad-if -p tcp --dport domain -j ACCEPT
<BR> $IPT -A bad-if -p udp --dport domain -j ACCEPT
<BR> $IPT -A bad-if -p tcp --dport www -j ACCEPT
<BR> $IPT -A bad-if -p tcp --dport https -j ACCEPT
<BR> $IPT -A bad-if -p tcp --dport 20:21 -j ACCEPT
<BR> $IPT -A bad-if -j log-n-drop
<BR>
<BR>######## Interface intrne Reseau local
<BR> # On accepte que les pings et SSH
<BR># echo "Define BAD interface rules ..."
<BR>
<BR> $IPT -A prv-if -p icmp -j icmp-acc
<BR> $IPT -A prv-if -p tcp --dport ssh -j ACCEPT
<BR> $IPT -A prv-if -p tcp --sport ssh -j ACCEPT
<BR> $IPT -A prv-if -p udp --dport 136:138 -j DROP
<BR># laisser temps que passerelle = pc de greg
<BR> $IPT -A prv-if -p tcp --dport domain -j ACCEPT
<BR> $IPT -A prv-if -p udp --dport domain -j ACCEPT
<BR> $IPT -A prv-if -p tcp --dport www -j ACCEPT
<BR> $IPT -A prv-if -p tcp --dport https -j ACCEPT
<BR> $IPT -A prv-if -p tcp --dport 20:21 -j ACCEPT
<BR>#########
<BR> $IPT -A prv-if -j log-n-drop
<BR>
<BR>######## Activation du forwarding de la passerelle
<BR># echo "Forwarding activation ..."
<BR>
<BR> echo 1 > /proc/sys/net/ipv4/ip_forward
<BR>
<BR> echo "Start Iptables rules OK ..."
<BR> ;;
<BR>
<BR> stop)
<BR># echo "Stop Iptables rules ..."
<BR> echo "Delete tables rules ..."
<BR>
<BR> #$IPT -F mangle
<BR> #$IPT -F mangle
<BR> #$IPT -F nat
<BR> #$IPT -F nat
<BR> #$IPT -F INPUT
<BR> #$IPT -F OUTPUT
<BR> #$IPT -F FORWARD
<BR> $IPT -F
<BR> $IPT -X
<BR>
<BR> # On ferme toutes les connections
<BR> echo "Close connexions ..."
<BR>
<BR> $IPT -P INPUT DROP
<BR> $IPT -P OUTPUT DROP
<BR> $IPT -P FORWARD DROP
<BR>
<BR> # Suppression des variables
<BR># echo "Delete variables ..."
<BR>
<BR> DMZ_IF=""
<BR> DMZ_AD=""
<BR> BAD_IF=""
<BR> BAD_AD=""
<BR> PRV_IF=""
<BR> PRV_AD=""
<BR> SRV_EXT=""
<BR> SRV_DONKEY=""
<BR> LO_IF=""
<BR> LO_AD=""
<BR>
<BR> echo "Stop Iptables rules OK ..."
<BR> ;;
<BR>
<BR> *)
<BR> # Pour tous les autres cas
<BR> # on rappelle la syntaxe du script et on quitte
<BR>
<BR> echo -n "Usage : $(basename $0) start|stop (start for restart) ..."
<BR> echo ""
<BR> exit 1
<BR>esac
<BR>
<BR>#
<BR>#--- end of filenk
<BR>
<BR></BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->
<BR>
<BR>
<BR>reste si tu regarde : une petite erreur de logique et une petite erreur de securité et quelques repetitions....
<BR>sinon je pense que c'est assez comenté !
<BR>
<BR>bon courage !
L'univers et la $%#&! humaine sont infini ... quoique pour l'univers je ne suis pas sur ! " <br>Albert Einstein