Max's Guestbook version 1.0 suffers from a cross site scripting vulnerability.
6929c525157307cfb8c066422be51c338b5e131994e4ab28e2455268cf6d607e
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%
%% 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)