Ver Mensaje Individual
  #6 (permalink)  
Antiguo 23/08/2010, 21:28
martinferra
 
Fecha de Ingreso: agosto-2010
Mensajes: 7
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta 1/2: Formulario atacado por Spammer en sitio alojado en Dattatec

Buenas nuevamente,

El formulario lo descargué del sitio quinti(punto)net.
Esta compuesto por: contacto.php, gracias.php, cimg (una carpeta con 191 captchas en gif) y js (una carpeta con 2 archivos JavaScript).

Contacto.php

Código PHP:
Ver original
  1. <?
  2. if(!isset($_SERVER['HTTP_USER_AGENT'])){
  3.    die("Forbidden - You are not authorized to view this page");
  4.    exit;
  5. }
  6. if(!$_SERVER['REQUEST_METHOD'] == "POST"){
  7.    die("Forbidden - You are not authorized to view this page");
  8.    exit;    
  9. }
  10. $httprefe = getenv ("HTTP_REFERER");
  11. $httpagente = getenv ("HTTP_USER_AGENT");
  12. $datee = date("d/m/Y H:i:s");
  13. ?>
  14. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  15.  
  16. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  17. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" >
  18. <head>
  19. <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
  20. <meta name="keywords" content="formulario web contacto seguro" />
  21. <meta name="description" content="Formulario web de contacto seguro antispam con captcha de Quinti.net" />
  22. <title>Quinti.net - Formulario web seguro anti spam con captcha</title>
  23. <?
  24.     $antispam= 'http://www.quinti.net';
  25.     $antispamt= 'Quinti.net secure form script';
  26.     $antispam2= 'http://www.maismedia.com';
  27.     $antispamt2= 'MaisMedia Optimizacion Web';
  28.     echo "<script type=\"text/javascript\">\n";
  29.     echo "<!--\n";
  30.     echo "function validar(form1) {\n";
  31.     echo "if (form1.name.value.length < 2) {\n";
  32.     echo "alert('";
  33.     echo "Inserte el nombre";;
  34.     echo "')\n";
  35. echo "form1.name.focus();\n";
  36.   echo "return (false);}\n";
  37. echo "var checkOK = \"ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ \" + \"abcdefghijklmnñopqrstuvwxyzáéíóú\";\n";
  38.   echo "var checkStr = form1.name.value;\n";
  39.   echo "var allValid = true;\n";
  40.   echo "var uword = hex_md5(document.getElementById('uword').value)\n";
  41.   echo "for (i = 0; i < checkStr.length; i++) {";
  42.   echo "ch = checkStr.charAt(i);\n";
  43.   echo "for (j = 0; j < checkOK.length; j++)\n";
  44.   echo "if (ch == checkOK.charAt(j))\n";
  45.   echo "break;\n";
  46.   echo "if (j == checkOK.length) {\n";
  47.   echo "allValid = false;\n";
  48.   echo "break;";
  49.   echo "}}\n";
  50.   echo "if (!allValid) {\n";
  51.   echo "alert('";
  52.   echo "inserte el nombre";
  53.   echo "');\n";
  54.   echo "form1.name.focus();\n";
  55.   echo "return (false);}\n";
  56. echo "if ((form1.email.value.indexOf ('@', 0) == -1)||(form1.email.value.length < 9) ||
  57.  
  58. form1.email.value.indexOf ('.', 0)== -1 ){\n";
  59.   echo "alert('";
  60.   echo "inserte el email";
  61.   echo "');\n";
  62.   echo "form1.email.focus();";
  63.   echo "return (false);}\n";
  64. echo "if (form1.message.value.length < 7) {\n";
  65.   echo "alert('";
  66.   echo "inserte el mensaje";
  67.   echo "');\n";
  68.   echo "form1.message.focus();";
  69.   echo "return (false);}\n";
  70.  
  71. echo "if (uword==cword[anum-1]) {\n";
  72.   echo "return true;}\n";
  73.   echo "else {\n";
  74.   echo "alert('";
  75.   echo "inserte el código de la imagen";
  76.   echo "');\n";
  77.   echo "document.getElementById('uword').focus();\n";
  78.   echo "return false;}\n";
  79.   echo "return (true);}\n";
  80.   echo "-->\n";
  81.   echo "</script>\n";
  82.   ?>
  83. <script type="text/javascript" src="js/md5.js"></script>
  84. <script type="text/javascript" src="js/jcap.js"></script>
  85. <style type="text/css">
  86. <!--
  87. img {
  88.     border:0;
  89. }
  90. -->
  91. </style>
  92. </head>
  93. <body>
  94. <form method="post" onsubmit="return validar(this)" id="form1" action="gracias.php">
  95.   <p>
  96.     <input type="hidden" name="token" value="<?=$token?>" />
  97.   </p>
  98.   <p>
  99.     <input type="hidden" name="ip" value="<?=$_SERVER['REMOTE_ADDR']?>" />
  100.   </p>
  101.   <p>
  102.     <input type="hidden" name="httpref" value="<?=$httprefe?>" />
  103.   </p>
  104.   <p>
  105.     <input type="hidden" name="httpagent" value="<?=$httpagente?>" />
  106.   </p>
  107.   <p>
  108.     <input type="hidden" name="date" value="<?=$datee?>" />
  109.   </p>
  110.   <p>
  111.     <label for="name">Nombre:*</label>
  112.     <input name="name" id="name" type="text" value="" />
  113.   </p>
  114.   <p>
  115.     <label for="email">E-mail:*</label>
  116.     <input name="email" id="email" type="text" value="" />
  117.   </p>
  118.   <p>
  119.     <label for="phone">Asunto:</label>
  120.     <input name="phone" id="phone" type="text" value="" />
  121.   </p>
  122.   <p>
  123.     <label for="message">Mensaje:*</label>
  124.     <br />
  125.     <textarea id="message" name="message" cols="30" rows="5"></textarea>
  126.   </p>
  127.   <p>
  128.     <label for="uword">Inserte el código de la imagen siguiente* (para evitar el Spam)</label>
  129.   </p>
  130.   <p>
  131.     <input type="text" name="uword" id="uword" value="" />
  132.   </p>
  133.   <p>
  134.     <script type="text/javascript">cimg()</script>
  135.   </p>
  136.   <p>
  137.     <input type="submit" value="enviar"  />
  138.   </p>
  139. </form>
  140. <p>campos con * son obligatorios.
  141.   <!-- START COPYRIGHT IMPORTANT NOTE: these line can't be delete
  142.  2006, 2010 MaisMedia.com & Quinti.net solutions, Gran Vía 1, 4º C, Sarria, 27600 Lugo, Galicia, Spain.
  143. to remove the creator link, and/or for commercial use, the form costs (price is) 30E,
  144. Otherwise you cannot use this script and you was damaging Copyright's laws (C) 2006, 2010 MaisMedia.com & Quinti.net
  145. -->
  146.   <?php
  147. echo "<a href=\"$antispam\">$antispamt</a> &amp; <a href=\"$antispam2\">$antispamt2</a>";
  148. ?>
  149. </p>
  150. <!-- END COPYRIGHT IMPORTANT NOTE, DON'T REMOVE PLEASE -->
  151. <p> <a href="http://validator.w3.org/check?uri=referer"><img
  152.         src="http://www.w3.org/Icons/valid-xhtml11"
  153.         alt="Valid XHTML 1.1" height="31" width="88" /></a> </p>
  154. </body>
  155. </html>


gracias.php

Código PHP:
Ver original
  1. <?
  2.     $youremail = "[email protected]"; //YOUR MAIL HERE
  3.     $subject = "el título del tema "; // TITLE OF DE SUBJECT IN MAIL
  4.     $redirect = "contacto.php";//URL TO BE REDIRECTED IN 5 SECONDS
  5.     $secs = "10";// TIME TO BE REDIRECTED
  6.  
  7. if(eregi("MIME-Version:",$postVars)) {
  8. mail("[email protected]"/*YOUR MAIL HERE*/, "Form Hijack Attempt", "A spam relay was attempted from the Web site and was blocked.", "From:SpamMonitor");
  9. die();
  10. } //BLOCKING spam
  11.  
  12.  
  13.  $secret = 'ssshhitsasecret';  
  14.     $token = md5(rand(1, 1000).$secret);
  15.     $_SESSION['token'] = $token;
  16.     ?>
  17. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  18. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  19. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" >
  20. <head>
  21. <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
  22. <title>ejemplo de procesador de formulario web seguro antispam con captcha quinti.net</title>  
  23. <meta http-equiv="refresh" content="<?=$secs;?>;URL=<?=$redirect;?>" />
  24.  </head>
  25.         <body>
  26. <?
  27.   //a partir de aquí hay una serie de variables que impiden que los spammers usen nuestro formulario como lanzadera de su spam
  28.   $name = stripslashes($name);
  29.   $message = stripslashes($message);
  30.   $headers .= "From: " . $email . "\r\n\r\n";
  31.     //This is where the email is sent using your values from above. Be sure to update this if you change any fields in contact.php
  32.     mail("$youremail", "$subject","
  33.    Name: $name
  34.    Email: $email
  35.    Subject: $phone
  36.    Message: $message
  37.    IP: $ip
  38.    Browser Info: $httpagent
  39.    Referral : $httpref
  40.    Date : $date
  41. ",$headers);
  42.    // Strip \r and \n from the email address
  43.    $_POST['email'] = str_replace("\r", "", $_POST['email']);
  44.    $_POST['email'] = str_replace("\n", "", $_POST['email']);
  45.  
  46. //*****COMMENT: if you have problems with the lines 40/41, replace these for:
  47. //$_POST['email'] = str_replace("\r", "", $_POST['email']);
  48. //$_POST['email'] = str_replace("\n", "", $_POST['email']);//*****
  49.  
  50. //MARTINFERRA dice: EN MI CASO LAS TUVE QUE CAMBIAR, LAS ORIGINALES ERAN:
  51. //$_POST['email'] = preg_replace("\r", "", $_POST['email']);
  52. //$_POST['email'] = preg_replace("\n", "", $_POST['email']);//*****
  53. //...Y DABAN UN PROBLEMA EN LAS LINEAS 40/41
  54.  
  55.    $_SESSION['token'] = $token;
  56.    $token = md5(rand(1, 1000).$secret);
  57.    $secret = 'ssshhitsasecret';
  58.    $field = preg_replace( "/[\n\r]+/", " ", $field );
  59.     // Remove injected headers
  60.     $find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i");
  61.     $_POST['email'] = preg_replace($find, "", $_POST['email']);
  62.     $message = preg_replace($find, "", message);
  63.     $email=str_replace("\r","\n",$email);
  64.     $name=str_replace("\r","\n",$name);
  65.     $message=str_replace("\r","\n",$message);
  66.     $phone=str_replace("\r","\n",$phone);
  67.    
  68.    
  69. if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
  70. mail("$youremail", "Message Killed", "$message", "From: $name <$email>");
  71. exit("Message killed.");
  72. }
  73.  if (eregi('^(bcc$|content-type|mime-version|--)',$key))
  74. print_error("Field names indicate exploit.");  //BLOCKING SPAM
  75.  
  76. ?>
  77.  <p>Gracias, el formulario se ha enviado con éxito, le contestaremos en menos de 24 h. En 5 segundos será redirigido a la página principal.</p>
  78.  
  79.  
  80.         </body>
  81.         </html>


Probando el formulario con estos 2 archivos, verifiqué que el Captcha funciona OK, porque salta el cartel de JavaScript si ingreso mal el texto de verificación.
Pero el problema es que sigue apareciendo el mensaje al presionar el botón "enviar" del formulario:
Warning: mail() [function.mail]: SMTP server response: 554 Su dominio ha excedido el limite de 200 mails por hora o está intentando enviar mail desde una cuenta no valida. in \\hmfsw\web\dtcwin079\misitio.com\public_html\Quin ti\gracias.php on line 42


...continúo la explicación en mi próxima respuesta