L7-Filter Installation (partie 1)
J’avais fait un précédent billet sur l7-filter mais il n’est plus à jour. J’ai donc décidé d’en refaire un nouveau pour debian Etch noyau 2.6.18 avec iptables-1.3.5
L7-Filter o_O ?
C’est un module pour netfilter servant à filtrer le trafic par applicatif. L’utilisation se fait à l’aide d’expression régulière (pattern) servant de prise d’empreinte pour les protocoles.
Dans un premier temps installons les outils nécessaires à la compilation de noyau.
apt-get install build-essential fakeroot kernel-package
Puis installons les sources du noyau.
apt-get install linux-source-2.6.18
Maintenant que les sources sont téléchargé dans /usr/src il faut les extraire.
cd /usr/src & tar xvjf linux-source-2.6.18.tar.bz2
Créons un lien symbolique vers les sources.
ln -s linux-source-2.6.18 linux
Il faut maintenant télécharger l7-filter
wget http://switch.dl.sourceforge.net/sourceforge/l7-filter/netfilter-layer7-v2.17.tar.gz
tar xvzf netfilter-layer7-v2.17.tar.gz
Afin de profiter des fonctionnalités de l7filter il faut patcher le noyau.
cp netfilter-layer7-v2.17/for_older_kernels/kernel-2.6.18-2.6.19-layer7-2.9.patch linux
cd linux
Procédons au patch.
patch -p1 < kernel-2.6.18-2.6.19-layer7-2.9.patch
cd ..
Il faut ensuite préparer iptables à recevoir l7-filter. Pour ce faire téléchargeons les sources afin de les patcher.
Copions le patch
cp netfilter-layer7-v2.17/iptables-1.3-for-kernel-pre2.6.20-layer7-2.17.patch iptables-1.3.5-20061006/
cd iptables-1.3.5-20061006
patch -p1 < iptables-1.3-for-kernel-pre2.6.20-layer7-2.17.patch
Ensuite il faut installer iptables patché dans les sources du noyau.
chmod +x extensions/.layer7-test
make KERNEL_DIR=/usr/src/linux
make install KERNEL_DIR=/usr/src/linux
cd..
Enfin il nous reste à activer les modules afin de compiler le noyau.
cd linux
make menuconfig
Comme l’indique la doc, il faut activer les modules suivants :
* EXPERIMENTAL (Code maturity level options & Prompt for development and/or incomplete code/drivers)
* Netfilter (Device Drivers &Networking support & Networking Options & Network packet filtering)
* Connection tracking (Network packet filtering & IP: Netfilter Configuration & Connection tracking)
* “Connection tracking flow accounting” and “IP tables support” (on the same screen)
* And finally, “Layer 7 match support”
* Optional: Lots of other Netfilter options, ntably “FTP support” and other matches. If you don’t know what you’re doing, go ahead and enable all of them.
Il faut ensuite compiler les sources du noyau et créez les packages .deb.
make-kpkg
fakeroot make-kpkg –append-to-version=.666666 –initrd kernel_image
Et c’est parti pour une longue compilation.
Une fois ceci fait nous avons les packages dans /usr/src
linux-doc-2.6.18.181004_2.6.18.181004-10.00.Custom_all.deb
linux-image-2.6.18.181004_2.6.18.181004-10.00.Custom_i386.deb
linux-manual-2.6.18.181004_2.6.18.181004-10.00.Custom_all.deb
linux-source-2.6.18.181004_2.6.18.181004-10.00.Custom_all.deb
Installons-les.
dpkg -i *.deb
Un reboot est nécessaire. N’oubliez pas de vérifier dans votre /boot/grub/menu.lst que le noyau est disponible
Une fois rebooté regardons les commandes disponibles pour l7filter
iptables -m layer7 –help
iptables v1.3.8-20071014
LAYER7 match v1.3.8-20071014 options:
–l7dir <directory> : Look for patterns here instead of /etc/l7-protocols/
(–l7dir must be specified before –l7proto if used!)
–l7proto [!] <name> : Match the protocol defined in /etc/l7-protocols/name.pat
Il est donc possible de modifier le path de recherche des patterns via –l7dir
Ainsi que spécifier un protocole via – -l7proto
Justement jetons un coup d’œil a ces fameux patterns.
Il faut les télécharger et les installer.
wget http://surfnet.dl.sourceforge.net/sourceforge/l7-filter/l7-protocols-2008-02-20.tar.gz
tar xzf l7-protocols-2008-02-20.tar.gz
cd l7-protocols-2008-02-20
make install
cd /etc/l7-protocols/protocols/
Prenons par exemple le protocole http.
Voici le pattern http qui match ce protocole.
http/(0\.9|1\.0|1\.1) [1-5][0-9][0-9] [\x09-\x0d -~]*(connection:|content-type:|content-length:|date:)|post [\x09-\x0d -~]* http/[01]\.[019]
On voit qu’en fait l7-filter match sur les entêtes http. Ce qui nous indique bien qu’il s’agisse du protocole http
Cependant selon la documentation :
- l7-filter matching isn’t foolproof: there may be both false positives (one protocol can look like another) and false negatives (applications can do obscure things that we didn’t count on). Patterns that are known to regularly generate false positives are marked « overmatching » on the protocols page, but others may also do so occasionally.
- Almost every type of Internet traffic has legitimate uses. For instance, P2P protocols, while widely used to violate copyright, are also an efficient way to distribute open source software and legally free music.
- Programs can respond to being blocked by port-hopping, switching between TCP and UDP, opening a new connection for every trivial operation, using encryption, or employing other evasion tactics. Trying to block such protocols has consequences on two levels:
- In the case of port/protocol-hopping, you make it harder for yourself to identify protocols that already act this way.
- You encourage programmers to include these « features » in new programs, making it harder for everyone in the future. For example: In early 2006, Bittorrent started moving towards end-to-end encryption because many networks were either blocking it or severely restricting its bandwidth.
- l7-filter patterns are not generally designed with blocking in mind. We consider a protocol to be well identified if the identification is useful for controlling its bandwidth. This means, for instance, that for P2P applications, we do not focus on catching connections that are not downloads.
- Blocking with l7-filter provides no security, since any reasonably determined person can easily circumvent it.
Considérant ceci il semblerait que l7-filter soit plus utiliser dans le cadre de restriction de bande passante.
Dans un prochaine article nous verrons le traffic control sous linux avec l7filter.

The L7-Filter Installation (partie 1) by Steal This Blog, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Share Alike 2.0 France License.
