Foros del Web » Programando para Internet » PHP »

seguridad contra inyeccion SQL

Estas en el tema de seguridad contra inyeccion SQL en el foro de PHP en Foros del Web. una funcion contra la inyeccion sql: Código PHP:   if (! function_exists ( "GetSQLValueString" )) { function  GetSQLValueString ( $theValue ,  $theType ,  $theDefinedValue  =  "" ,  ...
  #1 (permalink)  
Antiguo 06/03/2008, 05:15
Avatar de farra  
Fecha de Ingreso: marzo-2008
Ubicación: Aqui estoy
Mensajes: 574
Antigüedad: 16 años, 1 mes
Puntos: 20
Exclamación seguridad contra inyeccion SQL

una funcion contra la inyeccion sql:

Código PHP:
 if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
    case 
"like1":
      
$theValue = ($theValue != "") ? "'%" $theValue "%'" "NULL";
      break;
    case 
"like2":
      
$theValue = ($theValue != "") ? "'" $theValue "%'" "NULL";
      break;
    case 
"like3":
      
$theValue = ($theValue != "") ? "'%" $theValue "'" "NULL";
      break;
  }
  return 
$theValue;
}

quisiera saber si es 100% segura?
  #2 (permalink)  
Antiguo 06/03/2008, 09:07
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Re: seguridad contra inyeccion SQL

Esa función (autogenerada por DW), es segura, pero no te deberías de fiar, todavía podrían usar ataques XSS para insertar JavaScript o algún otro contenido a tu pagina.

Saludos.
  #3 (permalink)  
Antiguo 06/03/2008, 12:06
Avatar de farra  
Fecha de Ingreso: marzo-2008
Ubicación: Aqui estoy
Mensajes: 574
Antigüedad: 16 años, 1 mes
Puntos: 20
Pregunta Re: seguridad contra inyeccion SQL

Cita:
Iniciado por GatorV Ver Mensaje
Esa función (autogenerada por DW), es segura, pero no te deberías de fiar, todavía podrían usar ataques XSS para insertar JavaScript o algún otro contenido a tu pagina.

Saludos.

ya entiendo, me pueden poner en el post algo asi:
Código:
<script> document.location.href='http://paginamaliciosa.com/' </script>
y se inserta eso en la BD y cuando listen en la pagina los usuarios van a ser direccionados..

le modifique ahora el codigo y le puse 'htmlentities'

Código PHP:

if (!function_exists("GetSQLValueString")) { 
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")  

  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

  switch (
$theType) { 
    case 
"text"
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL"
      break; 
    case 
"int"
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL"
      break; 
    case 
"double"
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL"
      break; 
    case 
"date"
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL"
      break; 
    case 
"defined"
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue
      break; 
    case 
"like1"
      
$theValue = ($theValue != "") ? "'%" $theValue "%'" "NULL"
      break; 
    case 
"like2"
      
$theValue = ($theValue != "") ? "'" $theValue "%'" "NULL"
      break; 
    case 
"like3"
      
$theValue = ($theValue != "") ? "'%" $theValue "'" "NULL"
      break; 
  } 

$theValue=htmlentities($theValue);  // agregado
 
 
return $theValue;

con el htmlentities cuando listen se va a ver asi en el codigo fuente html:
&lt;script&gt; document.location.href='http://paginamaliciosa.com/' &lt;/script&gt;
pero el usuario va a ver esto en su navegador:
<script> document.location.href='http://paginamaliciosa.com/' </script>
sin que se ejecute...

y ahora esta 100% segura o que otra vulnerabilidad detectas?
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 07:13.