UCenter防止恶意访问(安全加固)

网络编辑 20/3/29 1.5k 0

uc_server/admin.php是ucenter默认的后台地址,正常情况下可以直接访问,为了防止某些恶意访问的情况,可以修改以下内容进行安全性能提升。

适用版本:Discuz!x1-x3.4适用情况:ucenter在论坛根目录下

修改后效果:未登录Discuz论坛或不在指定的管理组,打开uc_server/admin.php提示404

具体实施方案:

打开uc_server/model/admin.php

搜索

$this->cookie_status = isset($_COOKIE['sid']) ? 1 : 0;
下面接入代码:
  1. if(!$this->cookie_status){
  2.                         include UC_ROOT.'../config/config_global.php';
  3.                         $cookiepre = $_config['cookie']['cookiepre'].substr(md5($_config['cookie']['cookiepath'].'|'.$_config['cookie']['cookiedomain']), 0, 4).'_';
  4.                         $auth = addslashes($_COOKIE[$cookiepre.'auth']);
  5.                         if(empty($_config['cookie']['saltkey'])) {
  6.                                 $_config['cookie']['saltkey'] = addslashes($_COOKIE[$cookiepre.'saltkey']);
  7.                         }
  8.                         $authkey = md5($_config['security']['authkey'].$_config['cookie']['saltkey']);
  9.                         $auth = daddslashes(explode("\t", $this->dauthcode($auth, 'DECODE',$authkey)));
  10.                         list($discuz_pw, $discuz_uid) = empty($auth) || count($auth) < 2 ? array('', '') : $auth;
  11.                         $discuz_uid = intval($discuz_uid);
  12.                         $groupid = $this->db->result_first("SELECT groupid FROM ".$_config['db'][1]['tablepre']."common_member WHERE uid='$discuz_uid'");
  13.                         if(!in_array($groupid,array('1','2'))){
  14.                                  header("HTTP/1.1 404 Not Found");header("Status: 404 Not Found");exit;
  15.                         }
  16.                 }
复制代码
其中这里增加用户组:
  1. array('1','2')
复制代码
搜索
function __construct() {
                $this->adminbase();
        }
加入
  1. function dauthcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  2.                 $ckey_length = 4;
  3.                 $key = md5($key );
  4.                 $keya = md5(substr($key, 0, 16));
  5.                 $keyb = md5(substr($key, 16, 16));
  6.                 $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
  7.                 $cryptkey = $keya.md5($keya.$keyc);
  8.                 $key_length = strlen($cryptkey);
  9.                 $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
  10.                 $string_length = strlen($string);
  11.                 $result = '';
  12.                 $box = range(0, 255);
  13.                 $rndkey = array();
  14.                 for($i = 0; $i <= 255; $i++) {
  15.                         $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  16.                 }
  17.                 for($j = $i = 0; $i < 256; $i++) {
  18.                         $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  19.                         $tmp = $box[$i];
  20.                         $box[$i] = $box[$j];
  21.                         $box[$j] = $tmp;
  22.                 }
  23.                 for($a = $j = $i = 0; $i < $string_length; $i++) {
  24.                         $a = ($a + 1) % 256;
  25.                         $j = ($j + $box[$a]) % 256;
  26.                         $tmp = $box[$a];
  27.                         $box[$a] = $box[$j];
  28.                         $box[$j] = $tmp;
  29.                         $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  30.                 }
  31.                 if($operation == 'DECODE') {
  32.                         if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
  33.                                 return substr($result, 26);
  34.                         } else {
  35.                                 return '';
  36.                         }
  37.                 } else {
  38.                         return $keyc.str_replace('=', '', base64_encode($result));
  39.                 }
  40.         }
复制代码
相关帖子
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
您需要登录后才可以回帖 登录 | 注册
本版积分规则