Lucene search

K
seebugRootSSV:69390
HistoryJul 01, 2014 - 12:00 a.m.

Struts2/XWork < 2.2.0 - Remote Command Execution Vulnerability

2014-07-0100:00:00
Root
www.seebug.org
136

0.054 Low

EPSS

Percentile

92.3%

漏洞详情

在struts2中,DefaultActionMapper类支持以"action:"、“redirect:”、"redirectAction:"作为导航或是重定向前缀,但是这些前缀后面同时可以跟OGNL表达式,由于struts2没有对这些前缀做过滤,导致利用OGNL表达式调用java静态方法执行任意系统命令。

这里以“redirect:”前缀举例,struts2会将“redirect:”前缀后面的内容设置到redirect.location当中,这里我们一步步跟踪,首先是这个getMapping函数跟入

这里一直到这个handleSpecialParameters(),继续跟入

这里真正传入OGNL表达式是在这个parameterAction.execute()中,继续跟入来到DefaultActionMapper.java的代码

然而上面的过程只是传递OGNL表达式,真正执行是在后面,这里是在FilterDispatcher类中的dispatcher.serviceAction()方法,这里的mapping对象中设置了传入的OGNL

这里跟入方法最终会在TextParseUtil这个类的调用stack.findValue()方法执行OGNL。

详情来源:http://drops.wooyun.org/papers/902


                                                Friday, July 9, 2010
CVE-2010-1870: Struts2/XWork remote command execution
Update Tue Jul 13 2010: Added proof of concept

Apache Struts team has announced uploaded but has not released, due to an unreasonably prolonged voting process, the 2.2.0 release of the Struts2 web framework which fixes vulnerability that I&#39;ve reported to them on May 31st 2010. Apache Struts team is ridiculously slow in releasing the fixed version and all of my attempts to expedite the process have failed.

Introduction
Struts2 is Struts + WebWork. WebWork in turn uses XWork to invoke actions and call appropriate setters/getters based on HTTP parameter names, which is achieved by treating each HTTP parameter name as an OGNL statement. OGNL (Object Graph Navigation Language) is what turns:

user.address.city=Bishkek&user[&#39;favoriteDrink&#39;]=kumys

into

action.getUser().getAddress().setCity(&#34;Bishkek&#34;)
action.getUser().setFavoriteDrink(&#34;kumys&#34;)

This is performed by the ParametersInterceptor, which calls ValueStack.setValue() with user-supplied HTTP parameters as arguments.
NOTE: If you are using XWork&#39;s ParametersInterceptor or operate with OGNL ValueStack in a similar way then you are vulnerable (ParametersInterceptor is on by default in struts-default.xml).

In addition to property getting/setting, OGNL supports many more features:

    * Method calling: foo()
    * Static method calling: @java.lang.System@exit(1)
    * Constructor calling: new MyClass()
    * Ability to work with context variables: #foo = new MyClass()
    * And more...

Since HTTP parameter names are OGNL statements, to prevent an attacker from calling arbitrary methods via HTTP parameters XWork has the following two variables guarding methods execution:

    * OgnlContext&#39;s property &#39;xwork.MethodAccessor.denyMethodExecution&#39; (set to true by default)
    * SecurityMemberAccess private field called &#39;allowStaticMethodAccess&#39; (set to false by default)

OGNL Context variables
To make it easier for developer to access various frequently needed objects XWork provides several predefined context variables:

    * #application
    * #session
    * #request
    * #parameters
    * #attr

These variables represent various server-side objects, such as session map. To prevent attackers from tampering with server-side objects XWork&#39;s ParametersInterceptor disallowed # in parameter names. About a year ago I found a way to bypass that protection(XW-641) using Java&#39;s unicode String representation: \u0023. At the time I felt like the fix that was implemented (OGNL value stack clearing) was insufficient, but had not time to investigate this further. 

CVE-2010-1870
Earlier this year I finally got a chance to look at this again and found that in addition to the above mentioned context variables there were more:

    * #context - OgnlContext, the one guarding method execution based on &#39;xwork.MethodAccessor.denyMethodExecution&#39; property value.
    * #_memberAccess - SecurityMemberAccess, whose &#39;allowStaticAccess&#39; field prevented static method execution.
    * #root
    * #this
    * #_typeResolver
    * #_classResolver
    * #_traceEvaluations
    * #_lastEvaluation
    * #_keepLastEvaluation

You can probably see the problem already. Using XW-641 trick I was able to modify the values that were guarding Java methods execution and run arbitrary Java code:

#_memberAccess[&#39;allowStaticMethodAccess&#39;] = true
#foo = new java .lang.Boolean(&#34;false&#34;)
#context[&#39;xwork.MethodAccessor.denyMethodExecution&#39;] = #foo
#rt = @java.lang.Runtime@getRuntime()
#rt.exec(&#39;mkdir /tmp/PWNED&#39;)

Actual proof of concept had to use OGNL&#39;s expression evaluation when crafting HTTP request. PoC for this bug will be published on July 12 2010. To test whether your application is vulnerable you can use the following proof of concept, which will call java.lang.Runtime.getRuntime().exit(1):


http://mydomain/MyStruts.action?(&#39;\u0023_memberAccess[\&#39;allowStaticMethodAccess\&#39;]&#39;)(meh)=true&(aaa)((&#39;\u0023context[\&#39;xwork.MethodAccessor.den
yMethodExecution\&#39;]\u003d\u0023foo&#39;)(\u0023foo\u003dnew%20java.lang.Boolean(&#34;false&#34;)))&(asdf)((&#39;\u0023rt.exit(1)&#39;)(\u0023rt\[email protected]@getRunti
me()))=1


Fixing CVE-2010-1870
Struts2 users must upgrade to the 2.2.0, which whitelists a set of characters that excludes characters required to exploit this vulnerability.


In cases where upgrade isn&#39;t possible you can use ParameterInterceptor&#39;s &#34;excludeParams&#34; parameter to whitelist the characters required for your application to operate correctly(usually A-z0-9_.&#39;&#34;[]) alternatively you can blacklist \()@ which are the characters required to exploit this bug.

Timeline
May 31st - email to [email protected] with vulnerability report.
June 4th - no response received, contacted developers again.
June 5th - had to find an XWork developer on IRC to look at this.
June 16th - Atlassian fixes vulnerability in its products. Atlassian and Struts developers worked together in coming up with the fix.
June 20th - 1-line fix commited
June 29th - Struts 2.2.0 release voting process started and is still going...