Dinámico lugar de redirigir...¿es esto suficiente seguro?

  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Noviembre 12th, 2010, 4:24 pm

Estoy haciendo un reportaje sobre mi página de inicio de sesión que si su es una variable denominada la página que redirecciona a la página después de la tala pulg

PHP Código: [ Select ]
<?php
// Default redirection page
$redirect = 'index.php';
       
// Checking if they came from another page
if(isset($_GET['page']) && !strpos('.', $_GET['page']) && !strpos('/', $_GET['page']) && file_exists($_GET['page']))
{
    $redirect = $_GET['page'];
}
 
// Sending the user to the main page
header("LOCATION: {$redirect}");
?>
  1. <?php
  2. // Default redirection page
  3. $redirect = 'index.php';
  4.        
  5. // Checking if they came from another page
  6. if(isset($_GET['page']) && !strpos('.', $_GET['page']) && !strpos('/', $_GET['page']) && file_exists($_GET['page']))
  7. {
  8.     $redirect = $_GET['page'];
  9. }
  10.  
  11. // Sending the user to the main page
  12. header("LOCATION: {$redirect}");
  13. ?>

Hasta el momento tengo que...¿es lo suficientemente seguro?

La razón que estoy haciendo esto es que si el usuario hace clic entrada que redirecciona a la página vinieron después de entrar en lo que no perderá su posición. Creo que funcionará muy bien.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Noviembre 12th, 2010, 4:24 pm

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de Usuario
  • Registrado: May 22, 2004
  • Mensajes: 3415
  • Loc: Richland, WA
  • Status: Offline

Nota Noviembre 12th, 2010, 6:09 pm

No veo por qué wouldnt ser seguro. Es sólo una redirección, que Arnt incluirlo en su página, así que no veo cómo alguien podría explotar.


No creo que esto funcionará si usted tiene cualquier tipo de cadena de consulta en el archivo sin embargo.
#define NULL (::rand() % 2)
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Noviembre 12th, 2010, 9:12 pm

SpooF escribió:
No veo por qué wouldnt ser seguro. Es sólo una redirección, que Arnt incluirlo en su página, así que no veo cómo alguien podría explotar.

Muy bien, gracias
SpooF escribió:
No creo que esto funcionará si usted tiene cualquier tipo de cadena de consulta en el archivo sin embargo.

¿Qué quieres decir? Lo que quiere decir que es correcto lol...Me parece que no puede conseguir que redirigir al lugar $ _GET ["pagina"] se dice que
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Registrado: Feb 10, 2004
  • Mensajes: 13455
  • Loc: Florida
  • Status: Offline

Nota Noviembre 12th, 2010, 9:16 pm

Probablemente se podría hacer sin comprobar el punto, y el uso de "! Empty ()" en lugar de "isset ()" va a salvar el sistema de la necesidad de proceder en un caso en que la página está establecido, pero no contiene un valor, pero parece seguro.

La única manera que puedo pensar que esta podría estar con bypass, es si los theres una cierta clase de caracteres multi-byte que el sistema operativo se interpretan como y convertir automáticamente a los separadores de la guía, puntos o algo por el estilo. Si eso fuera posible, supongo que una página de phishing podrían ser de configuración que redirige al usuario a un sitio externo con su redireccionamiento.

Básicamente instalación alguien un enlace a su página de inicio para insertar esta URL con formato incorrecto que apunta a su propio sitio web. Un usuario puede simplemente mirar en el primer nombre de dominio que ver en este enlace de conexión, lo que sería su dominio y no es motivo de preocupación. Mientras tanto, este vínculo con formato incorrecto que redirigir al usuario a un sitio web diferente que se ve exactamente como la página web de inicio de sesión, pero con un mensaje de error en la línea de "contraseña incorrecta, por favor asegúrese de que usted no tiene el BLOQ MAYÚS y vuelva a intentarlo", que desde que acaba de llegar desde la página de inicio de sesión, podría aliviar las sospechas anyones y hacerlos entrar en su nombre de usuario y una contraseña en este sitio de phishing. Después de recoger la contraseña del sitio de phishing puede redirigir al visitante a su sitio y la página que pensaron que iban en el primer lugar y nunca se dan cuenta lo que pasó hasta que fue demasiado tarde.

