[Programación] RE: [Programación] Problemas en php
programacion@lugro.org.ar
programacion@lugro.org.ar
Wed, 24 Nov 2004 09:57:21 -0300
La forma en que están tomando los parámetros es muy insegura.
Lo que tendrían que hacer es tomar los valores que pasan por la URL y
validarlos antes de mandar la consulta al servidor sql. Yo validaría que el
valor que se pasa en la variable $ids es numérico y no alfanumérico, de esta
menera solo me se va a tomar como parámetro un numero que corresponda al
mensaje que queres mostrar.
Creo que la mejor manera sería utilizar una expresión regular. Fijate en el
manual de PHP tenes las funciones para expresiones regulares.
Siempre es conveniente tomar todas las variables y parámetros que se pasan
de un script a otro como INSEGUROS ya que es la forma mas fácil de inyectar
código malicioso en un script.
Suerte.
Omar
-----Mensaje original-----
De: KSTOR [mailto:ekstor@yahoo.com.ar]
Enviado el: Miércoles 24 de Noviembre de 2004 09:26
Para: programacion@lugro.org.ar
Asunto: [Programación] Problemas en php
-----BEGIN PGP SIGNED MESSAGE-----Hash: SHA1
Amigos,...
Tengo un compañero que tiene en su página una especie de foro en PHP.El tema
es que existe un bugs por el cual le borran msj y ademáspueden ver la IP de
los que postean, etc...
El problema reside en que si en el navegar
ingresaswww.pagina.org/foro/reply.php?id=1,1Te devuelve el primer mensaje
(el id=1)Pero si pones:www.pagina.org/foro/reply.php?id=1,1 and ip like
1%Busca cualquier mensaje que cumpliese la segunda condición, e imaginoque
por este método es posible inyectar ordenes delete.Mi amigo añadió estas dos
instrucciones para intentar resolverlo
$ids[0] = intval($ids[0]);$ids[1] = intval($ids[1]);
Pero no tubo resultados.Ademas $ids = split( ",", $id, 2 ); solo deja pasar
numeros enteros pero en la practica es posible enviar cualquier orden a la
base de datos.Adjunto el código de la página en donde puede existir el
problema.
#################
<?php require( "../comun/cabeza.inc" ); require(
"functions.php" ); if( !isset( $id ) ) error( "LLamada incoreccta
a'reply.php'" ); $ids = (int) (array) $ids; $ids = split( ",",
$id, 2 );
$ids[0] = intval($ids[0]); $ids[1] = intval($ids[1]);
dbConnect(); $result = mysql_query( "SELECT rootID, name,
email, topic,msg, time, ip FROMforum WHERE rootID=${ids[ 1 ]}" ) or error(
mysql_error() ); $row = mysql_fetch_array( $result ); unset(
$result ); displayHeader( $forumTitle ); echo " <div
align=center> <center> <table border=0 cellpadding=0
cellspacing=0 width=80%> <tr> <td align=left
width=100% height=20> <a href=forum.php>Indice del
foro</a> </td> </tr> <tr>
<td width=100% height=1 bgcolor=#808080></td> </tr>
</table> </center> </div> <div align=center>
<center> <table border=0 cellpadding=0 cellspacing=0
width=80%> <tr> <b>De:</b> {$row[ 'name' ]} <a
href=mailto:{$row[ 'email' ]}>({$row['email' ]})</a><br>
<td><b>Asunto:</b> {$row[ 'topic' ]}<br> <b>Mens!
aje:</b> {$row[ 'msg' ]}</p>"; echo "
</tr> </table> </center> </div> <hr size=1
color=#808080 width=80%>"; if( $row[ 'ip' ] == "")
displayFooter(); echo " <a
name=reply> <center><h4>Responder</h4></center> <form
method=post action=post.php> <input type=hidden name=action
value=reply> <input type=hidden name=id value=\"${ids[ 0 ]},{$row[
'rootID' ]}\"> <div align=center> <center> <table
border=0 cellpadding=0 cellspacing=2 width=580> <tr>
<td width=80 height=18><b>Asunto:</b></td> <td width=500
height=18><input type=text name=topicvalue=\"RE: {$row['topic' ]}\" size=50
maxlength=50></td> </tr> <tr> <td
width=80 height=18><b>Nombre:</b></td> <td width=500
height=18><input type=text name=namesize=20
maxlength=20value='Anonimo'></td> </tr> !
<tr> <td width=80 height=18><b>E-mail:</b></td>
<td width=500 height=18><input type=text name=emailsize=40maxlength=40
value='Anonimo@anonino.com'></td> </tr> <tr>
<td width=80
valign='top'><b>Mensaje:</b><br><inputtype=submitvalue=Responder></td>
<td width=500><textarea style='height:auto;' name=msgrows=10
cols=50maxlength=2000></textarea></td> </tr> <tr>
<td width=80 height=18></td> <td width=500
height=18><input type=hidden name=getmailvalue=no></td>
</tr> <tr> <td width=80
height=18></td> <td width=500 height=18></td>
</tr> </table> </center> </div>
</form>"; require( "../comun/pie.inc"
); displayFooter();
?>
#################
Que puede estar pasando?
SALUDOS y Gracias...
- --Martín Di Luzioekstor@yahoo.com.arJabber ID: kstor@lugro.org.arUsuario
GNU/Linux #320520 - http://counter.li.org/
«Copyleft--all rights reversed»
-----BEGIN PGP SIGNATURE-----Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBpH3gPlxjGDYynKYRAnnEAJ9xGYj/TSQFlP3up5RfHfxze2rKswCfZQ3LsJBZxpvMS+Y5
47lhrHS1v00==eOu1-----END PGP SIGNATURE-----
_______________________________________________
Programacion mailing list
Programacion@lugro.org.ar
http://www.lugro.org.ar/mailman/listinfo/programacion