<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://php.apsique.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Php y otras yerbas - Respuesta a un comentario sobre PHP: hablemos de seguridad - Comentarios</title>
 <link>http://php.apsique.com/contenido/respuesta_comentario_sobre_php_hablemos_seguridad</link>
 <description>Comentarios para &quot;Respuesta a un comentario sobre PHP: hablemos de seguridad&quot;</description>
 <language>es</language>
<item>
 <title>Pero si esa consulta es todo</title>
 <link>http://php.apsique.com/contenido/respuesta_comentario_sobre_php_hablemos_seguridad#comment-79639</link>
 <description>&lt;p&gt;Pero si esa consulta es todo un mostrario de COMO NO DEBE SER UNA CONSULTA&lt;/p&gt;
&lt;p&gt;Primero lo de la Inyeccion SQL&lt;br /&gt;
Segundo Validar Datos&lt;br /&gt;
Tercero Control de datos entrados&lt;/p&gt;
&lt;p&gt;que tal que el campo fecha espere aa/mm/dd y el dato vaya dd/mm/aa&lt;/p&gt;
&lt;p&gt;que tal si el medicamento DEBA existir, debe ser validado antes&lt;/p&gt;
&lt;p&gt;que tal que un campo este definido para maximo 16 letras ?? y se le pasen mas...&lt;/p&gt;
&lt;p&gt;etc... en fin Validar antes de Meterlo. Tal cual como el uso del Condon :)&lt;/p&gt;
</description>
 <pubDate>Thu, 03 Apr 2008 09:25:19 -0700</pubDate>
 <dc:creator>Hely</dc:creator>
 <guid isPermaLink="false">comment 79639 at http://php.apsique.com</guid>
</item>
<item>
 <title>Jejeje, si lo había leído,</title>
 <link>http://php.apsique.com/contenido/respuesta_comentario_sobre_php_hablemos_seguridad#comment-70973</link>
 <description>&lt;p&gt;Jejeje, si lo había leído, es rebueno.&lt;/p&gt;
</description>
 <pubDate>Wed, 21 Nov 2007 10:53:37 -0800</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">comment 70973 at http://php.apsique.com</guid>
</item>
<item>
 <title>A veces con un chiste es una</title>
 <link>http://php.apsique.com/contenido/respuesta_comentario_sobre_php_hablemos_seguridad#comment-70971</link>
 <description>&lt;p&gt;A veces con un chiste es una buena idea para entender algunas cosas:&lt;/p&gt;
&lt;p&gt;http://xkcd.com/327/ (en inglés)&lt;/p&gt;
</description>
 <pubDate>Wed, 21 Nov 2007 09:36:32 -0800</pubDate>
 <dc:creator>maeghith</dc:creator>
 <guid isPermaLink="false">comment 70971 at http://php.apsique.com</guid>
</item>
<item>
 <title>Respuesta a un comentario sobre PHP: hablemos de seguridad</title>
 <link>http://php.apsique.com/contenido/respuesta_comentario_sobre_php_hablemos_seguridad</link>
 <description>&lt;p&gt;Un usuario acaba de enviarnos un comentario, preguntando porque falla lo siguiente (he eliminado las líneas con comentarios del comentario original)&lt;/p&gt;
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-inlinetags&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;include&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;conexion.php&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;Ejecucion de la sentencia SQL&lt;/span&gt;&lt;span class=&quot;hl-comment&quot;&gt;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;  &lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;mysql_query&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;INSERT INTO medicamento (grupo, nombre,clave,formula,prioridad , presentacion, contenido,unidad_medida,existencia,nivel ) VALUES (&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[clave],&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[nombre],&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[grupo], &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[prioridad], &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[formula], &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[presentacion], &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[unidad_medida], &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[nivel], &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[existencia], &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;[contenido])&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-inlinetags&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Más allá del problema obvio de la falla de comillas en los valores de la query, alrededor de los $_POST, lo más grave es la posibilidad de hacer una inyección SQL feroz.&lt;/p&gt;
&lt;p&gt;¿Cúal es la idea? La mayoría de los lenguajes SQL aceptan el &#039;;&#039; como fin de comando. Por tanto, arreglado el tema de las comillas, si en $_POST[&#039;contenido&#039;] pusieramos &lt;pre&gt;&#039;;) DELETE FROM medicamento; --&lt;/pre&gt;, podríamos borrar tranquilamente todos los datos de la tabla.&lt;/p&gt;
&lt;p&gt;¿Qué se puede hacer? Lo más sencillo es escapar las comillas ingresadas dentro de las variables enviadas. Más paranoico, pero no por ello menos útil, es buscar en las variables enviadas por los usuarios sentencias SQL, para banear la IP o enviarle mensajes amables del tipo &quot;Si sigues haciendo inyección, te mato a la madre!&quot;.&lt;/p&gt;
&lt;p&gt;Para más información, pueden leer &lt;a href=&#039;http://www.ngssoftware.com/papers.htm&#039;&gt;algunos papers en inglés sobre el tema de la inyección&lt;/a&gt;&lt;/p&gt; </description>
 <comments>http://php.apsique.com/contenido/respuesta_comentario_sobre_php_hablemos_seguridad#comments</comments>
 <category domain="http://php.apsique.com/lenguajes/php">PHP</category>
 <category domain="http://php.apsique.com/lenguajes/php/dummies">Php para dummies</category>
 <category domain="http://php.apsique.com/categoria/temas_generales/programacion">Programación</category>
 <category domain="http://php.apsique.com/lenguajes/sql">SQL</category>
 <category domain="http://php.apsique.com/categoria/busquedas_comunes/seguridad">seguridad</category>
 <category domain="http://php.apsique.com/categoria/busquedas_comunes/sql">sql</category>
 <pubDate>Wed, 21 Nov 2007 06:49:37 -0800</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">1168 at http://php.apsique.com</guid>
</item>
</channel>
</rss>