En realidad, cuando estaba escribiendo esto, separadores urlencoded directamente vino a la mente. Sin embargo, dado que tu tienes un file_exists () en que, toda esta idea es más o menos válido. Mientras los archivos críticos como tal vez un "config. php "están protegidos de ser vistos por los navegadores para empezar, no importa si se puede redirigir a los mismos. Además, sería más fácil sólo tienes que escribir la dirección en la barra de direcciones del navegador en ese caso.
Strong with this one, the sudo is.
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Noviembre 12th, 2010, 9:25 pm

Muy bien, tengo el siguiente (Gracias por la HeadsUp en el "isset ()" y el punto...Tomé el código de otro lugar en mi sitio que les obliga).

De todos modos...lo que tengo es la siguiente:

PHP Código: [ Select ]
<?php
// Default redirection page
$redirect = 'index.php';
       
// Checking if they came from another page
if(!empty($_GET['page']) && !strpos('/', $_GET['page']) && file_exists($_GET['page']))
{
    $redirect = $_GET['page'];
}
 
// Sending the user to the main page
header("LOCATION: {$redirect}");
?>
  1. <?php
  2. // Default redirection page
  3. $redirect = 'index.php';
  4.        
  5. // Checking if they came from another page
  6. if(!empty($_GET['page']) && !strpos('/', $_GET['page']) && file_exists($_GET['page']))
  7. {
  8.     $redirect = $_GET['page'];
  9. }
  10.  
  11. // Sending the user to the main page
  12. header("LOCATION: {$redirect}");
  13. ?>

Y eso no redirige el usuario a cualquier página especificada por "$ _GET [" pagina "]" como debería...Simplemente va a "index.php".

El encabezado de redirigir se coloca delante de cualquiera de los HTML se analiza.

[EDIT] También he intentado lo siguiente...

PHP Código: [ Select ]
<?php
        // Checking if they came from another page
        if(!empty($_GET['page']))
        {
            $redirect = $_GET['page'];
        }
        else
        {
            $redirect = 'index.php';
        }
        echo $redirect;
        // Sending the user to the main page
        //header("LOCATION: {$redirect}");
?>
  1. <?php
  2.         // Checking if they came from another page
  3.         if(!empty($_GET['page']))
  4.         {
  5.             $redirect = $_GET['page'];
  6.         }
  7.         else
  8.         {
  9.             $redirect = 'index.php';
  10.         }
  11.         echo $redirect;
  12.         // Sending the user to the main page
  13.         //header("LOCATION: {$redirect}");
  14. ?>

Y eso no funciona así...su siempre index.php no importa lo que
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Registrado: Feb 10, 2004
  • Mensajes: 13455
  • Loc: Florida
  • Status: Offline

Nota Noviembre 13th, 2010, 12:33 am

¿Ha sido agregar manualmente? Página =*** a la URL cuando se prueba, o ha estado utilizando el formulario de acceso?

Si usted ha estado utilizando el formulario de entrada, asegúrese de que sus incluyendo la variable de la página.
Strong with this one, the sudo is.
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Noviembre 13th, 2010, 12:41 am

joebert escribió:
¿Ha sido agregar manualmente? Página =*** a la URL cuando se prueba, o ha estado utilizando el formulario de acceso?

Si usted ha estado utilizando el formulario de entrada, asegúrese de que sus incluyendo la variable de la página.

Ive que agregar manualmente? Página =*** a la dirección, pulse Intro, a continuación, inicio de sesión y redirecciona al índice. php no importa lo que he puesto como el valor a la página...No tengo idea de qué se está encendiendo...

[EDIT] He intentado lo siguiente...

PHP Código: [ Select ]
<?php
$redirect = $_GET['page'];
 
// Sending the user to the main page
header("LOCATION: {$redirect}");
?>
  1. <?php
  2. $redirect = $_GET['page'];
  3.  
  4. // Sending the user to the main page
  5. header("LOCATION: {$redirect}");
  6. ?>


Y me sale el siguiente error

Quote:
Notice: Undefined index: página en / var / www / proyectos / CMS / login.php en la línea 96


La URL se parece a...

Quote:
http://localhost/Projects/CMS/login.php?page=test. php


No está seguro de qué hacer aquí...

