IPFilter
De Diablotins.org.
| Firewall IPFilter
|
| ||
FreeBSD dispose de plusieurs démons qui permettent de transformer votre FreeBSD en pare-feux appelés aussi passerelle filtrante ou «firewalls».
IPFilter est l'un des filtres de paquet les plus robustes et les plus sûrs. IPFILTER vous permet de contrôler toutes les entrées et sorties de chaque interface réseau. |
Sommaire |
pré-requis
Ici, on va considérer des cartes réseau 3COM 3c905 Boomerang.
On leur allouera les ip 192.168.1.5 et 192.168.1.6 sur l'interface xl0 et xl1 ou xl1 est considéré comme interface externe en SNAT sur le routeur externe. (nomenclature BSD).
Compilation du noyau
Il faut ajouter les lignes suivantes dans le fichier de conf de votre noyau.
options PFIL_HOOKS options IPFILTER options IPFILTER_LOG options IPFILTER_DEFAULT_BLOCK options RANDOM_IP_ID
Une ligne utile pour le sécurité, qui génère des id de paquets IP de façon aléatoire :
options RANDOM_IP_ID
Détail des paramètres :
- "options PFIL_HOOKS": Sans ce paramètre, vous aurez une erreur de compilation du noyau
- "options IPFILTER": on veux utiliser IPFILTER dans le noyau
- "options IPFILTER_LOG": permet d'enregister dans un journal les paquet reçus et/ou envoyés
- "options IPFILTER_DEFAULT_BLOCK": par défaut: on bloque les communications
- "options RANDOM_IP_ID": permet de generer des identifiants de paquets aléatoires
On compile le noyau (vérifiez que vos sources sont à jour :) )
# make buildkernel KERNCONF=/usr/src/sys/i386/conf/MONKERN # make installkernel KERNCONF=/usr/src/sys/i386/conf/MONKERN
Configuration de la distribution
On ajoute dans le fichier de configuration:
# vi /etc/rc.conf -- ipfilter_enable="YES" ipfilter_flags="" ipfilter_program="/sbin/ipf" ipfilter_rules="/etc/ipf.rules" # monitoring ipmon_enable="YES" # le journal ipmon_flags="-Dsvn" #ipnat_enable="YES" # pas utiles, pour info
Configuration
La configuration se fait dans le fichier “/etc/ipf.rules”;
ici on considère:
vi /etc/ipf.rules -- # on passe tout sur la boucle local pass in quick on lo0 all pass out quick on lo0 all # on passe tout le trafic sur la patte interne pass in quick on xl0 all # on passe tout le trafic sortant pass out quick proto tcp all keep state pass out quick proto udp all keep state # on bloque tout les paquets IP avec ipopts y compris lsrr et ssrr block in quick all with ipopts # on bloque les paquets fragmentés block in quick all with frag # on bloque les tentative de nmpa OS fingerprint block in quick on xl1 proto tcp all flags FUP block in log quick on xl1 proto tcp from any to any flags SF/SFRA block in log quick on xl1 proto tcp from any to any flags /SFRA # nmap outing sur interface externe et log block in log quick on xl1 proto tcp all flags SF/SFRA block in log quick on xl1proto tcp all flags /SFRA block in log quick on xl1 proto tcp all flags F/SFRA block in log quick on xl1 proto tcp all flags U/SFRAU block in log quick on xl1 proto tcp all flags P block in log quick on xl1 proto tcp from any to any flags FUP block in log quick on xl1 proto tcp from any to any port = 111 # réseau non routable sur l'interface externe block in quick on xl1 from 255.255.255.255/32 to any # block in quick on xl1 from 192.168.0.0/16 to any block in quick on xl1 from 172.16.0.0/12 to any block in quick on xl1 from 127.0.0.0/8 to any block in quick on xl1 from 10.0.0.0/8 to any block in quick on xl1 from 0.0.0.0/32 to any # bloque les ICMP externe block in quick on xl1 proto icmp from any to any icmp-type 0 keep state block in quick on xl1 proto icmp from any to any icmp-type 3 keep state block in quick on xl1 proto icmp from any to any icmp-type 8 keep state block in quick on xl1 proto icmp from any to any icmp-type 11 keep state pass in quick on xl0 proto icmp from any to any icmp-type 0 keep state pass in quick on xl0 proto icmp from any to any icmp-type 3 keep state pass in quick on xl0 proto icmp from any to any icmp-type 8 keep state pass in quick on xl0 proto icmp from any to any icmp-type 11 keep state pass out quick on xl0 proto icmp from any to any icmp-type 0 keep state pass out quick on xl0 proto icmp from any to any icmp-type 3 keep state pass out quick on xl0 proto icmp from any to any icmp-type 8 keep state pass out quick on xl0 proto icmp from any to any icmp-type 11 keep state # blacklist block in quick on xl1 from 216.133.253.100 to any block out quick on xl1 from any to 216.133.253.100 # on passe les services pass in quick on xl1 proto tcp from any to any port = 22 keep state pass in quick on xl1 proto tcp from any to any port = 25 keep state pass in quick on xl1 proto tcp from any to any port = 21 keep state pass in quick on xl1 proto tcp from any to any port = 443 keep state pass in quick on xl1 proto tcp from any to any port = 80 keep state # on bloque le reste block in quick on xl1
Piloter
Lancer le firewall :
# ipf -Fa -f /etc/ipf.rules
Surveiller le firewall :
# ipfstat -hio
Relancer le firewall :
# /sbin/ipf -Fa -f /etc/ipf.rules
Statitique comme 'top' :
# /sbin/ipfstat -t
Version d'IPFilter :
# /sbin/ipf -V

