<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JoPa.Fr &#187; Firewall</title>
	<atom:link href="http://www.jopa.fr/index.php/tag/firewall/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jopa.fr</link>
	<description>001100010BIDOUILLE11101010111100010LIBRE1000100111100101</description>
	<lastBuildDate>Tue, 10 Jan 2012 21:59:31 +0000</lastBuildDate>
	<language>fr</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Openwrt, Openvpn et Firewall&#8230;</title>
		<link>http://www.jopa.fr/index.php/2008/11/03/openwrt-openvpn-et-firewall/</link>
		<comments>http://www.jopa.fr/index.php/2008/11/03/openwrt-openvpn-et-firewall/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 00:01:55 +0000</pubDate>
		<dc:creator>Jopa</dc:creator>
				<category><![CDATA[Bidouilles]]></category>
		<category><![CDATA[Configurations]]></category>
		<category><![CDATA[Planet-Libre]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[Openvpn]]></category>
		<category><![CDATA[Openwrt]]></category>
		<category><![CDATA[Sécurité]]></category>

		<guid isPermaLink="false">http://www.jopa.fr/?p=687</guid>
		<description><![CDATA[Les dernières versions d&#8217;Openwrt (développement) intègrent un système de configuration plus homogène. L&#8217;ensemble de la configuration des services est placée dans le répertoire /etc/config, au même titre que le paramétrage des interfaces réseaux et wifi. La syntaxe diffère un peu de ce que nous pouvions avoir vu jusque là et mérite que nous y regardions [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><a href="http://www.jopa.fr/wp-content/uploads/2008/10/politique_defaut.png"><img class="alignright size-medium wp-image-696" title="politique_defaut" src="http://www.jopa.fr/wp-content/uploads/2008/10/politique_defaut-300x258.png" alt="" width="300" height="258" /></a>Les dernières versions d&#8217;Openwrt (développement) intègrent un système de configuration plus homogène. L&#8217;ensemble de la configuration des services est placée dans le répertoire /etc/config, au même titre que le paramétrage des interfaces réseaux et wifi. La syntaxe diffère un peu de ce que nous pouvions avoir vu jusque là et mérite que nous y regardions de plus près.</p>
<p style="text-align: justify;">La suite de l&#8217;article va présenter la configuration d&#8217;un client Openvpn et la mise en place de quelques règles de firewall entre le lan, Internet et ce vpn.</p>
<p style="text-align: justify;">
<p style="text-align: justify;"><span id="more-687"></span></p>
<h1>Openvpn</h1>
<p style="text-align: justify;">L&#8217;installation ne pose pas de problème particulier, il faut quand même penser que l&#8217;outil de gestion des paquets est maintenant <em>opkg</em> et non plus <em>ipkg</em> !</p>
<p style="text-align: justify;"><em>opkg install openvpn</em></p>
<p style="text-align: justify;">Comme précisé en introduction, le fichier de configuration est maintenant <em>/etc/config/openvpn.</em></p>
<p style="text-align: justify;">Le fichier founit par le paquet contient deux exemples de configurations bien commentés  (serveur ou client). L&#8217;exemple ci-dessous concerne un client.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p687code7'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6877"><td class="code" id="p687code7"><pre class="ini" style="font-family:monospace;">package openvpn                                                                                                                                              
&nbsp;
config openvpn linet.jopa                                                                                                                                    
&nbsp;
    # Activer le VPN
    option enable <span style="">1</span>                                                                                                                                      
&nbsp;
    # Mode Client
    option client <span style="">1</span>                                                                                                                                      
&nbsp;
    # Type d'interface <span style="">&#40;</span>tap ou tun<span style="">&#41;</span>
    option dev tun                                                                                                                                       
&nbsp;
    # Protocole <span style="">&#40;</span>tcp ou udp<span style="">&#41;</span>
    option proto udp                                                                                                                                     
&nbsp;
    # Adresse et port du serveur
    # Plusieurs lignes possible pour effectuer du load balancing
    # XX.XX.XX.XX est à remplacer par l'IP publique du serveur VPN
    list remote <span style="color: #933;">&quot;XX.XX.XX.XX 1194&quot;</span>                                                                                                                      
&nbsp;
    # Définition de la liaison point à point
    # N'est pas utilse si un pool d'adresses est defini sur le serveur
    option ifconfig <span style="color: #933;">&quot;10.8.1.1 10.8.1.2&quot;</span>                                                                                                        
&nbsp;
    # Essayer de résoudre l'adresse du serveur indéfiniment
    option resolv_retry infinite                                                                                                                         
&nbsp;
    # Inutile d'attacher un port specifique au client
    option nobind <span style="">1</span>                                                                                                                                      
&nbsp;
    # Essayer de conserver certains états au redémarrage
    option persist_key <span style="">1</span>
    option persist_tun <span style="">1</span>                              
&nbsp;
    # Chemin des clés et certificats SSL/TLS
    option ca /etc/openvpn/ca.crt
    option cert /etc/openvpn/linet.jopa.crt
    option key /etc/openvpn/linet.jopa.key                                                                                                               
&nbsp;
    # Activer le compression lzo
    option comp_lzo <span style="">1</span>                                                                                                                                    
&nbsp;
    # Niveaux de Logs
    option verb <span style="">3</span></pre></td></tr></table></div>

<p style="text-align: justify;">La configuration du client VPN est terminée&#8230;<br />
Pour complément d&#8217;informations, vous trouverez ci-dessous la configuration du serveur VPN correspondant. (Openvpn sur serveur Debian Etch). Le site &laquo;&nbsp;<a title="http://www.coagul.org/spip.php?article422&amp;var_recherche=openvpn" href="http://www.coagul.org/spip.php?article422&amp;var_recherche=openvpn">Coagul</a>&nbsp;&raquo; propose un tutoriel complet sur la mise en place d&#8217;une architecture Openvpn (SSL/TLS).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p687code8'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6878"><td class="code" id="p687code8"><pre class="ini" style="font-family:monospace;"># Serveur OpenVPN - Liaison avec Fonera/Openwrt Maison
&nbsp;
# Protocole / Interface / Port
proto udp
dev tun
port <span style="">1194</span>
&nbsp;
# Certificats 
&nbsp;
ca ca.crt
cert vpnserver.crt
key vpnserver.key
dh dh2048.pem
&nbsp;
# Serveur <span style="">&#40;</span>SSL/TLS<span style="">&#41;</span>
tls-server
&nbsp;
# Configuration statique des adresses Ptp
ifconfig 10.8.1.2 10.8.1.1
&nbsp;
# Adresse publique locale à utiliser
local XX.XX.XX.XX
&nbsp;
# Keepalive
keepalive <span style="">10</span> <span style="">90</span>
&nbsp;
# Compression LZO
comp-lzo
&nbsp;
# Utilisateur et groupe du démon openvpn
user nobody
group nogroup
&nbsp;
# Conserver l'état des clés et de l'interface au redémarrage
persist-key
persist-tun
&nbsp;
# Fichier de status
status openvpnlinet-status.log
&nbsp;
# Création d'une route sur le serveur
route 192.168.7.0 255.255.255.0
&nbsp;
# Ajout de routes sur le client
push <span style="color: #933;">&quot;route 192.168.70.0 255.255.255.0&quot;</span>
push <span style="color: #933;">&quot;route 192.168.72.0 255.255.255.0&quot;</span></pre></td></tr></table></div>

<h1>Firewall</h1>
<p>Nous disposons maintenant d&#8217;un routeur/firewall <em>OpenWrt</em> à trois pattes :</p>
<ul>
<li>LAN :  bridge entre l&#8217;interface ethernet connectée au réseau privé et l&#8217;interface wifi,</li>
<li>WAN : Interface ethernet publique,</li>
<li>VPN :  Interface virtuelle pour le vpn.</li>
</ul>
<p>Il nous faut avant tout déclarer l&#8217;interface <em>tun0</em> dans la configuration réseau pour pouvoir ensuite l&#8217;affecter à une zone du firewall. Celle-ci sera déclarée sur un réseau que nous appellerons arbitrairement &laquo;&nbsp;<em>vpn</em>&laquo;&nbsp;.</p>
<p><em>/etc/config/network</em></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p687code9'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6879"><td class="code" id="p687code9"><pre class="ini" style="font-family:monospace;">config 'interface' 'loopback'
        option 'ifname' 'lo'
        option 'proto' 'static'
        option 'ipaddr' '127.0.0.1'
        option 'netmask' '255.0.0.0'
&nbsp;
config 'interface' 'lan'
        option 'type' 'bridge'
        option 'proto' 'static'
        option 'ipaddr' '192.168.7.253'
        option 'netmask' '255.255.255.0'
        option 'ifname' 'eth0.0'
        option 'dns' '192.168.7.2'
&nbsp;
config 'interface' 'wan'
        option 'ifname' 'eth0.1'
        option 'proto' 'dhcp'
&nbsp;
config 'interface' 'vpn'
        option 'ifname' 'tun0'
        option 'network' 'vpn'
        option 'proto' 'none'</pre></td></tr></table></div>

<h2>Définition de la politique par défaut</h2>
<p>Nous pouvons dès à présent attaquer la configuration du Firewall. Pour une utilisation à domicile, nous allons opter pour une politique assez ouverte (pas trop quand même !).</p>
<p><a href="http://www.jopa.fr/wp-content/uploads/2008/10/politique_defaut.png"><img class="aligncenter size-full wp-image-696" title="politique_defaut" src="http://www.jopa.fr/wp-content/uploads/2008/10/politique_defaut.png" alt="" width="500" height="431" /></a></p>
<p>Seul le trafic du <em>lan</em> vers le routeur et du routeur vers Internet est ouvert.</p>
<p style="text-align: justify;">Si nous avions appliqué une politique plus sévère, nous aurions tout vérouillé à ce stade, pour gérer ensuite les autorisations au cas par cas en fonction du type flux.</p>
<p>/etc/config/firewall</p>
<pre style="text-align: justify;" lang="ini">config 'defaults'
        option 'syn_flood' '1'
        option 'input' 'REJECT'
        option 'output' 'REJECT'
        option 'forward' 'REJECT'                                                                    

config 'zone'
        option 'name' 'lan'
        option 'input' 'ACCEPT'
        option 'output' 'REJECT'
        option 'forward' 'REJECT'                                                                    

config 'zone'
        option 'name' 'vpn'
        option 'input' 'REJECT'
        option 'output' 'REJECT'
        option 'forward' 'REJECT'                                                                                                                                 

config 'zone'
        option 'name' 'wan'
        option 'input' 'REJECT'
        option 'forward' 'REJECT'
        option 'output' 'ACCEPT
        option 'masq' '1'</pre>
<p style="text-align: justify;">La dernière option (masq) permet biensûr d&#8217;activer le masquerading pour internet.</p>
<h2>Quelques ouvertures</h2>
<p style="text-align: justify;">Au delà de ce paramétrage par défaut, nous avons besoins d&#8217;être un peu plus permissifs, histoire de rendre la connexion internet utilisable !</p>
<p>Comme nous somme à la maison, nous allons nous permettre d&#8217;ouvrir le trafic provenant du <em>lan</em> et à destination du <em>vpn</em> ou d&#8217;<em>Internet</em>.</p>
<p><a href="http://www.jopa.fr/wp-content/uploads/2008/10/etape1.png"><img class="aligncenter size-full wp-image-702" title="etape1" src="http://www.jopa.fr/wp-content/uploads/2008/10/etape1.png" alt="" width="500" height="431" /></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p687code10'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p68710"><td class="code" id="p687code10"><pre class="ini" style="font-family:monospace;">config 'forwarding'
        option 'src' 'lan'
        option 'dest' 'wan'                                                                        
&nbsp;
config 'forwarding'
        option 'src' 'lan'
        option 'dest' 'vpn'</pre></td></tr></table></div>

<p style="text-align: justify;">Nous allons ensuite autoriser <em>ssh</em> et le <em>ping</em> depuis le <em>vpn</em> vers le <em>lan</em>&#8230; Puis soyons fous, nous allons aussi permettre le ping du routeur depuis Internet.</p>
<p><a href="http://www.jopa.fr/wp-content/uploads/2008/10/etape21.png"><img class="aligncenter size-full wp-image-704" title="etape21" src="http://www.jopa.fr/wp-content/uploads/2008/10/etape21.png" alt="" width="500" height="431" /></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p687code11'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p68711"><td class="code" id="p687code11"><pre class="ini" style="font-family:monospace;">config 'rule'
        option '_name' 'Ssh depuis VPN'
        option 'src' 'vpn'
        option 'dest' 'lan'
        option 'proto' 'tcp'
        option 'dest_port' '<span style="">22</span>'
        option 'target' 'ACCEPT'
&nbsp;
config 'rule'
        option '_name' 'Ping depuis VPN'
        option 'src' 'vpn'
        option 'dest' 'lan'
        option 'proto' 'icmp'
        option 'target' 'ACCEPT'  
&nbsp;
config 'rule'
        option '_name' 'Ping depuis Internet'
        option 'src' 'wan'
        option 'proto' 'icmp'
        option 'target' 'ACCEPT'</pre></td></tr></table></div>

<p style="text-align: justify;">Pour finir, nous pouvons rendre accessible depuis <em>Internet</em> le serveur web d&#8217;une machine située sur le Lan. ( Ceci est un exemple, dans la pratique, une <em>dmz</em> ne serait pas du luxe !).</p>
<p><a href="http://www.jopa.fr/wp-content/uploads/2008/10/etape3.png"><img class="aligncenter size-full wp-image-705" title="etape3" src="http://www.jopa.fr/wp-content/uploads/2008/10/etape3.png" alt="" width="500" height="431" /></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p687code12'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p68712"><td class="code" id="p687code12"><pre class="ini" style="font-family:monospace;">config 'redirect'
        option '_name' 'Http vers web perso'
        option 'src' 'wan'
        option 'proto' 'tcp'
        option 'src_dport' '<span style="">22</span>'
        option 'dest_ip' '192.168.7.2'
        option 'dest_port' '<span style="">22</span>'</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.jopa.fr/index.php/2008/11/03/openwrt-openvpn-et-firewall/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bases d&#8217;un firewall sur serveur dédié avec Netfilter (iptables)</title>
		<link>http://www.jopa.fr/index.php/2008/09/26/bases-dun-firewall-sur-serveur-dedie-avec-netfilter-iptables/</link>
		<comments>http://www.jopa.fr/index.php/2008/09/26/bases-dun-firewall-sur-serveur-dedie-avec-netfilter-iptables/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 00:14:17 +0000</pubDate>
		<dc:creator>Jopa</dc:creator>
				<category><![CDATA[Réseau]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sécurité]]></category>

		<guid isPermaLink="false">http://www.jopa.fr/?p=231</guid>
		<description><![CDATA[Notre serveur dédié se sent un peu nu sur Internet et pour cause : il n&#8217;est doté d&#8217;aucun filtrage IP. Il faudrait rapidement lui injecter, à l&#8217;aide d&#8217;iptables, quelques règles netfilter afin de le protéger un minimum. Nous allons créer un script contenant les règles à mettre en place. Ce script sera lancé au démarrage [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><img class="alignleft size-thumbnail wp-image-219" title="mur" src="http://www.jopa.fr/wp-content/uploads/2008/09/mur-150x150.jpg" alt="" width="129" height="129" />Notre serveur dédié se sent un peu nu sur Internet et pour cause : il n&#8217;est doté d&#8217;aucun filtrage IP. Il faudrait rapidement lui injecter, à l&#8217;aide d&#8217;<em>iptables, </em>quelques règles <em>netfilter</em> afin de le protéger un minimum.</p>
<p style="text-align: justify;">Nous allons créer un script contenant les règles à mettre en place. Ce script sera lancé au démarrage du serveur.</p>
<p style="text-align: justify;"><span id="more-231"></span></p>
<h2>Initialisation</h2>
<p>La toute première étape va consister à vider les tables :</p>
<pre><span style="color: #800000;"># RAZ DES TABLES
iptables -t filter -F
iptables -t filter -X</span>
 .</pre>
<p>Les connexions existantes ne doivent pas être cassées&#8230; C&#8217;est utile sur un serveur dédié, pour ne pas perdre la main.</p>
<pre><span style="color: #800000;"># Ne pas casser les connexions établies
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT</span>
 .</pre>
<p>Comme toujours quand on parle de sécurité, nous allons commencer par tout interdire. Aucun paquet, qu&#8217;il soit entrant, sortant ou routé par le serveur ne doit passer.</p>
<pre><span style="color: #800000;"># Interdire tous les paquets...tous...
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT DROP</span>
 .</pre>
<p>A nous maintenant d&#8217;autoriser le trafic nécessaire&#8230; Et seulement le trafic nécessaire.  Nous allons, dans l&#8217;ordre, étudier les connexions entrante, sortantes et éventuellement celles susceptibles d&#8217; être routées par la machine; C&#8217;est relativement rare pour un serveur dédié, mais possible, dans le cas de VPN par exemple.</p>
<h2>Règles pour les paquets entrants</h2>
<p style="text-align: center;"><em>Quels services sont fournis par le serveur ?</em></p>
<ul>
<li>Un serveur WEB,</li>
</ul>
<pre><span style="color: #800000;"># HTTP
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT</span>
.</pre>
<ul>
<li>Un serveur VPN (OpenVPN) pour un client dont l&#8217;adresse IP est XXX.XXX.XXX.XXX,</li>
</ul>
<pre><span style="color: #800000;"># OpenVPN
iptables -t filter -A INPUT -p udp --dport 1194 -s XXX.XXX.XXX.XXX -j ACCEPT</span>
.</pre>
<ul>
<li>Un serveur de mails,</li>
</ul>
<pre><span style="color: #800000;"># SMTP
iptables -t filter -A INPUT -p tcp --dport 25 -j ACCEPT</span>
.</pre>
<ul>
<li>Les boites mails sont accessibles en POP et IMAP, mais depuis le VPN uniquement,</li>
</ul>
<pre><span style="color: #800000;"># POP3
iptables -t filter -A INPUT  -i tun+ -p tcp --dport 110 -j ACCEPT
# IMAP
iptables -t filter -A INPUT -i tun+ -p tcp --dport 143 -j ACCEPT</span>
.</pre>
<ul>
<li>De même, un serveur DNS est disponible pour les machines du vpn,</li>
</ul>
<pre><span style="color: #800000;"># DNS en Entrée
iptables -t filter -A INPUT -i tun+ -p tcp --dport 53 -j ACCEPT
iptables -t filter -A INPUT -i tun+ -p udp --dport 53 -j ACCEPT</span>
.</pre>
<ul>
<li>Pour être conforme au RFC, le serveur répond aux requêtes ICMP (ping),</li>
</ul>
<pre><span style="color: #800000;"># ICMP
iptables -t filter -A INPUT -p icmp -j ACCEPT</span>
.</pre>
<ul>
<li>N&#8217;oublions pas SSH&#8230; Ca peut toujours servir,</li>
</ul>
<pre><span style="color: #800000;"># SSH
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT</span>
.</pre>
<ul>
<li>Enfin, aucune restriction n&#8217;est appliquée pour l&#8217;interface Loopback (Localhost)</li>
</ul>
<pre><span style="color: #800000;"># LOOPBACK
iptables -t filter -A INPUT -i lo -j ACCEPT</span>
.</pre>
<h2>Règles pour les paquets sortants</h2>
<p style="text-align: center;"><em>Quels services sont nécessaires au serveur ?</em></p>
<ul>
<li>Le serveur doit pouvoir envoyer des requêtes DNS,</li>
</ul>
<pre><span style="color: #800000;"># DNS
iptables -t filter -A OUTPUT  -p tcp --dport 53 -j ACCEPT
iptables -t filter -A OUTPUT  -p udp --dport 53 -j ACCEPT</span>
.</pre>
<ul>
<li>Disposer d&#8217;un accès HTTP ( utile pour les mises à jour ),</li>
</ul>
<pre><span style="color: #800000;"># HTTP
iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT</span>
.</pre>
<ul>
<li>Ssh est autorisé en sortie,</li>
</ul>
<pre><span style="color: #800000;"># SSH
iptables -t filter -A OUTPUT -p tcp --dport 22 -j ACCEPT</span>
.</pre>
<ul>
<li>Envoyer des mails,</li>
</ul>
<pre><span style="color: #800000;"># SMTP
iptables -t filter -A OUTPUT -p tcp --dport 25 -j ACCEPT</span>
.</pre>
<ul>
<li>Récupérer des mails sur un compte POP3 par l&#8217;intermédiaire de <em>fetchmail,</em></li>
</ul>
<pre><span><span style="color: #800000;"># POP3
iptables -t filter -A OUTPUT -p tcp --dport 110 -j ACCEPT</span></span>
.</pre>
<ul>
<li>Pinguer (ben tiens !),</li>
</ul>
<pre><span style="color: #800000;"># ICMP
iptables -t filter -A OUTPUT -t icmp -j ACCEPT</span>
.</pre>
<ul>
<li>Etablir une connexion OpenVPN vers un autre serveur dont l&#8217;adresse IP est YYY.YYY.YYY.YYY : Ce serveur interconnecte un VPN dont il est le serveur avec un VPN dont il est client,</li>
</ul>
<pre><span style="color: #800000;"># VPN
iptables -t filter -A OUTPUT -p udp --dport 1194 -d YYY.YYY.YYY.YYY -j ACCEPT</span>
.</pre>
<ul>
<li>Enfin, aucune restriction sur l&#8217;interface loopback,</li>
</ul>
<pre><span style="color: #800000;"># LOOPBACK
iptables -t filter -A OUTPUT -o lo -j ACCEPT</span>
.</pre>
<h2>Règle pour les paquets traversants (routés)</h2>
<ul>
<li>Ce serveur interconnecte deux VPN, on ne souhaite pas filter le trafic d&#8217;un VPN vers l&#8217;autre,</li>
</ul>
<pre><span style="color: #800000;"># VPN2VPN
iptables -t filter -A FORWARD -i tun+ -o tun+ -j ACCEPT
</span>
.</pre>
<h2><span style="color: #800000;">Syn flood, spoofing et compagnie&#8230;</span></h2>
<p>Pour finir, ajoutons quelques règles pour limiter tout ça, quelques traces dans les logs et le tour sera joué&#8230;</p>
<ul>
<li>Limitation du syn flood</li>
</ul>
<pre><span style="color: #800000;"># Syn Flood
iptables -A FORWARD -p tcp --syn -m limit --limit 1/second -j ACCEPT
iptables -A FORWARD -p udp  -m limit --limit 1/second -j ACCEPT</span>
.</pre>
<ul>
<li>&laquo;&nbsp;Anti-spoofing&nbsp;&raquo;</li>
</ul>
<pre><span style="color: #800000;"># Spoofing
iptables -N SPOOFED
iptables -A SPOOFED -s 127.0.0.0/8 -j DROP
iptables -A SPOOFED -s 169.254.0.0/12 -j DROP
iptables -A SPOOFED -s 172.16.0.0/12 -j DROP
iptables -A SPOOFED -s 192.168.0.0/16 -j DROP
iptables -A SPOOFED -s 10.0.0.0/8 -j DROP</span>
.</pre>
<ul>
<li>Log des paquets rejetés dans syslog</li>
</ul>
<pre><span style="color: #800000;"># LOG des paquets rejetés
iptables -N LOG_DROP
iptables -A LOG_DROP -j LOG --log-prefix '[IPTABLES DROP]:'
iptables -A LOG_DROP -j DROP
iptables -t filter -A INPUT -j LOG_DROP
iptables -t filter -A OUTPUT -j LOG_DROP
iptables -t filter -A FORWARD -j LOG_DROP</span>
.</pre>
<p>Voilà, ce n&#8217;est pas trop mal  pour un début ; ) Ci-dessous, le script &laquo;&nbsp;recollé&nbsp;&raquo; :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p231code14'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23114"><td class="code" id="p231code14"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">##########</span>
<span style="color: #666666; font-style: italic;">## INIT ##</span>
<span style="color: #666666; font-style: italic;">##########</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># RAZ DES TABLES</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-F</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-X</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Ne pas casser les connexions établies</span>
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> RELATED,ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> RELATED,ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># Interdire tous les paquets...tous...</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-P</span> INPUT DROP
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-P</span> FORWARD DROP
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-P</span> OUTPUT DROP
&nbsp;
<span style="color: #666666; font-style: italic;">###########</span>
<span style="color: #666666; font-style: italic;">## INPUT ##</span>
<span style="color: #666666; font-style: italic;">###########</span>
<span style="color: #666666; font-style: italic;"># HTTP</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># OpenVPN</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">1194</span> <span style="color: #660033;">-s</span> XXX.XXX.XXX.XXX <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># SMTP</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">25</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># POP3</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT  <span style="color: #660033;">-i</span> tun+ <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">110</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># IMAP</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> tun+ <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">143</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># DNS en Entrée</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> tun+ <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> tun+ <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># ICMP</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># SSH</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># LOOPBACK</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;">############</span>
<span style="color: #666666; font-style: italic;">## OUTPUT ##</span>
<span style="color: #666666; font-style: italic;">############</span>
<span style="color: #666666; font-style: italic;"># DNS</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT  <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT  <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># HTTP</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># SSH</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># SMTP</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">25</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># POP3</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">110</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># ICMP</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-t</span> icmp <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># VPN</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">1194</span> <span style="color: #660033;">-d</span> YYY.YYY.YYY.YYY <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;"># LOOPBACK</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-o</span> lo <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;">###############</span>
<span style="color: #666666; font-style: italic;">## FORWARD ##</span>
<span style="color: #666666; font-style: italic;">###############</span>
<span style="color: #666666; font-style: italic;"># VPN2VPN</span>
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> tun+ <span style="color: #660033;">-o</span> tun+ <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;">###############</span>
<span style="color: #666666; font-style: italic;">## FINITIONS ##</span>
<span style="color: #666666; font-style: italic;">###############</span>
<span style="color: #666666; font-style: italic;"># Syn Flood</span>
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--syn</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>second <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-p</span> udp  <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>second <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #666666; font-style: italic;"># Spoofing</span>
iptables <span style="color: #660033;">-N</span> SPOOFED
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 127.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 169.254.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">12</span> <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 172.16.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">12</span> <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 192.168.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">16</span> <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-A</span> SPOOFED <span style="color: #660033;">-s</span> 10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP
&nbsp;
<span style="color: #666666; font-style: italic;"># LOG des paquets rejetés</span>
iptables <span style="color: #660033;">-N</span> LOG_DROP
iptables <span style="color: #660033;">-A</span> LOG_DROP <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">'[IPTABLES DROP]:'</span>
iptables <span style="color: #660033;">-A</span> LOG_DROP <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-j</span> LOG_DROP
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-j</span> LOG_DROP
iptables <span style="color: #660033;">-t</span> filter <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-j</span> LOG_DROP</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.jopa.fr/index.php/2008/09/26/bases-dun-firewall-sur-serveur-dedie-avec-netfilter-iptables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

