zoukankan      html  css  js  c++  java
  • 原!struts安全漏洞,由2.3.37版本升级至2.5.22

    漏洞描述

    Apache Struts2框架是一个用于开发Java EE网络应用程序的Web框架。Apache Struts于2020年8月13日披露 S2-059 Struts 远程代码执行漏洞(CVE-2019-0230),在使用某些tag等情况下可能存在OGNL表达式注入漏洞,从而造成远程代码执行,风险极大。阿里云应急响应中心提醒Apache Struts用户尽快采取安全措施阻止漏洞攻击。

    影响版本

    Apache Struts 2.0.0 - 2.5.20

    安全版本

    Apache Struts >= 2.5.22

    安全建议

    将Apache Struts框架升级至最新版本。

    升级步骤:

    一、替换struts相关maven依赖包 ,版本改为2.5.22,同时删除struts.xwork依赖,2.5版本core已经集成该依赖。

    本人项目中只替换了struts的这些maven依赖,看网上有其他人替换了很多其他包,如果项目报错那就替换。

    二、struts.xml配置文件修改,包括以下几个方面:

     1)<!DOCTYPE改为2.5版本

    <!DOCTYPE struts PUBLIC

            "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "http://struts.apache.org/dtds/struts-2.5.dtd">

    2)增加配置,这个不加应该也行,百度出来好多都加了。
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
    <constant name="struts.enable.SlashesInActionNames" value="true"/>

    3)struts2从2.5版本开始,为了提升安全性,默认开启了严格的方法调用。
    action中如果要使用通配符*,必须在package中设置 strict-method-invocation="false" 或者 添加<global-allowed-methods>regex:.*</global-allowed-methods>

    例如:
    <package name="jspPath" extends="struts-default" strict-method-invocation="false">
    <interceptors>
    <interceptor name="pathMatch"
    class="com.cmcc.open.devportal.mlabs.common.interceptor.PageSwitchInterceptor"/>
    <interceptor name="ajaxTokenFilter"
    class="com.cmcc.open.devportal.mlabs.common.filter.AjaxTokenFilter">
    <param name="includeMethods">templateCallVoiceTemplate</param>
    </interceptor>
    <interceptor-stack name="pathMatchInterceptor">
    <interceptor-ref name="pathMatch"/>
    <interceptor-ref name="defaultStack"/>
    </interceptor-stack>
    </interceptors>
    <default-interceptor-ref name="pathMatchInterceptor"/>
    <!--struts 2.5版本 action通配符* 这个能被其他package继承,比较好用,如果你其他package都extends了某个基础的package -->
    <global-allowed-methods>regex:.*</global-allowed-methods>
    </package>

    或者
    <package name="apiData" extends="struts-default,json-default" namespace="/apiData">
    <global-allowed-methods>regex:.*</global-allowed-methods>
    <action name="calls" method="calls" class="com.cmcc.open.devportal.web.ApiCallsDataAction" >
    </action>
    </package>


    三、web.xml调整

    1)<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">


    2)

    <filter>

            <filter-name>struts2</filter-name>

            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

    </filter>

    把  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 中的.ng 去掉 修改为

    <filter>

            <filter-name>struts2</filter-name>

            <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>

    </filter>


    四、jsp页面涉及的id都不能用,会报错,利用正则全局替换。
    <s:iterator value="codeTypes" id="codeTypes" status="status">,idea工具 全局正则替换如下:

     <s:iterator(.*)id=

    <s:iterator$1var=

    其他参考:

    1.https://blog.csdn.net/qq_34128089/article/details/80804882?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

    2.https://blog.csdn.net/qq_40248086/article/details/104752778?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

    3.https://blog.csdn.net/blue_hh/article/details/79270850?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

  • 相关阅读:
    预防XSS攻击的一些方法整理
    Linux常用的命令集
    Linux根目录下各文件夹说明
    ThinkPHP框架3.2版本学习总结
    【ThinkPHP框架3.2版本学习总结】九、知识补充
    【ThinkPHP框架3.2版本学习总结】八、关联模型
    【ThinkPHP框架3.2版本学习总结】七、Ajax应用
    【ThinkPHP框架3.2版本学习总结】六、多表连接
    【ThinkPHP框架3.2版本学习总结】五、实用项
    tmux
  • 原文地址:https://www.cnblogs.com/wuyun-blog/p/13503665.html
Copyright © 2011-2022 走看看