Ver Mensaje Individual
  #12 (permalink)  
Antiguo 27/02/2012, 12:09
Avatar de Nemutagk
Nemutagk
Colaborador
 
Fecha de Ingreso: marzo-2004
Ubicación: México
Mensajes: 2.633
Antigüedad: 20 años, 1 mes
Puntos: 406
Respuesta: Vulnerabilidad de mi UPLOAD

Viendo detenidamente todo tu código es un spaguetti, sin ofender, pero tienes varios errores, no debes hacer que PHP imprima tanto código HTML estatico, solo haces que PHP trabaje mas para nada, usas short tags (<?) cuando estos están deprecate, debes usar <?php y vamos, con la llave me parece que era muy sencillo saber donde colocar la llave faltante...

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html>
  3.  
  4. <head>
  5. <link rel="stylesheet" href="styles.css" type="text/css" media="screen" />
  6. <link rel="shortcut icon" href="favicon.ico" />
  7. <meta http-equiv="imagetoolbar" content="false" />
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>Quien se ve mejor? - Sube tu foto</title>
  10.  
  11. <script language="JavaScript">
  12. <!--
  13. function isValid() {
  14. var isOK = false;
  15. if ((document.upload.name.value != '') && (document.upload.name.value.length > 1)) {
  16. isOK = true;
  17. }
  18. else {
  19. alert ('por favor, su nombre.')
  20. isOK = false;
  21. }
  22.  
  23. var fileName = document.upload.upfile.value.toLowerCase();
  24.  
  25. if((fileName.indexOf('.jpeg') != -1) ||
  26. (fileName.indexOf('.jpe') != -1) ||
  27. (fileName.indexOf('.jpg') != -1) ||
  28. (fileName.indexOf('.gif') != -1) ||
  29. (fileName.indexOf('.png') != -1) ) {
  30. isOK = true;
  31. }
  32. else {
  33. alert ('Unknown file type. Must be GIF, PNG or JPG/JPEG/JPE.');
  34. isOK = false;
  35. }
  36.  
  37. if(isOK) {
  38. showProgress();
  39. }
  40.  
  41. return isOK;
  42. }
  43.  
  44. function showProgress() {
  45. document.getElementById("progress").style.visibili ty = 'visible';
  46. document.getElementById("submit").disabled = true;
  47. }
  48.  
  49. function hideProgress() {
  50. document.getElementById("progress").style.visibili ty = 'hidden';
  51. document.getElementById("submit").disabled = false;
  52. }
  53. //-->
  54. </script>
  55. </head>
  56.  
  57. <body>
  58.  
  59. <? include('includes/header.php'); ?>
  60.  
  61.  
  62. <div id="main">
  63. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  64.  
  65. <?
  66.  
  67. if(isset($_FILES['upfile'])) {
  68.  
  69.     require_once('mysqlvalues.inc.php');
  70.     require_once('mysqlfunc.inc.php');
  71.    
  72.     $mimeType = $_FILES['archivo']['type'];
  73.     $type = substr($mimeType,6);
  74.     $typeFileAcept = array('jpeg','png','gif');
  75.     $error = false;
  76.  
  77.     if (in_array($type, $typeFileAcept)) {
  78.         $size = getimagesize($_FILES['archivo']['tmp_name'],$allInfo);
  79.  
  80.         if (count($allInfo) == 0) {
  81.             $error = true;
  82.         }
  83.     }else {
  84.         $error = true;
  85.     }
  86.    
  87.     if (!$error) {
  88.         open_conn();
  89.  
  90.         $Name=my_addslashes($_POST[name]);
  91.         $LinkText=my_addslashes($_POST[linktext]);
  92.         $LinkUrl = trim(preg_replace('/http:\/\//', '', $_POST[linkurl], 1));
  93.         if($LinkUrl != '') {$LinkUrl="http://$LinkUrl";}
  94.  
  95.         $res=mysql_query("INSERT INTO Models SET DateTime=NOW(), Name='$Name', Wins='0', Loses='0', Draws='0', Status='0', LinkText='$LinkText', LinkUrl='$LinkUrl'");
  96.  
  97.         $id=mysql_insert_id();
  98.         $extension=explode('.', $_FILES['upfile']['name']);
  99.         $imagename=str_replace(' ', '', "$id" . ".$extension[1]");
  100.  
  101.         if (move_uploaded_file($_FILES['upfile']['tmp_name'], "images/uploads/$imagename")) {
  102.  
  103.             chmod("images/uploads/$imagename", 0777);
  104.  
  105.             mysql_query("UPDATE Models SET Thumbnail='$imagename' WHERE ID='$id'");
  106.  
  107.             $message="<br><strong>Archivo Recibido!<br/></strong>Sera revisado y publicado en linea, por lo general dentro de 24 horas.<br/><br/><strong>Puede ver su publicacion en: <br/><a href=\"http://www.quiensevemejor.co.cc.com/stats.php?id=$id\">http://www.quiensevemejor.com/stats.php?id=$id</a> <font color='red'>(guarda este link)</font></strong><br/><br/><br/>";
  108.  
  109.         }else{
  110.             mysql_query("DELETE FROM Models WHERE ID='$id'"); $message="<strong>Error recibiendo el archivo.</strong><br/><br/><br/>";
  111.         }
  112.        
  113.         close_conn();
  114.     }else {
  115.         echo 'El archivo subido no es una imagen!';
  116.     }
  117.  
  118.     echo"<tr>
  119.    <td width=\"150\" id=\"results\">
  120.    &nbsp;
  121.    </td>
  122.    <td width=\"550\" id=\"vote\" align=\"left\">
  123.    <p>
  124.  
  125.    $message
  126.    <br/>
  127.    <p><a href=\"upload.php\">Upload another picture</a>.</p>
  128.    </p>
  129.    <p align=\"center\"><a href=\"index.php\"><u>Siniciar una nueva votacion!</u></a></p>
  130.    </td>
  131.  
  132.    <td width=\"150\" id=\"sponsor\">";
  133.  
  134.     include('includes/rightbanners.php');
  135.  
  136.     echo"<p align=\"center\">
  137.    &nbsp;
  138.    </p>
  139.    </td>
  140.    </tr>";
  141.  
  142. }else{
  143.  
  144.     echo"<tr>
  145.    <td width=\"150\" id=\"results\">
  146.    &nbsp;
  147.    </td>
  148.    <td width=\"550\" id=\"vote\" align=\"left\">
  149.    <p>
  150.  
  151.    <form action=\"upload.php\" onSubmit=\"return isValid()\" method=\"post\" name=\"upload\" enctype=\"multipart/form-data\">
  152.    <br/>
  153.    <strong>Submit your model for battle!</strong>
  154.    <ul>
  155.    <li>Nosotros evaluaremos su imagen antes de que sea visible en linea.</li>
  156.    <li>Las imagenes deben ser de al menos 250x250 pixeles (se recortaran a esta dimension).</li>
  157.    <li>Por favor, no incluir a criaturas menores de 12.</li>
  158.    <li>Imagenes necesita ser girada a la orientacion correcta.</li>
  159.    <li>El tema sera el texto que aparece debajo de la foto</li>
  160.    <li>El Link del tema es el Link donde se llevara cuando den click al texto (Tema)</li>
  161.    <li>.jpg .gif o .png <strong><em>SOLO</em></strong> esos formatos, por favor.</li>
  162.  
  163.    </ul>
  164.    <p>
  165.    <br/><label><strong>Tu Nombre:</strong>&nbsp;</label><input type=\"text\" name=\"name\" id=\"name\" maxlength=\"20\"/> <em>Obligatorio</em>
  166.    <br/><label><strong>Tema:</strong>&nbsp;</label><input type=\"text\" name=\"linktext\" id=\"lintext\"/>
  167.    <br/><label><strong>Link del tema:</strong>&nbsp;</label><input type=\"text\" name=\"linkurl\" id=\"linkurl\"/>
  168.    <br/><label><strong>Archivo:</strong>&nbsp;</label><input type=\"file\" name=\"upfile\" id=\"upfile\" />
  169.    <br/><label>&nbsp;</label><input type=\"submit\" id=\"submit\" name=\"submit\" value=\"Subir Foto\"/>&nbsp;<span id=\"progress\"><img src=\"images/busy_blue.gif\"/>&nbsp;<strong>Subiendo archivo...</strong></span>
  170.    <script language=\"JavaScript\">
  171.    hideProgress();
  172.    </script>
  173.  
  174.    </p>
  175.    </form>
  176.    <p><strong>Aviso:</strong> Al enviar material a este sitio, usted acepta los terminos de nuestra <a href=\"legal.php\">privacidad y politicas</a>.</p>
  177.    </p>
  178.    <p align=\"center\"><a href=\"index.php\"><u>Empezar una nueva votacion!</u></a></p>
  179.    </td>
  180.  
  181.    <td width=\"150\" id=\"sponsor\">";
  182.  
  183.     include('includes/rightbanners.php');
  184.  
  185.     echo"<p align=\"center\">
  186.    &nbsp;
  187.    </p>
  188.    </td>
  189. </tr>";
  190. }
  191.  
  192. ?>
  193.  
  194. </table>
  195. </div>
  196.  
  197. <? include('includes/footer.php'); ?>
  198.  
  199. </div>
  200. </body>
  201. </html>
__________________
Listo?, tendría que tener 60 puntos menos de IQ para considerarme listo!!!
-- Sheldon Cooper
http://twitter.com/nemutagk
PD: No contestaré temas vía mensaje personal =)