Struts2升级版本至2.5.10,高危漏洞又来了

àì夳堔傛蜴生んèń 2021-09-12 08:56 478阅读 0赞

http://blog.csdn.net/zhulin2012/article/details/61916778

这里写图片描述

前情概要

漏洞年年有,最近特别多。2017年3月6日,Apache Struts2被曝存在远程命令执行漏洞,漏洞编号:S2-045,CVE编号:CVE-2017-5638,官方评级为高危,该漏洞是由于在使用基于Jakarta插件的文件上传功能条件下,恶意用户可以通过修改HTTP请求头中的Content-Type值来触发该漏洞,进而执行任意系统命令,导致系统被黑客入侵。

漏洞分析请移步:https://yq.aliyun.com/articles/72008

建议

如果这个版本在Struts2.3.5 到 Struts2.3.31 以及 Struts2.5 到 Struts2.5.10之间则存在漏洞,请升级到struts 2.3.32或2.5.10.1版本(哔了狗了狗了,公司还在用struts2)。

由于目前使用版本是struts2-core-2.3.28,于是赶紧升了下级别,略过2.3 直接升级到2.5版本。

升级说明

一、找不到类

  1. java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  2. 1
  3. 1

找不到那得多正常,查看了一下源码,2.5版本已变更了包路径。

  1. <filter>
  2. <filter-name>struts2</filter-name>
  3. <filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
  4. </filter-class>
  5. </filter>
  6. 1
  7. 2
  8. 3
  9. 4
  10. 5
  11. 1
  12. 2
  13. 3
  14. 4
  15. 5

二、配置好了居然找不到Action

是不是有点怀疑人生了,赶紧去http://struts.apache.org/ struts2的官网扒拉扒拉。

由于版本跨度大,2.5版本升级了很多特性,在Struts 2.5中,严格DMI被扩展,它被称为严格方法调用 又名SMI。你可以想象DMI是一个“边境警察”,SMI是一个“税务警察”,并注意内部。使用此版本,SMI默认情况下启用(strict-method-invocation属性默认设置为 true在 struts-default包中),您可以选择禁用它每个包 - 没有全局开关禁用整个应用程序的SMI。

  1. SMI的工作原理如下:
  2. <allowed-methods> / @AllowedMethods 被定义每个动作 - SMI工作,而不打开它,但只是那些动作(加上<global-allowed-methods/>)
  3. SMI已启用,但没有<allowed-methods> / @AllowedMethods 被定义 - SMI工作,但只有<global-allowed-methods/>
  4. SMI已禁用 - 允许调用任何与默认RegEx匹配的操作方法 - ([A-Za-z0-9_$]*) 您可以使用常量重新定义默认RegEx,如下所示 <constant name="struts.strictMethodInvocation.methodRegex" value="([a-zA-Z]*)"/> 在操作定义中使用通配符映射时,SMI有两种方式: SMI被禁用 - 任何通配符将被替换为默认的RegEx,即:<action name="Person*" method="perform*">将被翻译成allowedMethod = "regex:perform([A-Za-z0-9_$]*)". 启用S​​MI - 不会发生通配符替换,必须严格定义通过注释或<allowed-method/>标记可以访问哪些方法。
  5. 1
  6. 2
  7. 3
  8. 4
  9. 5
  10. 6
  11. 7
  12. 8
  13. 9
  14. 10
  15. 11
  16. 1
  17. 2
  18. 3
  19. 4
  20. 5
  21. 6
  22. 7
  23. 8
  24. 9
  25. 10
  26. 11

也就是说你必须加入这个配置才可以,最好全局设置:

  1. <global-allowed-methods>regex:.*</global-allowed-methods>
  2. 1
  3. 1

三、package中元素顺序的问题

  1. 元素类型为 "package" 的内容必须匹配 "(result-types?,interceptors?,default-interceptor-ref?,default-action-ref?
  2. 1
  3. 1

出现此报错,你就要注意了,一定要检查package中 global-allowed-methods 的位置,然后按照报错指定顺序放置配置。

四、可能会出现的问题

如果你的项目中使用的是log4j而不是log4j2,那么问题就来了,你还需要加入log4j-api-2.7.jar 和log4j-core-2.7.jar,并且配置 log4j2.xml(暂且是个空的)。

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration status="error">
  3. <appenders>
  4. </appenders>
  5. <loggers>
  6. <root level="info">
  7. </root>
  8. </loggers>
  9. </configuration>
  10. 1
  11. 2
  12. 3
  13. 4
  14. 5
  15. 6
  16. 7
  17. 8
  18. 9
  19. 1
  20. 2
  21. 3
  22. 4
  23. 5
  24. 6
  25. 7
  26. 8
  27. 9

否则会一直报以下错误,至于为什么,还没深入了解。

  1. ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
  2. 1
  3. 1

好了,如果启动没有其他问题,应该就可以访问到久违的Action了。

原文:http://blog.52itstyle.com/archives/430/

发表评论

表情:
评论列表 (有 0 条评论,478人围观)

还没有评论,来说两句吧...

相关阅读