[EDITAR #2] No está seguro de qué hacer o qué buscar...aquí es todo el archivo...tal vez usted podría notar algo que no puedo...

PHP Código: [ Select ]
<?php
 
/*
 * login.php
 *
 *
 */
 
// Security first
define('IN_CMS', true);
 
// Including the global file... without it, we don't have the system.
require_once('includes/init.php');
 
// Checking if the user is already logged in
if($sess->logged() != false)
{
    header("LOCATION: index.php");
}
 
// Defining the variables for the header
$tpl->title = "Log In to {$tpl->header}";
$tpl->description = "Log In to {$tpl->header} to be able to see and use all the member's only items.";
 
// Setting the error session (if required)
if(!isset($_SESSION['login_trials']))
{
    $_SESSION['login_trials'] = 0;
}
 
// Checking if the user has reached the error limit of failed login attempts
if($_SESSION['login_trials'] >= 4)
{
    $tpl->securityCode = true;
}
 
// Doing the page processing
if(isset($_POST['Submit']))
{
    // Initiating the error array
    $error = array();
 
    // Checking the username
    if($_POST['username'] == '' OR strlen($_POST['username']) > 20)
    {
        $error[] = "You need to put in a valid username that is under 20 characters.";
    }
    else
    {   // checking if the username exists
        $sql = $db->build_key_query(array('SELECT'  => 'username',
                                          'FROM'    => USER_TABLE,
                                          'WHERE'   => array("username" => $_POST['username'],
                                                             "password" => md5($_POST['password']))));
       
        // Counting if we have a username by the submitted username
        if($db->num_rows($sql) == 0)
        {
            $error[] = "The username / password combination was incorrect. Please try again.";
           
            // Making sure that the user doesn't attempt more then the defined times
            $_SESSION['login_trials'] += 1;
        }
    }
   
    // Checking the Password
    if($_POST['password'] == '' OR strlen($_POST['password']) > 20)
    {
        $error[] = "You need to put in a valid password that is under 20 characters.";
    }
   
    // Checking if the user has reached the error limit of failed login attempts
    if($_SESSION['login_trials'] > 5)
    {
        // Checking the CAPTCHA / Security Code
        if(strtolower($_SESSION['qwerty']) != strtolower($_POST['qwerty']))
        {
            $error[] = "You need to type in the Correct Security code. It is not case sensitive.";
        }
    }
   
    // Checking for any errors in the submittion
    if(count($error) > 0)
    {
        $tpl->formErrors = $error;
    }
    else
    {
        // Removing the failed login trials session entry
        unset($_SESSION['login_trials']);
       
        // We are logging the user in here since everything checked out
        $_SESSION['u_logged_in'] = $db->_get_('userID', USER_TABLE, array("username" => $_POST['username'],
                                                                          "password" => md5($_POST['password'])));
       
        $redirect = $_GET['page'];
 
        // Sending the user to the main page
        header("LOCATION: {$redirect}");
    }
}
 
// Setting the required template variables to display
$tpl->loginFormMethod = 'post';
$tpl->loginFormAction = 'login.php';
 
// Displaying the page here
$tpl->display('header', 'login', 'footer');
?>
  1. <?php
  2.  
  3. /*
  4.  * login.php
  5.  *
  6.  *
  7.  */
  8.  
  9. // Security first
  10. define('IN_CMS', true);
  11.  
  12. // Including the global file... without it, we don't have the system.
  13. require_once('includes/init.php');
  14.  
  15. // Checking if the user is already logged in
  16. if($sess->logged() != false)
  17. {
  18.     header("LOCATION: index.php");
  19. }
  20.  
  21. // Defining the variables for the header
  22. $tpl->title = "Log In to {$tpl->header}";
  23. $tpl->description = "Log In to {$tpl->header} to be able to see and use all the member's only items.";
  24.  
  25. // Setting the error session (if required)
  26. if(!isset($_SESSION['login_trials']))
  27. {
  28.     $_SESSION['login_trials'] = 0;
  29. }
  30.  
  31. // Checking if the user has reached the error limit of failed login attempts
  32. if($_SESSION['login_trials'] >= 4)
  33. {
  34.     $tpl->securityCode = true;
  35. }
  36.  
  37. // Doing the page processing
  38. if(isset($_POST['Submit']))
  39. {
  40.     // Initiating the error array
  41.     $error = array();
  42.  
  43.     // Checking the username
  44.     if($_POST['username'] == '' OR strlen($_POST['username']) > 20)
  45.     {
  46.         $error[] = "You need to put in a valid username that is under 20 characters.";
  47.     }
  48.     else
  49.     {   // checking if the username exists
  50.         $sql = $db->build_key_query(array('SELECT'  => 'username',
  51.                                           'FROM'    => USER_TABLE,
  52.                                           'WHERE'   => array("username" => $_POST['username'],
  53.                                                              "password" => md5($_POST['password']))));
  54.        
  55.         // Counting if we have a username by the submitted username
  56.         if($db->num_rows($sql) == 0)
  57.         {
  58.             $error[] = "The username / password combination was incorrect. Please try again.";
  59.            
  60.             // Making sure that the user doesn't attempt more then the defined times
  61.             $_SESSION['login_trials'] += 1;
  62.         }
  63.     }
  64.    
  65.     // Checking the Password
  66.     if($_POST['password'] == '' OR strlen($_POST['password']) > 20)
  67.     {
  68.         $error[] = "You need to put in a valid password that is under 20 characters.";
  69.     }
  70.    
  71.     // Checking if the user has reached the error limit of failed login attempts
  72.     if($_SESSION['login_trials'] > 5)
  73.     {
  74.         // Checking the CAPTCHA / Security Code
  75.         if(strtolower($_SESSION['qwerty']) != strtolower($_POST['qwerty']))
  76.         {
  77.             $error[] = "You need to type in the Correct Security code. It is not case sensitive.";
  78.         }
  79.     }
  80.    
  81.     // Checking for any errors in the submittion
  82.     if(count($error) > 0)
  83.     {
  84.         $tpl->formErrors = $error;
  85.     }
  86.     else
  87.     {
  88.         // Removing the failed login trials session entry
  89.         unset($_SESSION['login_trials']);
  90.        
  91.         // We are logging the user in here since everything checked out
  92.         $_SESSION['u_logged_in'] = $db->_get_('userID', USER_TABLE, array("username" => $_POST['username'],
  93.                                                                           "password" => md5($_POST['password'])));
  94.        
  95.         $redirect = $_GET['page'];
  96.  
  97.         // Sending the user to the main page
  98.         header("LOCATION: {$redirect}");
  99.     }
  100. }
  101.  
  102. // Setting the required template variables to display
  103. $tpl->loginFormMethod = 'post';
  104. $tpl->loginFormAction = 'login.php';
  105.  
  106. // Displaying the page here
  107. $tpl->display('header', 'login', 'footer');
  108. ?>
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de Usuario
  • Registrado: May 22, 2004
  • Mensajes: 3415
  • Loc: Richland, WA
  • Status: Offline

Nota Noviembre 13th, 2010, 12:55 am

Este error hace que suene como no hay ningún índice "página" en la variable $ _GET.
#define NULL (::rand() % 2)
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Noviembre 13th, 2010, 1:06 am

Sí...No tengo ni idea de por qué, aunque como soy lo que pasa a través de la dirección...¿por qué sería una tontería hacer eso?

Pongo echo $ redirigir, en la línea 96 y no echo nada...pero si pongo echo $ _GET ["pagina"]; en la línea 20 se hace eco de test.php...lo que el?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Noviembre 13th, 2010, 1:13 am

No importa, mi cerebro simples vecinos que no importa lo que he puesto en la dirección, la acción de formulario no tiene que :(

:lol: De todos modos...Lo tengo fijo.

Mi otro problema...$ _SERVER ["PHP_SELF"] devuelve / ruta / al / archivo. php y estoy tratando de mantenerla segura al no permitir que los guiones...

¿Debo permitir que los guiones o debo usar expresiones regulares para recibir sólo el "archivo.php" parte? Si tengo que usar expresiones regulares theres otro problema...No sé expresiones regulares...
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Registrado: Feb 10, 2004
  • Mensajes: 13455
  • Loc: Florida
  • Status: Offline

Nota Noviembre 13th, 2010, 1:40 am

No usar $ _SERVER ["PHP_SELF"], usar $ _SERVER ["SCRIPT_FILENAME"] en su lugar. SCRIPT_FILENAME nunca contendrá PATH_INFO (es decir, "/ index.php / path-info") y también tiene en cuenta los enlaces simbólicos en el servidor, mientras que la constante __FILE__ no.

Usar basename () para recuperar el "archivo.php" parte de SCRIPT_FILENAME y dirname () para obtener el directorio de trabajo.
Strong with this one, the sudo is.
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Noviembre 14th, 2010, 1:29 pm

Ah ok, gracias por el heads-up. Que funciona a la perfección :)
"Bring forth therefore fruits meet for repentance:" Matthew 3:8

Publicar Información

  • Total de mensajes en este tema: 12 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 239 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC