|
|
Ligne 137 : |
Ligne 137 : |
|
| |
|
| [[Catégorie:Aide]] | | [[Catégorie:Aide]] |
|
| |
| == Sujet du message: Règles iptables pour vos applications (pc de bureau). ==
| |
| <code bash>
| |
| #! /bin/sh
| |
| ### BEGIN INIT INFO
| |
| # Provides: iptables
| |
| # Required-Start:
| |
| # Required-Stop:
| |
| # Should-Start:
| |
| # Should-Stop:
| |
| # Default-Start: 1 2 3 4 5
| |
| # Default-Stop: 0 6
| |
| # Short-Description: script iptables
| |
| ### END INIT INFO
| |
|
| |
| # activer au demarage.
| |
| # en root avec su ou sudo
| |
| # cp ...iptables /etc/init.d/
| |
| # chown root:root /etc/init.d/iptables
| |
| # chmod 750 /etc/init.d/iptables
| |
| # update-rc.d iptables defaults
| |
| # /etc/init.d/iptables start
| |
|
| |
| on="1"
| |
| off="0"
| |
| PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
| |
| interface_WAN="eth0"
| |
| ##### règles appliquer ou non ######
| |
| ipblacklist=$off
| |
| pingexterne=$off
| |
| SecondeLife=$off
| |
| LandesEternelles=$on
| |
| transmition=$on
| |
| clientNTP=$on
| |
| amsn=$on
| |
| ###################################
| |
| start() {
| |
| ### SUPPRESSION de TOUTES LES ANCIENNES TABLES (OUVRE TOUS!!) ###
| |
| iptables -F
| |
| iptables -X
| |
| ### BLOC TOUS PAR DEFAULT (si aucune règle n'est définit par la suite) ###
| |
| iptables -P INPUT DROP
| |
| iptables -P OUTPUT DROP
| |
| iptables -P FORWARD DROP
| |
| ### Iptables refuse les scans XMAS et NULL
| |
| iptables -A INPUT -p tcp --tcp-flags FIN,URG,PSH FIN,URG,PSH -j DROP
| |
| iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
| |
| iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
| |
| iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
| |
| ### Iptables limite TCP, UDP, ICMP Flood !
| |
| ### Une des attaques possible est de saturer votre interface réseau.
| |
| # TCP Syn Flood
| |
| iptables -A INPUT -i $interface_WAN -p tcp --syn -m limit --limit 3/s -j ACCEPT
| |
| # UDP Syn Flood
| |
| iptables -A INPUT -i $interface_WAN -p udp -m limit --limit 10/s -j ACCEPT
| |
| # Ping Flood
| |
| iptables -A INPUT -i $interface_WAN -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
| |
| iptables -A INPUT -i $interface_WAN -p icmp --icmp-type echo-reply -m limit --limit 1/s -j ACCEPT
| |
|
| |
| # fichiers de conf a modifier
| |
| #pas de spoofing
| |
| # Fichier /etc/sysctl.conf
| |
| # net.ipv4.conf.default.rp_filter=1
| |
| # net.ipv4.conf.all.rp_filter=1
| |
| #pas de synflood
| |
| #Fichier /etc/sysctl
| |
| #net.ipv4.tcp_syncookies=1
| |
| #net.ipv4.tcp_max_syn_backlog=1280 # Ceci active la resistance au Flood SYN
| |
|
| |
|
| |
| ### IP indésirables
| |
| ## en gros elle sont sur le site du RIPE (organisme distribuent les IP ou plage IP au professionnel)
| |
| ## site du RIPE https://apps.db.ripe.net/search/full-text.html (ADOPI et trident media guard (tmg) sont de mot a rechercher ;)
| |
| if [ $ipblacklist -eq $on ]
| |
| while read ligne
| |
| do
| |
| ipdrop=`echo $ligne | cut -d " " -f1`
| |
| iptables -I INPUT -s $ipdrop -j DROP
| |
| iptables -I OUTPUT -d $ipdrop -j DROP
| |
| done < /usr/local/share/ipblacklist
| |
| fi
| |
| # les lignes du fichier ipblacklist doive ètre de type :
| |
| # xxx.xxx.xxx.xxx/xx <=espace commentaire sans le # au debut bien sur
| |
| # ou
| |
| # xxx.xxx.xxx.xxx/xxx.xxx.xxx.xxx <=espace commentaire en fonction de comment on écrit le masque réseau
| |
|
| |
| iptables -I INPUT -s 85.116.217.200/29 -j DROP # ADOPI
| |
| iptables -I INPUT -s 193.107.240.0/22 -j DROP # trident media guard (tmg)
| |
| iptables -I INPUT -s 195.191.244.0/23 -j DROP # trident media guard (tmg)
| |
| iptables -I INPUT -s 193.105.197.0/24 -j DROP # trident media guard (tmg)
| |
|
| |
| iptables -I OUTPUT -d 85.116.217.200/29 -j DROP # ADOPI
| |
| iptables -I OUTPUT -d 193.107.240.0/22 -j DROP # trident media guard (tmg)
| |
| iptables -I OUTPUT -d 195.191.244.0/23 -j DROP # trident media guard (tmg)
| |
| iptables -I OUTPUT -d 193.105.197.0/24 -j DROP # trident media guard (tmg)
| |
|
| |
| ### ACCEPT ALL interface loopbaak ###
| |
| iptables -A INPUT -i lo -j ACCEPT
| |
| iptables -A OUTPUT -o lo -j ACCEPT
| |
|
| |
| ### axepte en entrer les connexions déjà établies (en gros sa permet d'accepter que les connexions initier
| |
| ### par sont propre PC)
| |
| iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
| |
|
| |
| ### DNS indispensable pour naviguer facilement sur le web ###
| |
| iptables -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT
| |
|
| |
| ### HTTP navigation internet non sécuriséer ###
| |
| iptables -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPT
| |
|
| |
| ### HTTPS pour le site de banque .... ###
| |
| iptables -A OUTPUT -p tcp -m tcp --dport 443 -j ACCEPT
| |
|
| |
| ### emesene,pindgin,amsn... ####
| |
| if [ $amsn -eq $on ]
| |
| then
| |
| iptables -A OUTPUT -p tcp -m tcp --dport 1863 -j ACCEPT
| |
| iptables -A OUTPUT -p tcp -m tcp --dport 6891:6900 -j ACCEPT # pour transfert de fichiers , webcam
| |
| iptables -A OUTPUT -p udp -m udp --dport 6891:6900 -j ACCEPT # pour transfert de fichiers , webcam
| |
| fi
| |
| ### pop thunderbird ... réceptions des message ####
| |
| iptables -A OUTPUT -p tcp -m tcp --dport 110 -j ACCEPT
| |
|
| |
| ### smtp thunderbird ... envoi des messages ###
| |
| iptables -A OUTPUT -p tcp -m tcp --dport 25 -j ACCEPT
| |
|
| |
| ### clientNTP ... sincro a un serveur de temp ###
| |
| if [ $clientNTP -eq $on ]
| |
| then
| |
| iptables -A OUTPUT -p udp -m udp --dport 123 -j ACCEPT
| |
| fi
| |
| ### client-transmition
| |
| if [ $transmition -eq $on ]
| |
| then
| |
| iptables -A OUTPUT -p udp -m udp --sport 51413 -j ACCEPT
| |
| iptables -A OUTPUT -p tcp -m tcp --sport 30000:65000 -j ACCEPT
| |
| fi
| |
| ### ping ... autorise a pinger un ordinateur distant ###
| |
| iptables -A OUTPUT -p icmp -j ACCEPT
| |
|
| |
| ### LandesEternelles
| |
| if [ $LandesEternelles -eq $on ]
| |
| then
| |
| iptables -A OUTPUT -d 62.93.225.45 -p tcp --sport 39943 --dport 3000 -j ACCEPT
| |
| fi
| |
| ### SecondeLife
| |
| if [ $SecondeLife -eq $on ]
| |
| then
| |
| iptables -A OUTPUT -p tcp -m tcp --dport 53 -j ACCEPT
| |
| iptables -A INPUT -s 216.82.0.0/18 -p tcp --dport 1023:65000 -j ACCEPT # Secondelife
| |
| iptables -A INPUT -s 64.94.252.0/23 -p tcp --dport 1023:65000 -j ACCEPT # Voice
| |
| iptables -A INPUT -s 70.42.62.0/24 -p tcp --dport 1023:65000 -j ACCEPT # Voice
| |
| iptables -A INPUT -s 74.201.98.0/23 -p tcp --dport 1023:65000 -j ACCEPT # Voice
| |
|
| |
| iptables -A INPUT -s 216.82.0.0/18 -p udp --dport 1023:65000 -j ACCEPT # Secondelife
| |
| iptables -A INPUT -s 64.94.252.0/23 -p udp --dport 1023:65000 -j ACCEPT # Voice
| |
| iptables -A INPUT -s 70.42.62.0/24 -p udp --dport 1023:65000 -j ACCEPT # Voice
| |
| iptables -A INPUT -s 74.201.98.0/23 -p udp --dport 1023:65000 -j ACCEPT # Voice
| |
|
| |
| iptables -A OUTPUT -d 216.82.0.0/18 -p tcp --sport 1023:65000 -j ACCEPT # Secondelife
| |
| iptables -A OUTPUT -d 64.94.252.0/23 -p tcp --sport 1023:65000 -j ACCEPT # Voice
| |
| iptables -A OUTPUT -d 70.42.62.0/24 -p tcp --sport 1023:65000 -j ACCEPT # Voice
| |
| iptables -A OUTPUT -d 74.201.98.0/23 -p tcp --sport 1023:65000 -j ACCEPT # Voice
| |
|
| |
| iptables -A OUTPUT -d 216.82.0.0/18 -p udp --sport 1023:65000 -j ACCEPT # Secondelife
| |
| iptables -A OUTPUT -d 64.94.252.0/23 -p udp --sport 1023:65000 -j ACCEPT # Voice
| |
| iptables -A OUTPUT -d 70.42.62.0/24 -p udp --sport 1023:65000 -j ACCEPT # Voice
| |
| iptables -A OUTPUT -d 74.201.98.0/23 -p udp --sport 1023:65000 -j ACCEPT # Voice
| |
| fi
| |
|
| |
| ### ping ... autorise l'extèrieur a vous pinger ###
| |
| if [ $pingexterne -eq $on ]
| |
| iptables -A INPUT -p icmp -j ACCEPT # enlever le # du début de ligne pour activer cette règle
| |
| fi
| |
|
| |
| ### LOG ### Log tous ce qui qui n'est pas accepter par une règles précédente
| |
| # prés requit : sudo apt-get install sysklogd
| |
| # echo 'kern.warning /var/log/iptables.log' > /etc/syslog.conf
| |
| iptables -A OUTPUT -j LOG --log-level 4
| |
| iptables -A INPUT -j LOG --log-level 4
| |
| iptables -A FORWARD -j LOG --log-level 4
| |
| echo "############ <START> ##############"
| |
| iptables -L -n
| |
| echo "############ </START> ##############"
| |
| }
| |
| stop() {
| |
| ### OUVRE TOUS !! ###
| |
| iptables -F
| |
| iptables -X
| |
| iptables -P INPUT ACCEPT
| |
| iptables -P OUTPUT ACCEPT
| |
| iptables -P FORWARD ACCEPT
| |
| echo "############ <STOP> ##############"
| |
| iptables -L -n
| |
| echo "############ </STOP> ##############"
| |
| }
| |
|
| |
| case "$1" in
| |
| start)
| |
| start
| |
| ;;
| |
| stop)
| |
| stop
| |
| ;;
| |
| restart)
| |
| stop
| |
| start
| |
| ;;
| |
| *)
| |
| N=/etc/init.d/${0##*/}
| |
| echo "Usage: $N {start|stop|restart}" >&2
| |
| exit 1
| |
| ;;
| |
| esac
| |
|
| |
| exit 0
| |
| </code>
| |