SYN, SYN-ACK, ACK …

Steal This Blog

Archives Posts

Mirroring de traffic via iptables [Debian Etch]

juin 5th, 2008 by Corbier

This option adds a `ROUTE’ target, which enables you to setup unusual

routes. For example, the ROUTE lets you route a received packet through

an interface or towards a host, even if the regular destination of the

packet is the router itself. The ROUTE target is also able to change the

incoming interface of a packet.

To copy (duplicate) all traffic from and to a local ECHO server to a second box (nonfinal target)

iptables -A PREROUTING -t mangle -p tcp –dport 7 -j ROUTE –gw 1.2.3.4 –tee

iptables -A POSTROUTING -t mangle -p tcp –sport 7 -j ROUTE –gw 1.2.3.4 –tee

Afin d’activer la cible route pour iptables il est nécéssaire de recompiler l’ensemble « noyau + iptables »

Nous allons donc préparer notre environnement de travail.

apt-get install linux-source-2.6.18 gcc make ncurses-dev
cd /usr/src
tar -xvjf linux-source-2.6.18.tar.bz2
ln -s linux-source-2.6.18 linux

On télécharge les sources d’iptables et on les décompresses

wget http://www.netfilter.org/projects/iptables/files/iptables-1.3.6.tar.bz2

tar -xjpf iptables-1.3.6.tar.bz2

On peut maintenant télécharger le patch-o-matic :

wget http://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/patch-o-matic-ng-20070728.tar.bz2

tar xvjf patch-o-matic-ng-20070728.tar.bz2

cd patch-o-matic-ng-20070728

Nous devons spécifié le dossier des sources d’iptables

IPTABLES_DIR=/usr/src/iptables-1.3.6 ./runme ROUTE

Hey! KERNEL_DIR is not set.

Where is your kernel source directory? [/usr/src/linux]

Loading patchlet definitions…………….. done

Welcome to Patch-o-matic ($Revision: 6736 $)!

Kernel: 2.6.18, /usr/src/linux

Iptables: 1.3.6, /usr/src/iptables-1.3.6

Each patch is a new feature: many have minimal impact, some do not.

Almost every one has bugs, so don’t apply what you don’t need!

——————————————————-

Already applied:

Testing ROUTE… not applied

The ROUTE patch:

Author: Cédric de Launois <delaunois@info.ucl.ac.be>

Status: Experimental

This option adds a `ROUTE’ target, which enables you to setup unusual

routes. For example, the ROUTE lets you route a received packet through

an interface or towards a host, even if the regular destination of the

packet is the router itself. The ROUTE target is also able to change the

incoming interface of a packet.

The target can be or not a final target. It has to be used inside the

mangle table.

ROUTE target options:

–oif ifname Send the packet out using `ifname’ network interface.

–iif ifname Change the packet’s incoming interface to `ifname’.

–gw ip Route the packet via this gateway.

–continue Route the packet and continue traversing the rules.

–tee Route a copy of the packet, but continue traversing

the rules with the original packet, undisturbed.

Note that –iif, –continue, and –tee, are mutually exclusive.

Examples :

# To force all outgoing icmp packet to go through the eth1 interface

# (final target) :

iptables -A POSTROUTING -t mangle -p icmp -j ROUTE –oif eth1

# To tunnel outgoing http packets and continue traversing the rules :

iptables -A POSTROUTING -t mangle -p tcp –dport 80 -j ROUTE –oif tunl1 –continue

# To forward all ssh packets to gateway w.x.y.z, and continue traversing

# the rules :

iptables -A POSTROUTING -t mangle -p tcp –dport 22 -j ROUTE –gw w.x.y.z –continue

# To change the incoming network interface from eth0 to eth1 for all icmp

# packets (final target) :

iptables -A PREROUTING -t mangle -p icmp -i eth0 -j ROUTE –iif eth1

# To copy (duplicate) all traffic from and to a local ECHO server

# to a second box (nonfinal target)

iptables -A PREROUTING -t mangle -p tcp –dport 7 -j ROUTE –gw 1.2.3.4 –tee

iptables -A POSTROUTING -t mangle -p tcp –sport 7 -j ROUTE –gw 1.2.3.4 –tee

—————————————————————–

Do you want to apply this patch [N/y/t/f/a/r/b/w/q/?] y

Excellent! Source trees are ready for compilation.

Nous pouvons maintenant compiler le noyau

cd /usr/src/linux

make oldconfig

Quelques librairies sont rapidement indispensable ;o)

apt-get install kernel-package

Et c’est partie pour de la compilation

make-kpkg clean

make-kpkg –initrd kernel_image kernel_headers

