Improve descriptions / comments (switch all in english, etc.)

This commit is contained in:
Gregory Colpart 2015-09-13 18:37:53 +02:00
parent 9579cfe991
commit 2f561a6172
2 changed files with 75 additions and 72 deletions

11
README Normal file
View file

@ -0,0 +1,11 @@
minifirewall is shellscripts for easy firewalling on a standalone server
we used netfilter/iptables http://netfilter.org/ designed for recent Linux kernel
See https://forge.evolix.org/projects/minifirewall
Usage :
-------
* download minifirewall and minifirewall.conf
* copy minifirewall.conf in /etc (for Debian, use /etc/default/minifirewall)
and configure it
* start / stop with : minifirewall start / minifirewall stop

View file

@ -1,24 +1,19 @@
#!/bin/sh #!/bin/sh
# minifirewall is shellscripts for easy firewalling on a standalone server # minifirewall is shellscripts for easy firewalling on a standalone server
# See http://git.evolix.org/?p=evolinux/minifirewall.git;a=summary # we used netfilter/iptables http://netfilter.org/ designed for recent Linux kernel
# See https://forge.evolix.org/projects/minifirewall
# Copyright (c) 2007-2011 Evolix # Copyright (c) 2007-2015 Evolix
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License. # of the License.
# Script netfilter/iptables
# http://netfilter.org/
#
# Designed for Linux kernel 2.6
# http://www.kernel.org/
# Description # Description
# script for local server # script for standalone server
# Start or stop a mini-firewall # Start or stop minifirewall
# #
### BEGIN INIT INFO ### BEGIN INIT INFO
@ -30,22 +25,21 @@
# Default-Start: 2 3 4 5 # Default-Start: 2 3 4 5
# Default-Stop: 0 1 6 # Default-Stop: 0 1 6
# Short-Description: start and stop the firewall # Short-Description: start and stop the firewall
# Description: Firewall designed by evolix.fr # Description: Firewall designed for standalone server
### END INIT INFO ### END INIT INFO
DESC="minifirewall" DESC="minifirewall"
NAME="minifirewall" NAME="minifirewall"
### # Variables configuration
# Configuration des variables #########################
###
# chemin iptables # iptables paths
IPT=/sbin/iptables IPT=/sbin/iptables
IPT6=/sbin/ip6tables IPT6=/sbin/ip6tables
# variables TCP/IP # TCP/IP variables
LOOPBACK='127.0.0.0/8' LOOPBACK='127.0.0.0/8'
CLASSA='10.0.0.0/8' CLASSA='10.0.0.0/8'
CLASSB='172.16.0.0/12' CLASSB='172.16.0.0/12'
@ -61,31 +55,32 @@ PORTSUSER='1024:65535'
case "$1" in case "$1" in
start) start)
echo "Demarrage regles IPTables..." echo "Start IPTables rules..."
# Stop and warn if error! # Stop and warn if error!
set -e set -e
trap 'echo "ERROR in minifirewall configuration (fix it now!) or script manipulation (fix yourself)." ' INT TERM EXIT trap 'echo "ERROR in minifirewall configuration (fix it now!) or script manipulation (fix yourself)." ' INT TERM EXIT
# 1.Protections diverses
# ne pas repondre aux ping broadcast # sysctl network security settings
##################################
# Don't answer to broadcast pings
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# Ignorer les mauvais messages d'erreurs ICMP # Ignore bogus ICMP responses
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
# effacer la source des paquets routes # Disable Source Routing
for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do
echo 0 > $i echo 0 > $i
done done
# activer les TCP SYN cookies evitant des attaques DoS de type TCP-SYN-FLOOD # Enable TCP SYN cookies to avoid TCP-SYN-FLOOD attacks
# cf http://cr.yp.to/syncookies.html # cf http://cr.yp.to/syncookies.html
echo 1 > /proc/sys/net/ipv4/tcp_syncookies echo 1 > /proc/sys/net/ipv4/tcp_syncookies
# desactiver les messages ICMP d'information de redirection # Disable ICMP redirects
# potentiellement dangereux
for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do
echo 0 > $i echo 0 > $i
done done
@ -94,7 +89,7 @@ for i in /proc/sys/net/ipv4/conf/*/send_redirects; do
echo 0 > $i echo 0 > $i
done done
# filtrage par chemin inverse: verifie que les reponses sortent bien de l'interface d'arrivee # Enable Reverse Path filtering : verify if responses use same network interface
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo 1 > $i echo 1 > $i
done done
@ -104,7 +99,8 @@ for i in /proc/sys/net/ipv4/conf/*/log_martians; do
echo 1 > $i echo 1 > $i
done done
# 2. Sur la machine # IPTables configuration
########################
$IPT -N LOG_DROP $IPT -N LOG_DROP
$IPT -A LOG_DROP -j LOG --log-prefix '[IPTABLES DROP] : ' $IPT -A LOG_DROP -j LOG --log-prefix '[IPTABLES DROP] : '
@ -136,7 +132,7 @@ if [ -s $tmpfile ]; then
fi fi
rm $tmpfile rm $tmpfile
# trusted ip addresses # Trusted ip addresses
$IPT -N ONLYTRUSTED $IPT -N ONLYTRUSTED
$IPT -A ONLYTRUSTED -j LOG_DROP $IPT -A ONLYTRUSTED -j LOG_DROP
for x in $TRUSTEDIPS for x in $TRUSTEDIPS
@ -144,7 +140,7 @@ for x in $TRUSTEDIPS
$IPT -I ONLYTRUSTED -s $x -j ACCEPT $IPT -I ONLYTRUSTED -s $x -j ACCEPT
done done
# privilegied ip addresses # Privilegied ip addresses
# (trusted ip addresses *are* privilegied) # (trusted ip addresses *are* privilegied)
$IPT -N ONLYPRIVILEGIED $IPT -N ONLYPRIVILEGIED
$IPT -A ONLYPRIVILEGIED -j ONLYTRUSTED $IPT -A ONLYPRIVILEGIED -j ONLYTRUSTED
@ -153,31 +149,29 @@ for x in $PRIVILEGIEDIPS
$IPT -I ONLYPRIVILEGIED -s $x -j ACCEPT $IPT -I ONLYPRIVILEGIED -s $x -j ACCEPT
done done
# chain for restrictions (blacklist ips/ranges) # Chain for restrictions (blacklist IPs/ranges)
$IPT -N NEEDRESTRICT $IPT -N NEEDRESTRICT
# On autorise tout sur l'interface loopback # We allow all on loopback interface
$IPT -A INPUT -i lo -j ACCEPT $IPT -A INPUT -i lo -j ACCEPT
[ $IPV6 != 'off' ] && $IPT6 -A INPUT -i lo -j ACCEPT [ $IPV6 != 'off' ] && $IPT6 -A INPUT -i lo -j ACCEPT
# if OUTPUTDROP # if OUTPUTDROP
$IPT -A OUTPUT -o lo -j ACCEPT $IPT -A OUTPUT -o lo -j ACCEPT
[ $IPV6 != 'off' ] && $IPT6 -A OUTPUT -o lo -j ACCEPT [ $IPV6 != 'off' ] && $IPT6 -A OUTPUT -o lo -j ACCEPT
# on evite pas mal de paquets "martiens" effet de bord de virus # We avoid "martians" packets, typical when W32/Blaster virus
# notamment W32/Blaster qui attaquait windowsupdate.com # attacked windowsupdate.com and DNS was changed to 127.0.0.1
# et dont l'enregistrement DNS avait ete change pour 127.0.0.1
# $IPT -t NAT -I PREROUTING -s $LOOPBACK -i ! lo -j DROP # $IPT -t NAT -I PREROUTING -s $LOOPBACK -i ! lo -j DROP
$IPT -A INPUT -s $LOOPBACK ! -i lo -j DROP $IPT -A INPUT -s $LOOPBACK ! -i lo -j DROP
#################################################################
# Les services accessibles
#################################################################
# Les services accessibles en local ? # Local services restrictions
#$IPT -A INPUT -i $INT2 -j ACCEPT #############################
# Allow services for $INTLAN (local server or local network)
$IPT -A INPUT -s $INTLAN -j ACCEPT $IPT -A INPUT -s $INTLAN -j ACCEPT
# On passe tout d'abord par la chaine de protection pour certains services # Enable protection chain for sensible services
for x in $SERVICESTCP1p for x in $SERVICESTCP1p
do do
$IPT -A INPUT -p tcp --dport $x -j NEEDRESTRICT $IPT -A INPUT -p tcp --dport $x -j NEEDRESTRICT
@ -188,7 +182,7 @@ for x in $SERVICESUDP1p
$IPT -A INPUT -p udp --dport $x -j NEEDRESTRICT $IPT -A INPUT -p udp --dport $x -j NEEDRESTRICT
done done
# Services publics # Public service
for x in $SERVICESTCP1 for x in $SERVICESTCP1
do do
$IPT -A INPUT -p tcp --dport $x -j ACCEPT $IPT -A INPUT -p tcp --dport $x -j ACCEPT
@ -201,7 +195,7 @@ for x in $SERVICESUDP1
[ $IPV6 != 'off' ] && $IPT6 -A INPUT -p udp --dport $x -j ACCEPT [ $IPV6 != 'off' ] && $IPT6 -A INPUT -p udp --dport $x -j ACCEPT
done done
# Services semi-publics # Privilegied services
for x in $SERVICESTCP2 for x in $SERVICESTCP2
do do
$IPT -A INPUT -p tcp --dport $x -j ONLYPRIVILEGIED $IPT -A INPUT -p tcp --dport $x -j ONLYPRIVILEGIED
@ -212,7 +206,7 @@ for x in $SERVICESUDP2
$IPT -A INPUT -p udp --dport $x -j ONLYPRIVILEGIED $IPT -A INPUT -p udp --dport $x -j ONLYPRIVILEGIED
done done
# Services prives # Private services
for x in $SERVICESTCP3 for x in $SERVICESTCP3
do do
$IPT -A INPUT -p tcp --dport $x -j ONLYTRUSTED $IPT -A INPUT -p tcp --dport $x -j ONLYTRUSTED
@ -223,12 +217,11 @@ for x in $SERVICESUDP3
$IPT -A INPUT -p udp --dport $x -j ONLYTRUSTED $IPT -A INPUT -p udp --dport $x -j ONLYTRUSTED
done done
#################################################################
# Les services auxquels la machine peut acceder
#################################################################
# DNS # External services
# autoriser a recevoir des reponses DNS ###################
# DNS authorizations
for x in $DNSSERVEURS for x in $DNSSERVEURS
do do
$IPT -A INPUT -p tcp ! --syn --sport 53 --dport $PORTSUSER -s $x -j ACCEPT $IPT -A INPUT -p tcp ! --syn --sport 53 --dport $PORTSUSER -s $x -j ACCEPT
@ -236,75 +229,74 @@ for x in $DNSSERVEURS
$IPT -A OUTPUT -o $INT -p udp -d $x --dport 53 --match state --state NEW -j ACCEPT $IPT -A OUTPUT -o $INT -p udp -d $x --dport 53 --match state --state NEW -j ACCEPT
done done
# HTTP # HTTP (TCP/80) authorizations
# autoriser a se connecter a certaines IP en http (miroirs debian par exemple)
for x in $HTTPSITES for x in $HTTPSITES
do do
$IPT -A INPUT -p tcp ! --syn --sport 80 --dport $PORTSUSER -s $x -j ACCEPT $IPT -A INPUT -p tcp ! --syn --sport 80 --dport $PORTSUSER -s $x -j ACCEPT
done done
# HTTPS # HTTPS (TCP/443) authorizations
for x in $HTTPSSITES for x in $HTTPSSITES
do do
$IPT -A INPUT -p tcp ! --syn --sport 443 --dport $PORTSUSER -s $x -j ACCEPT $IPT -A INPUT -p tcp ! --syn --sport 443 --dport $PORTSUSER -s $x -j ACCEPT
done done
# FTP # FTP (so complex protocol...) authorizations
# autoriser a se connecter a certaines IP en ftp (miroirs debian par exemple)
for x in $FTPSITES for x in $FTPSITES
do do
# requetes exterieures sur le canal de controle # requests on Control connection
$IPT -A INPUT -p tcp ! --syn --sport 21 --dport $PORTSUSER -s $x -j ACCEPT $IPT -A INPUT -p tcp ! --syn --sport 21 --dport $PORTSUSER -s $x -j ACCEPT
# FTP port-mode sur le canal de donnees # FTP port-mode on Data Connection
$IPT -A INPUT -p tcp --sport 20 --dport $PORTSUSER -s $x -j ACCEPT $IPT -A INPUT -p tcp --sport 20 --dport $PORTSUSER -s $x -j ACCEPT
# FTP passive-mode sur le canal de donnees # FTP passive-mode on Data Connection
# ATTENTION, cela active aussi les connexions sur tous les ports TCP > 1024 pour cette machine # WARNING, this allow all connections on TCP ports > 1024
$IPT -A INPUT -p tcp ! --syn --sport $PORTSUSER --dport $PORTSUSER -s $x -j ACCEPT $IPT -A INPUT -p tcp ! --syn --sport $PORTSUSER --dport $PORTSUSER -s $x -j ACCEPT
done done
# autoriser a se connecter sur certaines IP par SSH # SSH authorizations
for x in $SSHOK for x in $SSHOK
do do
$IPT -A INPUT -p tcp ! --syn --sport 22 -s $x -j ACCEPT $IPT -A INPUT -p tcp ! --syn --sport 22 -s $x -j ACCEPT
done done
# SMTP # SMTP authorizations
for x in $SMTPOK for x in $SMTPOK
do do
$IPT -A INPUT -p tcp ! --syn --sport 25 --dport $PORTSUSER -j ACCEPT $IPT -A INPUT -p tcp ! --syn --sport 25 --dport $PORTSUSER -j ACCEPT
done done
# SMTP secure # secure SMTP (TCP/465 et TCP/587) authorizations
for x in $SMTPSECUREOK for x in $SMTPSECUREOK
do do
$IPT -A INPUT -p tcp ! --syn --sport 465 --dport $PORTSUSER -j ACCEPT $IPT -A INPUT -p tcp ! --syn --sport 465 --dport $PORTSUSER -j ACCEPT
$IPT -A INPUT -p tcp ! --syn --sport 587 --dport $PORTSUSER -j ACCEPT $IPT -A INPUT -p tcp ! --syn --sport 587 --dport $PORTSUSER -j ACCEPT
done done
# NTP # NTP authorizations
# autoriser synchronisation ntpdate
for x in $NTPOK for x in $NTPOK
do do
$IPT -A INPUT -p udp --sport 123 -s $x -j ACCEPT $IPT -A INPUT -p udp --sport 123 -s $x -j ACCEPT
$IPT -A OUTPUT -o $INT -p udp -d $x --dport 123 --match state --state NEW -j ACCEPT $IPT -A OUTPUT -o $INT -p udp -d $x --dport 123 --match state --state NEW -j ACCEPT
done done
# ICMP # Always allow ICMP
$IPT -A INPUT -p icmp -j ACCEPT $IPT -A INPUT -p icmp -j ACCEPT
[ $IPV6 != 'off' ] && $IPT6 -A INPUT -p icmpv6 -j ACCEPT [ $IPV6 != 'off' ] && $IPT6 -A INPUT -p icmpv6 -j ACCEPT
# politique
# par defaut rien ne rentre # IPTables policy
#################
# by default DROP INPUT packets
$IPT -P INPUT DROP $IPT -P INPUT DROP
[ $IPV6 != 'off' ] && $IPT6 -P INPUT DROP [ $IPV6 != 'off' ] && $IPT6 -P INPUT DROP
# par defaut rien ne transite (obsolete, notamment pour les VM) # by default, no FORWARING (deprecated for Virtual Machines)
#echo 0 > /proc/sys/net/ipv4/ip_forward #echo 0 > /proc/sys/net/ipv4/ip_forward
#$IPT -P FORWARD DROP #$IPT -P FORWARD DROP
#$IPT6 -P FORWARD DROP #$IPT6 -P FORWARD DROP
# par defaut tout peut sortir sauf l'UDP (sinon voir OUTPUTDROP) # by default allow OUTPUT packets... but drop UDP packets (see OUTPUTDROP to drop OUTPUT packets)
$IPT -P OUTPUT ACCEPT $IPT -P OUTPUT ACCEPT
[ $IPV6 != 'off' ] && $IPT6 -P OUTPUT ACCEPT [ $IPV6 != 'off' ] && $IPT6 -P OUTPUT ACCEPT
$IPT -A OUTPUT -o $INT -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT $IPT -A OUTPUT -o $INT -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
@ -316,14 +308,14 @@ $IPT -A OUTPUT -p udp -j DROP
trap - INT TERM EXIT trap - INT TERM EXIT
echo "Fin du chargement des regles... " echo "...loading IPTables rules is now finish."
;; ;;
stop) stop)
echo "On vide toutes les regles et on accepte tout..." echo "We flush all rules and we accept everything..."
# On supprime toutes les regles # Delete all rules
$IPT -F INPUT $IPT -F INPUT
$IPT -F OUTPUT $IPT -F OUTPUT
$IPT -F LOG_DROP $IPT -F LOG_DROP
@ -336,7 +328,7 @@ trap - INT TERM EXIT
$IPT6 -F INPUT $IPT6 -F INPUT
$IPT6 -F OUTPUT $IPT6 -F OUTPUT
# On accepte tout # Accept all
$IPT -P INPUT ACCEPT $IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT $IPT -P OUTPUT ACCEPT
$IPT6 -P INPUT ACCEPT $IPT6 -P INPUT ACCEPT
@ -345,7 +337,7 @@ trap - INT TERM EXIT
#$IPT -t nat -P PREROUTING ACCEPT #$IPT -t nat -P PREROUTING ACCEPT
#$IPT -t nat -P POSTROUTING ACCEPT #$IPT -t nat -P POSTROUTING ACCEPT
# On supprime les tables creees # Delete non-standard chains
$IPT -X LOG_DROP $IPT -X LOG_DROP
$IPT -X LOG_ACCEPT $IPT -X LOG_ACCEPT
$IPT -X ONLYPRIVILEGIED $IPT -X ONLYPRIVILEGIED
@ -366,7 +358,7 @@ trap - INT TERM EXIT
reset) reset)
echo "On remet les compteurs a zero..." echo "Reset all IPTables counters..."
$IPT -Z $IPT -Z
$IPT -t nat -Z $IPT -t nat -Z