The Struts2 S2-007 vulnerability affects versions 2.0.0 to 2.2.3. When a validation rule is configured (e.g., UserAction-validation.xml) and a type conversion error occurs (e.g., submitting a string for an integer field), the backend concatenates the user input with single quotes and executes an OGNL expression. This allows injection of arbitrary OGNL expressions by breaking out of the string, similar to SQL injection. The exploit requires finding a form field with such validation rules that triggers a conversion error. A proof-of-concept payload for command execution is provided, though it cannot run in the test environment.
S2-007 远程代码执行漏洞
影响版本:2.0.0 - 2.2.3
漏洞详情:http://struts.apache.org/docs/s2-007.html
测试环境搭建
原理
参考 http://rickgray.me/2016/05/06/review-struts2-remote-command-execution-vulnerabilities.html
当配置了验证规则 <ActionName>-validation.xml 时,若类型验证转换出错,后端默认会将用户提交的表单值通过字符串拼接,然后执行一次 OGNL 表达式解析并返回。例如这里有一个 UserAction:
然后配置有 UserAction-validation.xml:
当用户提交 age 为字符串而非整形数值时,后端用代码拼接 "'" + value + "'" 然后对其进行 OGNL 表达式解析。要成功利用,只需要找到一个配置了类似验证规则的表单字段使之转换出错,借助类似 SQLi 注入单引号拼接的方式即可注入任意 OGNL 表达式。
因为受影响版本为 Struts2 2.0.0 - Struts2 2.2.3,所以这里给出绕过安全配置进行命令执行的 Payload(弹计算器,无法在本项目环境下运行):
Exploit
@rickgray 在原文中只给了弹计算器的 POC,我给出执行任意代码的 EXP:
将 Exp 传入可以利用的输入框(age),得到命令执行结果: