|
Mostrar Temas
|
Páginas: [1] 2 3 4 5
|
1
|
Seguridad Informática / Nivel Web / Evitar cookie nula en php
|
en: 18 Octubre 2009, 04:42 am
|
Hola, me gustaría preguntar de qué manera se puede evitar una cookie nula. Por ejemplo, en un sitio existía un mecanismo de autenticación algo así (los nombres los he cambiado): /adm/control.php <?php session_start(); if ($_SESSION['auth'] != 'YES') { header('Location: index.php'); } echo 'Panel de admin'; ?>
/adm/index.php <?php echo 'No logeado'; ?>
y al acceder a /adm/control.php se va a index.php porque no está registrada la variable de sesión. Pero si modifico el contenido de la Cookie con tamper data así: PHPSESSID=
Se produce lo siguiente: Warning: session_start() [function.session-start]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in C:\sitio\adm\control.php on line 3
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\sitio\adm\control.php:3) in C:\sitio\adm\control.php on line 3
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\sitio\adm\control.php:3) in C:\sitio\adm\control.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at C:\sitio\adm\control.php:3) in C:\sitio\adm\control.php on line 5 Panel de admin
Entonces, mi pregunta es cómo evitar que session_start() se caiga ante un ataque así.
|
|
|
2
|
Programación / PHP / Ayuda con sistema de login
|
en: 13 Octubre 2009, 22:14 pm
|
Hola, estoy intentando desarrollar un sistema de login en php, al parecer todo funciona bien, pero lo que no me funciona es el sistema anti session hijacking. Quisiera saber si alguien me puede ayudar a encontrar el problema. Para probar el csrf, una vez logueado con tamper data trato de enviar logout pero eliminando el t= Entonces dice csrf attempt. Pero para probar session hijacking, no me funciona el tema del $fingerprint, una vez logueado, abro otra pestaña con firefox, y accedo a la url viendo el contenido exlusivo, si abro otra pestaña y accedo a la url, pero modificando el user agent, no se cae, diciendo session hijacking attempt, como que no cambia la cadena $fingerprint, y ese es el problema que tengo. Si alguien por favor también pudiera darme sugerencias para hacer un buen sistema de login, se lo agradecería también. //editado porque no estaba bueno. Abajo encuentran un código más decente.
|
|
|
3
|
Programación / PHP / Filtro SQL Injection y Filtro XSS
|
en: 13 Octubre 2009, 06:20 am
|
Aquí comparto dos funciones que hice para prevenir sql injection y xss. El código está en base64, una vez que lo decodifican, pueden guardarlo como Filtros.php y requerirlo en su script. PD9waHANCg0KIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjDQojIEZpbHRybyBw YXJhIGV2aXRhciBTUUwgSW5qZWN0aW9uICMNCiMgdmVyc2lvbjogMC4xICAgICAgICAgICAgICAg ICAgICAgIw0KIyBBdXRvcjogMHgwMzA5ICAgICAgICAgICAgICAgICAgICAjDQojIyMjIyMjIyMj IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMNCmZ1bmN0aW9uIGFudGlTUUxJbmplY3Rpb24oJHN0 cikNCnsNCiAgICBpZiAoaXNfc3RyaW5nKCRzdHIpKSB7DQogICAgICAgICAvL2VuIHBocCA2IG1h Z2ljIHF1b3RlcyB5YSBubyB2YW4NCiAgICAgICAgaWYgKGdldF9tYWdpY19xdW90ZXNfZ3BjKCkp IHsNCiAgICAgICAgICAgICRzdHIgPSBzdHJpcHNsYXNoZXMoJHN0cik7DQogICAgICAgIH0NCiAg ICAgICAgJHN0ciA9IG15c3FsX3JlYWxfZXNjYXBlX3N0cmluZygkc3RyKTsNCiAgICAgICAgJHN0 ciA9IGFkZGNzbGFzaGVzKCRzdHIsICclXycpOw0KICAgIH0NCiAgICByZXR1cm4gJHN0cjsNCn0N Cg0KIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw0KIyBGaWx0cm8g cGFyYSBldml0YXIgQ3Jvc3MtU2l0ZSBTY3JpcHRpbmcgIw0KIyB2ZXJzaW9uOiAwLjEgICAgICAg ICAgICAgICAgICAgICAgICAgICAgIw0KIyBBdXRvcjogMHgwMzA5ICAgICAgICAgICAgICAgICAg ICAgICAgICAgIw0KIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw0K ZnVuY3Rpb24gYW50aUNyb3NzU2l0ZVNjcmlwdGluZygkc3RyKQ0Kew0KICAgIGlmIChpc19zdHJp bmcoJHN0cikpIHsNCiAgICAgICAkc3RyID0gaHRtbGVudGl0aWVzKCRzdHIsIEVOVF9RVU9URVMs ICdVVEYtOCcpOw0KICAgIH0NCiAgICByZXR1cm4gJHN0cjsNCn0NCg0KPz4=
y pueden usarlo así: //Para consultas a base de datos: //Si el campo id de la base de datos es string : $id = antiSQLInjection( $_POST['id'] ); //Sino si el campo id de la base de datos es entero: $id = (int) $_POST['id'];
$query = "select nombre from usuario where id='{$id}'"; mysql_query($query);
//Para imprimir: echo antiCrossSiteScripting($_POST['texto']);
|
|
|
4
|
Programación / PHP / Pegar imagenes en php
|
en: 12 Octubre 2009, 22:04 pm
|
Hola, tengo un pequeño problema, estoy generando imagenes de niveles de sokoban dinámicamente. El problema es que para que en pantalla se muestre algo así:  Este es el código que genero con php: <img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><br/> <img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><br/> <img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/box.gif" width="16" height="16" /><img src="http://midominio/images/player.gif" width="16" height="16" /><img src="http://midominio/images/box.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><br/> <img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/box.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/box.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><br/> <img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/goal.gif" width="16" height="16" /><img src="http://midominio/images/goal.gif" width="16" height="16" /><img src="http://midominio/images/goal.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><br/> <img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/box.gif" width="16" height="16" /><img src="http://midominio/images/goal.gif" width="16" height="16" /><img src="http://midominio/images/goal_box.gif" width="16" height="16" /><img src="http://midominio/images/goal.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><br/> <img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/goal.gif" width="16" height="16" /><img src="http://midominio/images/goal_box.gif" width="16" height="16" /><img src="http://midominio/images/goal.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><br/> <img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/box.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><br/> <img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/box.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><br/> <img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><br/> <img src="http://midominio/images/floor.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/wall.gif" width="16" height="16" /><img src="http://midominio/images/floor.gif" width="16" height="16" /><br/> <br/>
Y obviamente, el htm generado pesa mucho, por lo que tendré problemas de ancho de banda, por ejemplo, para unos 100 niveles, el htm pesa más de un mega. Tengo pensado evitar: width="16" height="16 y poner class="algo" y especificar el tamaño con css. Sin embargo de todas formas, es mucho código, así es que me gustaría poder pegar todas las imagenes, ¿se puede hacer con php dinámicamente? y así generar una sola imagen para que el htm quede: <img src=" http://midominio/images/imagenGenerada.gif" /> Si se puede, podría generar todas las imágenes, y subirlas a otro hosting, por ejemplo imageshack, así me ahorro un montón de ancho de banda. Nota: cada cuadro de 16*16 de la imagen que muestro es una imagen, por ejemplo: wall.gif es el bloque de muralla, floor.gif es el bloque negro, etc.
|
|
|
5
|
Programación / PHP / Sugerencia login
|
en: 7 Octubre 2009, 07:44 am
|
Hola, estoy recién comenzando a jugar con las sesiones, quisiera recibir por favor sugerencias sobre este script para comprender bien la lógica. Edito: tenía un problema, pero edito, ahora me gustaría recibir sugerencias sobre cómo mejorar el script. Le he añadido protección básica contra fijación de sesiones y cross site request forgeries. <?php if (!isset($_SESSION['logeado'])) { if ($_POST['user'] == 'carlos' && $_POST['password'] == 'entrar') { $_SESSION['logeado'] = true; } } else if ($_POST['logout']) { if (isset($_SESSION['token']) && $_POST['token'] == $_SESSION['token']) { } } if ($_SESSION['logeado'] == true) { echo 'Contenido exlusivo' . '<br />'; } ?> <html> <body> <?php if ($_SESSION['logeado'] == false) { ?> <form method='POST' action='login.php'> User: <input name="user" type="text" maxlength="50" size="20" /> Password: <input name="password" type="text" maxlength="50" size="20" /> <input name="login" type="submit" value="Login" /> </form> <?php } else { ?> <form method='POST' action='login.php'> <input name="token" type="hidden" value="<?php echo $_SESSION['token']; ?>" /> <input name="logout" type="submit" value="Logout" /> </form> <?php } ?> </body> </html>
|
|
|
6
|
Programación / PHP / Se puede tener una configuración personalizada de php en un servidor compartido?
|
en: 6 Octubre 2009, 06:56 am
|
Tengo esa duda: ¿Se puede tener una configuración personalizada de php en un servidor compartido?
Me gustaría contratar un hosting barato (compartido), pero me gustaría tener mi configuración personal de php, por ejemplo, deshabilitar las magic quotes, y establecer la conexión por defecto a la bd dentro de la configuración de php, así me evito exponer los datos de la bd innecesariamente.
Mi pregunta es si se puede.
|
|
|
7
|
Programación / Scripting / Bug batch.
|
en: 1 Octubre 2009, 08:33 am
|
Yo había leído en un sitio que para asignar con el comando set es lo mismo: set "variable=valor" que (set variable=valor) Sin embargo, he encontrado un bug de cmd.exe. Cuando cmd.exe reconoce una sola comilla dentro de paréntesis termina el archivo por lotes. Por eso si se hace: (") el archivo por lotes termina. Por eso si tenemos el siguiene código: test.cmd @echo off (set var=%1) echo.El texto se muestra. y ejecutamos: test.cmd " el texto no se muestra porque el archivo por lotes concluyó antes por el bug. Pero si hacemos: test.cmd @echo off set "var=%1" echo.El texto se muestra. el texto si es mostrado. Entonces no es lo mismo: (set variable=valor) que contiene el bug. que: set "variable=valor"
|
|
|
8
|
Programación / Scripting / Error reply [batch]
|
en: 30 Septiembre 2009, 22:28 pm
|
Hola sin querer creo haber encontrado un problema del comando reply alias keyboard. keyboard.com 14 bytes :reply ( echo.N REPLY.COM;O KEYBOARD.COM echo.E 0000 B4 08 CD 21 3C 00 75 02 CD 21 B4 4C CD 21 echo.R CX echo.000E echo.W0 echo.Q echo. ) | debug
Cuando lo ejecutan con tabla de códigos 1252 sale un mensaje: chcp 1252 reply.com 3íÆž è®ôè&s ítè ë Æ”œè sÚëøëù^_ZY[XÃSQRWVœèf ƒ>ð @
- 1252,
Solución, llamar a reply.com redirigiendo salida a nul: reply.com > nul Creo que será necesario siempre redirigir la salida a nul para evitar posibles mensajes.  También, si le dan como entrada a reply nul se queda "colgado". reply.com < nul
Alternativa a reply.com: getkey.com de Herbert Kleebauer 137 bytes echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>getkey.com echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU!WvX0GwUY Wv;ovBX2Gv0ExGIuht6>>getkey.com echo L?p{KsUWK`LR0x>>getkey.com
|
|
|
9
|
Programación / Scripting / Respaldo towel.blinkenlights.nl
|
en: 27 Septiembre 2009, 23:57 pm
|
Hace tiempo quise hacer esto, y pensé que no se podía, hacer un respaldo de la animación de star wars de towel.blinkenlights.nl Para verla: telnet.exe towel.blinkenlights.nl Yo intentaba hacer: telnet.exe towel.blinkenlights.nl > respaldo.txt y no funcionó. Al final, desistí, pero hoy, leyendo la ayuda del comando telnet.exe me acordé de esto y ya conseguí hacer el respaldo. Es así: telnet.exe -f respaldo.txt towel.blinkenlights.nl
De esa forma, todo lo que se ve va quedando en el archivo de texto. Más o menos queda así: /~\ |oo ) _\=/_ ___ / _ \ / ()\ //|/.\|\\ _|_____|_ \\ \_/ || | | === | | \|\ /| || |_| O |_| # _ _/ # || O || | | | ||__*__|| | | | |~ \___/ ~| []|[] /=\ /=\ /=\ | | | ________________[_]_[_]_[_]________/_]_[_\_________________________ /~\ |oo ) Did you hear that? _\=/_ ___ / _ \ / ()\ //|/.\|\\ _|_____|_ \\ \_/ || | | === | | \|\ /| || |_| O |_| # _ _/ # || O || | | | ||__*__|| | | | |~ \___/ ~| []|[] /=\ /=\ /=\ | | | ________________[_]_[_]_[_]________/_]_[_\_________________________ /~\ |oo ) _\=/_ ___ / _ \ / ()\ //|/.\|\\ _|_____|_ \\ \_/ || | | === | | \|\ /| || |_| O |_| # _ _/ # || O || | | | ||__*__|| | | | |~ \___/ ~| []|[] /=\ /=\ /=\ | | | ________________[_]_[_]_[_]________/_]_[_\_________________________ /~\ |oo ) _\=/_ ___ # / _ \ / ()\ \\//|/.\|\\ _|_____|_ \/ \_/ || | | === | | |\ /| || |_| O |_| \_ _/ # || O || | | | ||__*__|| | | | |~ \___/ ~| []|[] /=\ /=\ /=\ | | | ________________[_]_[_]_[_]________/_]_[_\_________________________ /~\ ( oo| They've shut down _\=/_ the main reactor. ___ # / _ \ / ()\ \\//|/.\|\\ _|_____|_ \/ \_/ || | | === | | |\ /| || |_| O |_| \_ _/ # || O || | | | ||__*__|| | | | |~ \___/ ~| []|[] /=\ /=\ /=\ | | | ________________[_]_[_]_[_]________/_]_[_\_________________________ /~\ ( oo| They've shut down _\=/_ the main reactor. ___ # / _ \ / ()\ \\//|/.\|\\ _|_____|_ \/ \_/ || | | === | | |\ /| || |_| O |_| \_ _/ # || O || | | | ||__*__|| | | | |~ \___/ ~| []|[] /=\ /=\ /=\ | | | ________________[_]_[_]_[_]________/_]_[_\_________________________
Sin embargo, esto genera una salida imprimible, para un verdadero respaldo se puede usar el putty y activar en Session -> Logging: All session output. De esa forma tienen el texto con las secuencias de escape. Por ejemplo: /~\ |oo ) At last! _\=/_ ___ / _ \ / ()\ //|/.\|\\ _|_____|_ || \_/ || | | === | | || |\ /| || |_| O |_| # \_ _/ # || O || | | | ||__*__|| | | | |~ \___/ ~| []|[] /=\ /=\ /=\ | | | ________________[_]_[_]_[_]________/_]_[_\_________________________[H
|
|
|
10
|
Programación / PHP / Ayuda con header [solucionado]
|
en: 25 Septiembre 2009, 06:49 am
|
Hola, tengo un pequeño problema y quisiera pedirles ayuda por favor para solucionarlo. [ya lo solucioné] Estoy escribiendo un conversor de archivos en php, para ello ya tengo listo y probado el upload y funciona bien, pero quiero que una vez comprobé que el archivo subido es correcto, proceder a la conversión y que aparezca para descargarlo, de lo contrario que muestre el mensaje de error. este es un código con la idea, y con el problema. <?php header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename=' . '"' . 'convertido.txt' . '"'); ?> <? $archivoValido = 0; if ($archivoValido == 1) { echo "Esto va dentro del archivo: convertido.txt"; } else { // Que debo hacer para el mensaje de error en la página.? echo "Error. que esto se muestre en la pagina"; } ?>
edito: al final la solución era usar un solo bloque de código php, y especificar los headers solo en la sección correspondiente. Al final queda así: <? $archivoValido = 0; if ($archivoValido == 1) { header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename=' . '"' . 'convertido.txt' . '"'); echo "Esto va dentro del archivo: convertido.txt"; } else { // Que debo hacer para el mensaje de error en la página.? echo "Error. que esto se muestre en la pagina"; } ?>
|
|
|
|
|
|
|