Ver Mensaje Individual
  #9 (permalink)  
Antiguo 02/03/2011, 22:04
Avatar de s00rk
s00rk
 
Fecha de Ingreso: octubre-2010
Ubicación: Mexico
Mensajes: 238
Antigüedad: 13 años, 6 meses
Puntos: 48
Respuesta: Inyección XSS, Seguridad PHP, Eval, y otras funciones ayuda!!

Has algo tan sencillo como esto

con una simple funcion, yo asi lo hago y nunca he obtenido alguna injeccion

Código PHP:
Ver original
  1. <?
  2.        function clean($value)
  3.        {
  4.             $check = $value;
  5.             $value = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$value);
  6.             $value = trim($value);
  7.             $value = strip_tags($value);
  8.             $value = addslashes($value);
  9.             $value = str_replace("'", "''", $value);
  10.  
  11.             if( $check != $value )
  12.             {
  13.                 $logf = fopen("logs/injection.txt", "a+");
  14.                 fprintf($logf, "Fecha: %s IP: %s Valor: %s, Corregido: %s\r\n", date("d-m-Y h:i:s A"), $_SERVER['REMOTE_ADDR'], $check, $value );
  15.                 fclose($logf);
  16.                 alertbox("Que intentas hacer? (: , Mejor mira esto xD", "http://www.google.com/");
  17.             }
  18.  
  19.             return( $value );
  20. }
  21.  
  22. if(!function_exists("alertbox")){
  23. function alertbox($text, $url)
  24. {
  25.     echo "<body  bgcolor='#000000'><script>alert('$text');document.location = '$url'</script></body>";
  26.     die("Javascript disabled");
  27. } }
  28.  
  29. ?>

Y ya solamente lo utilizamos en tu for, con uno solo bastaria y no tendrias que usarlo dos veces

Código PHP:
Ver original
  1. #
  2. foreach( $_POST as $data => $valor ){
  3.        $_POST [ $data ] = clean($_POST[$data]);
  4.        }

Espero te sirva n_n