<?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>Admin'oob.com &#187; netstat</title>
	<atom:link href="http://www.adminoob.com/tag/netstat/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adminoob.com</link>
	<description>Pour les administrateurs débutants</description>
	<lastBuildDate>Mon, 31 Aug 2009 05:35:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Sécuriser son serveur</title>
		<link>http://www.adminoob.com/2008/04/26/securiser-son-serveur/</link>
		<comments>http://www.adminoob.com/2008/04/26/securiser-son-serveur/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 13:57:46 +0000</pubDate>
		<dc:creator>Jice</dc:creator>
				<category><![CDATA[Serveur & Sécurité]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[netstat]]></category>
		<category><![CDATA[Sécurité]]></category>

		<guid isPermaLink="false">http://www.adminoob.com/?p=16</guid>
		<description><![CDATA[La sécurité est une activité, ce n&#8217;est pas un résultat. On peut s&#8217;occuper de sécurité mais on ne pourra jamais l&#8217;atteindre complètement. L&#8217;aspect sécuritaire sur un site web couvre deux aspects. Il y a tout d&#8217;abord l&#8217;interface web qui est présentée au public, et qui peut comporter des failles de programmation (sql injection, mauvaise sécurisation [...]]]></description>
			<content:encoded><![CDATA[<p><strong> La sécurité est une activité, ce n&#8217;est pas un résultat</strong>.</p>
<p align="justify">On peut s&#8217;occuper de sécurité mais on ne pourra jamais l&#8217;atteindre complètement. L&#8217;aspect sécuritaire sur un site web couvre deux aspects. Il y a tout d&#8217;abord l&#8217;interface web qui est présentée au public, et qui peut comporter des failles de programmation (sql injection, mauvaise sécurisation de la zone administrateur, &#8230;), et ensuite le serveur lui même, qui peut comporter des failles de sécurité (système d&#8217;exploitation, droits d&#8217;utilisateurs, &#8230;).</p>
<p align="justify">Cet article couvrira uniquement les aspects &#8220;serveur&#8221;. Je traiterai peut être les aspects logiciels dans un autre article. Il sera question d&#8217;un serveur Apache avec php et mysql installés tournant sous linux.<span id="more-16"></span></p>
<p style="text-align: center;"><img class="size-medium wp-image-58 aligncenter" style="border: 1px solid black; margin-top: 10px; margin-bottom: 10px;" title="Sécurité d'un serveur" src="http://www.adminoob.com/wp-content/uploads/2008/08/network_security-lock-300x225.jpg" alt="Sécurité d'un serveur" width="270" height="203" /></p>
<p align="justify">
<p align="justify">Il faut considérer la sécurité comme un oignon, pour sécuriser un système on le fera par couches successives. Pour sécuriser le serveur on considérera les deux couches suivantes (qui se sépareront en sous couches lorsque l&#8217;on voudra sécuriser encore mieux le système) : l&#8217;aspect réseau, et l&#8217;aspect système de fichiers.</p>
<p align="justify"><span style="text-decoration: underline;">A lire :</span></p>
<p align="justify"><a href="http://www.soyo123.com/HardeningLinux" target="_blank">http://www.soyo123.com/HardeningLinux</a></p>
<p align="justify"><a href="http://www.freesoftwaremagazine.com/articles/hardening_linux" target="_blank">http://www.freesoftwaremagazine.com/articles/hardening_linux </a></p>
<h3>Le Réseau :</h3>
<p align="justify">On va tenter de sécuriser les logiciels qui servent d&#8217;interface entre le serveur et le web.</p>
<h4>Ecoute des ports :</h4>
<p align="justify">La première chose à faire est d&#8217;écouter les ports de son serveur. Pour cela deux outils : <em>netstat </em>et <em>nmap</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-l</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-p</span> <span style="color: #660033;">-t</span> <span style="color: #660033;">-u</span> <span style="color: #660033;">-w</span></pre></div></div>

<p align="justify">-l pour écouter (listenning)</p>
<p align="justify">-n pour voir des informations sur l&#8217;IP</p>
<p align="justify">-p sert à recueillir des informations sur le processus qui utilise le port</p>
<p align="justify">-t, -u, -w pour les connections TCP, Udp, et Raw</p>
<p align="justify">

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">nmap</span> <span style="color: #660033;">-sS</span> 127.0.0.1</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Starting Nmap <span style="color: #000000;">4.20</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> http:<span style="color: #000000; font-weight: bold;">//</span>insecure.org <span style="color: #7a0874; font-weight: bold;">&#41;</span> at <span style="color: #000000;">2008</span>-04-<span style="color: #000000;">26</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">52</span> CEST
 Interesting ports on localhost.localdomain <span style="color: #7a0874; font-weight: bold;">&#40;</span>127.0.0.1<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
 Not shown: <span style="color: #000000;">1689</span> closed ports
 PORT STATE SERVICE
 <span style="color: #000000;">22</span><span style="color: #000000; font-weight: bold;">/</span>tcp open <span style="color: #c20cb9; font-weight: bold;">ssh</span>
 <span style="color: #000000;">25</span><span style="color: #000000; font-weight: bold;">/</span>tcp open smtp
 <span style="color: #000000;">80</span><span style="color: #000000; font-weight: bold;">/</span>tcp open http
 <span style="color: #000000;">143</span><span style="color: #000000; font-weight: bold;">/</span>tcp open imap
 <span style="color: #000000;">631</span><span style="color: #000000; font-weight: bold;">/</span>tcp open ipp
 <span style="color: #000000;">3306</span><span style="color: #000000; font-weight: bold;">/</span>tcp open mysql
 <span style="color: #000000;">8000</span><span style="color: #000000; font-weight: bold;">/</span>tcp open http-alt
 <span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>tcp open http-proxy</pre></div></div>

<p>Sert à recueillir des informations sur les ports ouverts par les processus du serveur.</p>
<hr class="system-pagebreak" title="Configuration du Pare Feu" />
<p><br class="spacer_" /></p>
<h3>Configuration du pare-feu :</h3>
<p>(A lire : <a href="http://guides.ovh.com/fireWall" target="_blank">guide OVH</a>)</p>
<p align="justify">Iptables est un pare-feu élémentaire qui nous servira à protéger l&#8217;accès à notre serveur. Iptables est configuré par un ensemble de règles qui vont définir les comportements à suivre pour les instructions entrantes, sortantes et transmises. Pour afficher les règles en cours :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ iptables <span style="color: #660033;">--list</span></pre></div></div>

<p>Nous allons les effacer, afin de reprendre au début la configuration :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ iptables <span style="color: #660033;">-F</span></pre></div></div>

<p>Pour donner une structure globale du paramétrage du pare-feu serait le suivant :</p>
<ol>
<li>Permettre les connexions sortantes initiées par le serveur</li>
<li><strong>Autoriser les connexion entrantes en ssh sur le port 22 (obligatoire sinon vous ne pourrez plus accéder à votre serveur à distance)<br />
 </strong></li>
<li>Autoriser les connexion entrantes en http sur le port 80</li>
<li>Autoriser le https sur le port 443</li>
<li>Autoriser les requêtes internes</li>
<li>Bloquer toutes les connexions ssh sortantes</li>
<li>Bloquer tout le reste</li>
</ol>
<p>Ce qui donne :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> RELATED,ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW,RELATED,ESTABLISHED <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 127.0.0.1 <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> DROP
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-j</span> REJECT
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-j</span> DROP</pre></div></div>

<p>Enfin, je sauve ces règles que je pourrai restaurer :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables-save <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>firewall
iptables-restore <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>firewall</pre></div></div>

<p>NB : pour mon serveur, j&#8217;ai rajouté les requêtes entrantes sur les ports qui m&#8217;intéressent</p>
<p><br class="spacer_" /></p>
<p><strong>ATTENTION </strong>: il est possible de restaurer le pare feu au démarrage de la machine. Or si celui-ci a été mal réglé (accès au ssh impossible par exemple ), il vous sera impossible d&#8217;accéder à votre serveur. Si jamais vous avez vérifier que toutes les requêtes aboutissaient, le lancement automatique se fera dans le dossier : /etc/init.d (voir articles dédié plus tard).</p>
<p align="justify"><strong>NOTE </strong>: Chez OVH il est important de mettre le rejet des input en REJECT. En effet,à la différence de DROP, les paquets sont traités lors d&#8217;un REJECT, et l&#8217;envoyeur reçoit un message d&#8217;erreur. Les services de OVH se basant sur un ping régulier des serveurs qu&#8217;ils hébergent, si vous placez un DROP à cet endroit, OVH pensera que votre machine s&#8217;est débranché du réseau, et la fera rebooter sans vous demander votre avis.</p>
<p><br class="spacer_" /></p>
<hr class="system-pagebreak" title="Sécuriser SSH" />
<h3>Sécuriser SSH :</h3>
<p>Changer le port de connexion : fichier de configuration : <strong>/etc/ssh/sshd_config</strong>.</p>
<p>Remplacer la ligne :</p>
<blockquote><p><em># What ports, IPs and protocols we listen for<br />
 Port 22 </em></p>
</blockquote>
<p>par</p>
<blockquote><p><em># What ports, IPs and protocols we listen for<br />
 Port 2200</em></p>
<p><br class="spacer_" /></p>
</blockquote>
<p>IMPORTANT : n&#8217;oubliez pas de rajouter le nouveau port en lecture sur iptables, et de retirer l&#8217;ancien :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">&amp;</span>amp; iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">2200</span> <span style="color: #660033;">-j</span> ACCEPT
$ iptables <span style="color: #660033;">-D</span> INPUT <span style="color: #ff0000;">&quot;numéro de la règle concernant le port 22&quot;</span></pre></div></div>

<p>Redémarrez ensuite le processus :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> restart</pre></div></div>

<hr class="system-pagebreak" title="Le système de Fichier" />
<h3>Les fichiers de configuration :</h3>
<p align="justify">Si votre système n&#8217;est pas encore envahi (le mieux étant donc de réaliser les étapes de sécurisation avant la mise en ligne du serveur si possible), il est intéressant de vérifier que vos fichiers de configuration restent inchangés dans le temps. Si cela n&#8217;est pas le cas, il s&#8217;agit sûrement d&#8217;un intrus qui a modifié les fichiers de base de votre système.</p>
<p align="justify">Il existe plusieurs <em>Intrusion Detection System </em>(IDS). Leur rôle est d&#8217;enregistrer dans une base de données des informations concernant les répertoires que vous aurez sélectionnés (configuration et autre), afin de vérifier rapidement si ces fichiers ont subi une modification depuis la création de la base de données. De manière grossière, ce type de logiciel vérifie la date de création et la taille des différents fichiers contenus dans les répertoire cibles afin de vérifier la concordance.</p>
<p align="justify">
<p align="justify">On utilisera ici le logiciel fcheck.</p>
<p align="justify">Installer le (compilation / apt-get install) et vérifier que la configuration indique bien :</p>
<blockquote><p align="justify"></p>
<p><em># Directories that will be monitored<br />
 # if there is a trailing / it will be recursive </em></p>
<p><em>Directory = /etc/<br />
 Directory = /bin/<br />
 Directory = /sbin/<br />
 Directory = /lib/<br />
 Directory = /usr/bin/<br />
 Directory = /usr/sbin/<br />
 Directory = /usr/lib/<br />
 TimeZone = PST8PDT # For Pacific Standard</em></p>
<p><em># Database of file signatures</em></p>
<p><em>DataBase = /usr/local/fcheck/sol.dbf<br />
 Logger = /usr/bin/logger -t fcheck</em></p>
<p><em># Utility to determin file type<br />
 FileTyper = /bin/file </em></p>
<p><em># What to use to create signatures Database of <br />
 # file signatures</em></p>
<p><em>$Signature = /usr/bin/md5sum#<br />
 DataBase = /usr/local/fcheck/sol.dbf<br />
 Logger = /usr/bin/logger -tfcheck</em></p>
<p><em># Utility to determin file type</em></p>
<p><em>FileTyper = /bin/file </em></p>
</blockquote>
<p><br class="spacer_" /></p>
<p>A présent, il faut initialiser la base de données pour qu&#8217;elle possède ses signatures à jour :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ fcheck <span style="color: #660033;">-cadsx</span></pre></div></div>

<div>
<p>Pour les arguments : c = Create, a=All, d=monitor, s=créer les Signatures, x= eXtended permissions monitoring</p>
</div>
<p>A suivre&#8230;</p>
<h3  class="related_post_title">Posts similaires</h3><ul class="related_post"><li><a href="http://www.adminoob.com/2008/02/12/configurer-apache/" title="Configurer Apache">Configurer Apache</a></li><li><a href="http://www.adminoob.com/2008/02/09/prevenir-les-pirates-grace-aux-erreurs-404/" title="Prévenir les pirates grâce aux erreurs 404">Prévenir les pirates grâce aux erreurs 404</a></li><li><a href="http://www.adminoob.com/2008/02/09/protection-contre-les-spameur-de-liens/" title="Protection contre les spameur de liens">Protection contre les spameur de liens</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.adminoob.com/2008/04/26/securiser-son-serveur/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

