Struts2 漏洞:Struts2.2.1版本紧急升级Struts2.3.15.1版本中遇到问题和解决方法,你中招了没?!

Struts2这个流行的框架遭遇了最严重的一次危机,官方进行了紧急修复新出了一个2.3.15.1的版本,感觉这个版本出的太急躁了,补了东墙,西墙又出了问题,然后引起连锁反应!

导致全球范围内大部分使用S2框架的网站中招,国内的有:中国电信、中国联通等运营商部分分站,中科院、工信部、交通部、中国邮政等部分站点,以及腾讯、淘宝、搜狐等大型互联网公司的部分分站均在列,不过很多分站并不涉及数据库。

怎么说呢,是OGNL的对象树太牛逼了!


下午开始进行升级,先下载最新的2.3.15.1的压缩包<下载地址>,解压,进入lib目录:

由于使用了MyEclipse 10,并且项目中引入了Struts 2 Core Libraries库,直接对照里面的jar包进行更新了

1.涉及到的jar包有:

aopalliance-1.0.jar

asm-3.3.jar

asm-commons-3.3.jar

classworlds-1.1.jar

commons-beanutils-1.8.0.jar

commons-chain-1.2.jar

commons-collections-3.1.jar

commons-digester-2.0.jar

commons-fileupload-1.3.jar

commons-io-2.0.1.jar

commons-lang-2.4.jar

commons-lang3-3.1.jar

commons-logging-1.1.3.jar

commons-logging-api-1.1.jar

commons-validator-1.3.1.jar

freemarker-2.3.19.jar

javassist-3.11.0.GA.jar

json-lib-2.3-jdk15.jar

ognl-3.0.6.jar

oro-2.0.8.jar

struts2-convention-plugin-2.3.15.1.jar

struts2-core-2.3.15.1.jar

struts2-dojo-plugin-2.3.15.1.jar

struts2-embeddedjsp-plugin-2.3.15.1.jar

struts2-json-plugin-2.3.15.1.jar

struts2-spring-plugin-2.3.15.1.jar

xwork-core-2.3.15.1.jar

根据你的项目使用到的包做相应的精简,偷懒的话,全部加进去。

结果发现:

1.json-lib-2.3-jdk15中JSONArray已经没有put方法了,于是换成了add方法;

2.StringUtils换成了org.apache.commons.lang3.StringUtils

然后,启动项目. . . . Tomcat启动中


启动后访问页面action,后台出现

***************************************************************************
*                                 WARNING!!!                              *
*                                                                         *
* >>> ActionContextCleanUp <<< is deprecated! Please use the new filters! *
*                                                                         *
*             This can be a source of unpredictable problems!             *
*                                                                         *
*                Please refer to the docs for more details!               *
*              http://struts.apache.org/2.x/docs/webxml.html              *
*                                                                         *
***************************************************************************

原来,自2.1.3起,ActionContextCleanUp就已经不推荐使用了,于是在web.xml中把

<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>

<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

注释掉,

继续运行,发现原来可以保存的内容现在后台提示

ParametersInterceptor - Developer Notification (set struts.devMode to false to disable this message):

Caused by: No object in the CompoundRoot has a publicly accessible property named 'xxxxx'

好嘛根据提示去struts.xml里把struts.devMode设置为false,世界到是清静了,但还是保存不成功!

新版本里,加强了各种验证,在devMode为true模式下,可以发现各种问题了,有助于在开发中提前发现一些问题。


**********************郁闷的分割线********************


还是保存不成功啊,于是继续找问题发现

<action.....>

<result type="json">
<param name="includeProperties">success,tip</param>
</result>

</action>

该action中列表中已经有值了,但页面上的json就是空的,action实现了ModelDriven


直到某个兄弟尝试搜索了一下Struts2 ModelDriven不返回json,有一个伙计也遇到同样的问题,点这里

新的Struts2-json-plugin-2.3.15.jar用ModelDriven接收参数,在返回JSON时,JSON的结构有变化,2.2版本中ValueStack中rootObject是Action类,新的里面却没了,于是有了下面的修改:

<result type="json">
<param name="root">action</param>
<param name="includeProperties">
success,tip
</param>
</result>

增加了红色字体行,于是就OK了,可是这始终感觉不正规,所有的Action使用了JSON的地方都要这么处理。。。。。暂时先这样吧,还没有更好的办法!


有好办法的童鞋,在下面留言啊!


关于这次的漏洞,可以参考这位大大的空虚浪子心 的博客,国内还是有牛人的!


今天,你中招了吗?


不管你中没中,反正我是中了!!!

猜你喜欢

转载自blog.csdn.net/jackymvc/article/details/9860629