Ver Mensaje Individual
  #23 (permalink)  
Antiguo 27/02/2012, 18:29
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

o.O no se que estes haciendo amigo, la verdad ya me tienes desconsertado, tengo este código (que aunque esta comentado lo que no me sirve a mi) implementado y funciona, chechalo y verifica tu código y este y ve las diferencias, si sigue sin funcionarte la verdad es que no se que haces >.<

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. <div id="main">
  60. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  61.  
  62. <?
  63.  
  64. if(isset($_FILES['upfile'])) {
  65.  
  66. //    require_once('mysqlvalues.inc.php');
  67. //    require_once('mysqlfunc.inc.php');
  68.    
  69.     $mimeType = $_FILES['upfile']['type'];
  70.     $type = substr($mimeType,6);
  71.     $typeFileAcept = array('jpeg','png','gif');
  72.     $error = false;
  73.  
  74.     if (in_array($type, $typeFileAcept)) {
  75.         $size = getimagesize($_FILES['upfile']['tmp_name'],$allInfo);
  76.  
  77.         if (count($allInfo) == 0) {
  78.             $error = true;
  79.         }
  80.     }else {
  81.         $error = true;
  82.     }
  83.    
  84.     if (!$error) {
  85. //        open_conn();
  86. //
  87. //        $Name=my_addslashes($_POST[name]);
  88. //        $LinkText=my_addslashes($_POST[linktext]);
  89. //        $LinkUrl = trim(preg_replace('/http:\/\//', '', $_POST[linkurl], 1));
  90. //        if($LinkUrl != '') {$LinkUrl="http://$LinkUrl";}
  91. //
  92. //        $res=mysql_query("INSERT INTO Models SET DateTime=NOW(), Name='$Name', Wins='0', Loses='0', Draws='0', Status='0', LinkText='$LinkText', LinkUrl='$LinkUrl'");
  93. //
  94. //        $id=mysql_insert_id();
  95. //        $extension=explode('.', $_FILES['upfile']['name']);
  96. //        $imagename=str_replace(' ', '', "$id" . ".$extension[1]");
  97.  
  98. //        if (move_uploaded_file($_FILES['upfile']['tmp_name'], "images/uploads/$imagename")) {
  99.  
  100. //            chmod("images/uploads/$imagename", 0777);
  101. //
  102. //            mysql_query("UPDATE Models SET Thumbnail='$imagename' WHERE ID='$id'");
  103. //
  104.             $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/>";
  105.  
  106. //        }else{
  107. //            mysql_query("DELETE FROM Models WHERE ID='$id'");
  108. //            $message="<strong>Error recibiendo el archivo.</strong><br/><br/><br/>";
  109. //        }
  110.        
  111. //        close_conn();
  112.     }else {
  113.         echo 'El archivo subido no es una imagen!';
  114.     }
  115.  
  116.     echo"<tr>
  117.    <td width=\"150\" id=\"results\">
  118.    &nbsp;
  119.    </td>
  120.    <td width=\"550\" id=\"vote\" align=\"left\">
  121.    <p>
  122.  
  123.    $message
  124.    <br/>
  125.    <p><a href=\"upload.php\">Upload another picture</a>.</p>
  126.    </p>
  127.    <p align=\"center\"><a href=\"index.php\"><u>Siniciar una nueva votacion!</u></a></p>
  128.    </td>
  129.  
  130.    <td width=\"150\" id=\"sponsor\">";
  131.  
  132.     include('includes/rightbanners.php');
  133.  
  134.     echo"<p align=\"center\">
  135.    &nbsp;
  136.    </p>
  137.    </td>
  138.    </tr>";
  139.  
  140. }else{
  141.  
  142.     echo"<tr>
  143.    <td width=\"150\" id=\"results\">
  144.    &nbsp;
  145.    </td>
  146.    <td width=\"550\" id=\"vote\" align=\"left\">
  147.    <p>
  148.  
  149.    <form action=\"\" onSubmit=\"return isValid()\" method=\"post\" name=\"upload\" enctype=\"multipart/form-data\">
  150.    <br/>
  151.    <strong>Submit your model for battle!</strong>
  152.    <ul>
  153.    <li>Nosotros evaluaremos su imagen antes de que sea visible en linea.</li>
  154.    <li>Las imagenes deben ser de al menos 250x250 pixeles (se recortaran a esta dimension).</li>
  155.    <li>Por favor, no incluir a criaturas menores de 12.</li>
  156.    <li>Imagenes necesita ser girada a la orientacion correcta.</li>
  157.    <li>El tema sera el texto que aparece debajo de la foto</li>
  158.    <li>El Link del tema es el Link donde se llevara cuando den click al texto (Tema)</li>
  159.    <li>.jpg .gif o .png <strong><em>SOLO</em></strong> esos formatos, por favor.</li>
  160.  
  161.    </ul>
  162.    <p>
  163.    <br/><label><strong>Tu Nombre:</strong>&nbsp;</label><input type=\"text\" name=\"name\" id=\"name\" maxlength=\"20\"/> <em>Obligatorio</em>
  164.    <br/><label><strong>Tema:</strong>&nbsp;</label><input type=\"text\" name=\"linktext\" id=\"lintext\"/>
  165.    <br/><label><strong>Link del tema:</strong>&nbsp;</label><input type=\"text\" name=\"linkurl\" id=\"linkurl\"/>
  166.    <br/><label><strong>Archivo:</strong>&nbsp;</label><input type=\"file\" name=\"upfile\" id=\"upfile\" />
  167.    <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>
  168.    <script language=\"JavaScript\">
  169.    hideProgress();
  170.    </script>
  171.  
  172.    </p>
  173.    </form>
  174.    <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>
  175.    </p>
  176.    <p align=\"center\"><a href=\"index.php\"><u>Empezar una nueva votacion!</u></a></p>
  177.    </td>
  178.  
  179.    <td width=\"150\" id=\"sponsor\">";
  180.  
  181.     include('includes/rightbanners.php');
  182.  
  183.     echo"<p align=\"center\">
  184.    &nbsp;
  185.    </p>
  186.    </td>
  187. </tr>";
  188. }
  189.  
  190. ?>
  191.  
  192. </table>
  193. </div>
  194.  
  195. </div>
  196. </body>
  197. </html>

Nota:Se me olvidaba, con lo que dices sobre implementar otro upload, pues seria reescribir todo de nuevo, aunque podría funcionar mejor si TU sabes realmente lo que hace el código y no solo hacer copy/paste de uno que encuentres en internet
__________________
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 =)