make-kpkg –initrd kernel_image

Une fois la compilation effectué il faut installer et booter sur le noyau.

dpkg –i monnoyau.deb

Vérifiez votre /boot/grub/menu.lst afin de voir si votre nouveau noyau apparait.

Ensuite Reboot

Pour monitorer tout le trafic entrant vers une ip (Un IDS par exemple J) utiliser la règle iptables suivante :

iptables -A POSTROUTING -t mangle -p tcp –sport 7 -j ROUTE –gw 1.2.3.4 –tee

Nous verrons dans un prochain billet comment utiliser ce trafic avec un IDS.

Archives Posts

L7-Filter Installation (partie 1)

avril 11th, 2008 by Corbier

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.

wget http://ftp.netfilter.org/pub/iptables/snapshot/iptables-1.3.5-20061006.tar.bz2 & tar xvjf iptables-1.3.5-20061006.tar.bz2

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:
    1. In the case of port/protocol-hopping, you make it harder for yourself to identify protocols that already act this way.
    2. 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.

Archives Posts

ByPass Hotspot Neuf (Chillspot)

décembre 29th, 2007 by Corbier

Avec l’arrivée et la multiplication des hotspots, il devient néccéssaire d’avoir un compte sur les hotspots ou pas…

Afin de ByPass l’accès réseau. Qui se base sur votre compte en banque. Nous avons cherché un moyen de « sortir » du hotspot.

Sachant que le protocole dns étant le seul protocole autorisé a sortir. Nous avons donc constater que le tunneling serait je pense la meilleur solution.

Pour réussir, Il vous faut.

Un serveur VPN, et un laptop evidement.

Nous avons choisi openvpn en mode static key afin de géré cette connection.

Voici la configuration ip du server vpn

br0 Link encap:Ethernet HWaddr 00:18:39:AE:73:A7
inet addr:192.168.30.254 Bcast:192.168.30.255 Mask:255.255.255.0
UP BROADCAST RUNNING PROMISC ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:231701 errors:0 dropped:0 overruns:0 frame:0
TX packets:142476 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13696143 (13.0 MiB) TX bytes:92534590 (88.2 MiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MULTICAST MTU:16436 Metric:1
RX packets:1300 errors:0 dropped:0 overruns:0 frame:0
TX packets:1300 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:139429 (136.1 KiB) TX bytes:139429 (136.1 KiB)

tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.10.10.10 P-t-P:10.10.10.11 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:542 errors:0 dropped:0 overruns:0 frame:0
TX packets:368 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:38381 (37.4 KiB) TX bytes:239530 (233.9 KiB)

vlan1 Link encap:Ethernet HWaddr 00:18:39:AE:73:A8
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING PROMISC ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:75864 errors:0 dropped:0 overruns:0 frame:0
TX packets:49847 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:84198507 (80.2 MiB) TX bytes:5662097 (5.3 MiB)

On considère que l’interface vlan1 est l’interface public du server vpn. tun0 est l’interface virtuel d’entrée du vpn.

Voici le fichier de conf du server vpn

dev tun
ifconfig 10.10.10.10 10.10.10.11
secret /tmp/static.key
comp-lzo
port 53
verb 3

Pour plus d’info sur la configuration du vpn ici

Il faut copié cette clé sur le laptop que servira de client.

Il faut aussi activé le nat su le server vpn

iptables -t nat -A POSTROUTING -o vlan1 -j MASQUERADE

Voici le fichier de conf du client

dev tun
remote ipwanduservervpn
ifconfig 10.10.10.11 10.10.10.10
port 53
secret static.key
proto tcp-client
comp-lzo
route 192.168.30.0 255.255.255.0

Il vous reste plus qu’a vous connecter au hotspot dans votre gare préféré et de lancer votre connect vpn

et hop vous êtes chez vous :p

Filed under Linux, Securité, iptables having 12 Comments »

Archives Posts

l7-filter (suite)

décembre 14th, 2007 by Corbier

Suite à un précédent billet sur l7-filter

J’ai préparé des packets noyau 2.6.18 avec iptables l7 filter compilé prête à l’emploi.

Ils sont disponible sur le dépot http://corbier.homelinux.com/deb/l7-filter/

Faites-en bon usage.

J’ai aussi découvert une manière de cloner les disques virtuels via un outil disponible dans le paquet VirtualBox

VBoxManage clonevdi Master.vdi clone.vdi

En effet, la copie simple ne fonctionne pas (problème d’uuid).

Une autre manipulation peut être intéressante. On peut « compacter » un disque VDI.

VBoxManage modifyvdi Debian-l7-filter.vdi compact