<?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>El Blog de Loretahur &#187; htaccess</title>
	<atom:link href="http://blog.loretahur.net/tag/htaccess/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.loretahur.net</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2012 21:21:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Qué hacer ante un robot agresivo</title>
		<link>http://blog.loretahur.net/2008/07/qu-hacer-ante-un-robot-agresivo.html</link>
		<comments>http://blog.loretahur.net/2008/07/qu-hacer-ante-un-robot-agresivo.html#comments</comments>
		<pubDate>Fri, 25 Jul 2008 22:10:00 +0000</pubDate>
		<dc:creator>Lorena Fernández</dc:creator>
				<category><![CDATA[Nireblog]]></category>
		<category><![CDATA[Seguridad]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[robot]]></category>
		<category><![CDATA[robots.txt]]></category>
		<category><![CDATA[spider]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://blog.loretahur.net/2008/07/que-hacer-ante-un-robot-agresivo.html</guid>
		<description><![CDATA[Hace unos días vimos que la carga del servidor de Nireblog subía espectacularmente en un horario en el que no suele tener mucha. Tras comprobar que había más de 700 tareas entre apache y mysql, hice un netstat y constaté que la mayoría de las conexiones venían de una sola dirección ip. Se trataba de [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/baboon/3946055/"><img src="http://blog.loretahur.net/wp-content/uploads/2008/07/robot.jpg" alt="robot" title="robot" width="174" height="180" class="alignleft size-full wp-image-1005" /></a>Hace unos días vimos que la carga del servidor de Nireblog subía espectacularmente en un horario en el que no suele tener mucha. Tras comprobar que había más de 700 tareas entre apache y mysql, hice un netstat y constaté que la mayoría de las conexiones venían de una sola dirección ip. Se trataba de un bot agresivo de <a href="http://www.genbeta.com/2007/11/07-attributor-escaneando-en-busca-de-copias-de-nuestros-contenidos-en-otros-sitios-web">Attributor</a> que estaba haciendo peticiones a diestro y siniestro (del orden de unas 10 por segundo). Tras denegar la ip mediante iptables, recuperamos la carga. Pero eso sólo fue una solución temporal, dado que usan más direcciones y ayer nos volvió a tocar con otra diferente. Así que os voy a contar una serie de soluciones que podemos aplicar ante estos robots chupa-conexiones.
<ul>
<li><span style="font-weight: bold;">Fichero robots.txt</span>: cuando un robot visita una página, lo primero que solicita es http://www.lapagina.com/robots.txt. En ese documento se le indica si tiene permitido el acceso o no. Esto, claro está, si es un bot bien programado o con buenas intenciones (por ejemplo, las arañas que se usan para extraer direcciones de correo a las que enviar spam no siguen el protocolo <img src='http://blog.loretahur.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ). Por tanto, esta solución puede que no nos valga de mucho. Para decirle que no pase, pondríamos lo siguiente:</p>
<blockquote><p>User-agent: attributor.com<br />Disallow: /</p></blockquote>
<p>Para más información sobre el funcionamiento de este fichero, pasaros por <a href="http://www.robotstxt.org/">robotstxt.org</a>. Además también tenéis un completo <a href="http://www.botsvsbrowsers.com/category/1/index.html">listado de User Agents</a> con las ip&#8217;s que suelen usar.</li>
<p>
<li><span style="font-weight: bold;">Fichero .htaccess</span>: si el bot deja su nombre en el campo user-agent, podremos denegar su acceso en este fichero de la siguiente forma:</p>
<blockquote><p>RewriteCond %{HTTP_USER_AGENT} ^.*attributor.*$<br />RewriteRule ^.* &#8211; [F,L]</p></blockquote>
<p>Con esto le estamos diciendo a nuestro apache que, a todas las peticiones que le lleguen en las que el campo User Agent tenga la palabra attributor, les devuelva el código <span style="font-style: italic;">403 : Forbidden</span>. <br />Expliquemos más a fondo la expresión regular que se usa:</p>
<ul>
<li>^   indica que es el comenzamiento de la URL</li>
<li>.*  cualquier cadena alfanumérica</li>
<li>$   indica que es el final de la URL</li>
</ul>
<p>Como vemos, esto nos librará de conexiones a base de datos, porque no se sirve nada, pero no de las conexiones a nuestro servidor web. Aunque si queremos pagar al bot con su misma moneda, podemos modificar la acción de la regla y en vez de hacer que se deniegue el acceso, se puede redirigir a la página del bot en cuestión (en nuestro caso a www.attributor.com). <br />Recordad que para usar .htaccess tenemos que tener habilitado el modulo mod_rewrite de apache.</p>
<p>Para comprobar si nos está funcionando correctamente este método, podemos hacer una petición simulada desde <a href="http://www.botsvsbrowsers.com/SimulateUserAgent.asp">aquí</a>, donde podemos introducir el User Agent a mano y hacer una petición a nuestra web.</li>
<p>
<li><span style="font-weight:bold;">Iptables</span>: si ni siquiera queremos que trabaje nuestro servidor web, podemos rechazar las peticiones con nuestro firewall. Aunque para eso deberemos conocer las direcciones ip que usa el bot. Si las sabemos, podemos agregar la siguiente regla:</p>
<blockquote><p>iptables -A INPUT -s 64.41.145.240 -j LOG &#8211;log-prefix &#8220;[BLOQ]=>&#8221;<br />iptables -A INPUT -s 64.41.145.240 -j DROP</p></blockquote>
<p>La primera línea hace que se registre el bloqueo en el log de iptables (en el caso de debian es /var/log/syslog ) y la segunda hace que todos los paquetes que lleguen de esa dirección sean descartados. Si no sabemos todas las direcciones que usan los bots, también podemos aplicar la <a href="http://gallir.wordpress.com/2008/06/14/limitar-a-los-bots-agresivos-en-las-iptables/">siguiente solución</a> que nos presentó Ricardo Galli: usar el módulo recent de iptables para que descarte las conexiones si un cliente ha intentado hacer más de 30 en 10 segundos</li>
</ul>




	<a rel="nofollow"  href="mailto:?subject=Qu%C3%A9%20hacer%20ante%20un%20robot%20agresivo&amp;body=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html" title="email"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html&amp;title=Qu%C3%A9%20hacer%20ante%20un%20robot%20agresivo&amp;notes=Hace%20unos%20d%C3%ADas%20vimos%20que%20la%20carga%20del%20servidor%20de%20Nireblog%20sub%C3%ADa%20espectacularmente%20en%20un%20horario%20en%20el%20que%20no%20suele%20tener%20mucha.%20Tras%20comprobar%20que%20hab%C3%ADa%20m%C3%A1s%20de%20700%20tareas%20entre%20apache%20y%20mysql%2C%20hice%20un%20netstat%20y%20constat%C3%A9%20que%20la%20mayor%C3%ADa%20de%20las%20c" title="del.icio.us"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html&amp;t=Qu%C3%A9%20hacer%20ante%20un%20robot%20agresivo" title="Facebook"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html&amp;title=Qu%C3%A9%20hacer%20ante%20un%20robot%20agresivo&amp;annotation=Hace%20unos%20d%C3%ADas%20vimos%20que%20la%20carga%20del%20servidor%20de%20Nireblog%20sub%C3%ADa%20espectacularmente%20en%20un%20horario%20en%20el%20que%20no%20suele%20tener%20mucha.%20Tras%20comprobar%20que%20hab%C3%ADa%20m%C3%A1s%20de%20700%20tareas%20entre%20apache%20y%20mysql%2C%20hice%20un%20netstat%20y%20constat%C3%A9%20que%20la%20mayor%C3%ADa%20de%20las%20c" title="Google Bookmarks"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://barrapunto.com/submit.pl?subj=Qu%C3%A9%20hacer%20ante%20un%20robot%20agresivo&amp;story=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html" title="BarraPunto"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/barrapunto.png" title="BarraPunto" alt="BarraPunto" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html&amp;title=Qu%C3%A9%20hacer%20ante%20un%20robot%20agresivo&amp;source=El+Blog+de+Loretahur+&amp;summary=Hace%20unos%20d%C3%ADas%20vimos%20que%20la%20carga%20del%20servidor%20de%20Nireblog%20sub%C3%ADa%20espectacularmente%20en%20un%20horario%20en%20el%20que%20no%20suele%20tener%20mucha.%20Tras%20comprobar%20que%20hab%C3%ADa%20m%C3%A1s%20de%20700%20tareas%20entre%20apache%20y%20mysql%2C%20hice%20un%20netstat%20y%20constat%C3%A9%20que%20la%20mayor%C3%ADa%20de%20las%20c" title="LinkedIn"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html" title="Technorati"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bitacoras.com/anotaciones/http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html" title="Bitacoras.com"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/bitacoras.png" title="Bitacoras.com" alt="Bitacoras.com" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.wikio.com/vote?url=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html" title="Wikio"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/wikio.png" title="Wikio" alt="Wikio" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=Qu%C3%A9%20hacer%20ante%20un%20robot%20agresivo&amp;link=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html" title="FriendFeed"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html" title="Identi.ca"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=Qu%C3%A9%20hacer%20ante%20un%20robot%20agresivo%20-%20http%3A%2F%2Fblog.loretahur.net%2F2008%2F07%2Fqu-hacer-ante-un-robot-agresivo.html" title="Twitter"><img src="http://blog.loretahur.net/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.loretahur.net/2008/07/qu-hacer-ante-un-robot-agresivo.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

