1024cms 2.1.1 SQL Injection

Type packetstorm
Reporter kallimero
Modified 2012-08-22T00:00:00


                                            `# Exploit Title: 1024cms <= 2.1.1 SQL vulnerability  
# Date: 21/08/2012  
# Exploit Author: Kallimero  
# Vendor Homepage: http://www.1024cms.org  
# Software Link:  
# Version: 2.1.1  
# Tested on: Debian  
1024 cms is vulnerable to a tricky SQL injection  
The vuln  
First let's see the code :  
if(!isset($_GET['p']) || trim($_GET['p']) == "") $page = $defaultpage;  
else $page = mb_strtolower($_GET['p']);  
$online_page = $page;  
You see that it's possible to inject in the $online_page variable thanks to  
ligne 8:  
if(!isset($online_page) || $online_page == "") $location = $sitename;  
else $location = $online_page;  
$uid = $_SESSION['user'];  
$chk_user = mysql_query("SELECT ip FROM ".$prefix."online WHERE  
ip='".$ip."'") or die("WHOSONLINE::: Cannot check: ".mysql_error());  
if(mysql_num_rows($chk_user) > 0) mysql_query("UPDATE ".$prefix."online SET  
time='".$now."' WHERE ip='".$ip."'") or die("WHOSONLINE::: Cannot update  
user: ".mysql_error());  
else mysql_query("INSERT INTO ".$prefix."online (time, ip, username,  
location, uid) VALUES ('".$now."', '".$ip."', '".$username."',  
'".$location."', '".$uid."')") or die("WHOSONLINE::: Cannot insert user:  
w00t an SQL injection. $location isn't properly sanitarized.  
Its a bit tricky because to inject you have to be connected but not logged  
as an online user with your ip.  
The most simple solution is to log with an ip, then keep the cookies and  
inject with another.  
The PoC :  
Error based injection in INSERTO INTO :  
And you normally see :  
WHOSONLINE::: Cannot insert user: Duplicate entry 'admin:[MD5 HASH]~1' for  
key 'group_key'  
How to Fix ?  
To fix the vuln juste take this line of the index.php script :  
if(mb_eregi("[^[:space:]a-zA-Z0-9_.-]{1,}", $page)) die("PAGE FORMAT  
And put it before the whosonline.php inclusion.  
Special thanks : Epicout  
All hwc members : Necromoine, fr0g, AppleSt0rm, St0rn, Zhyar, k3nz0.  
Please visit : http://orgasm.re/