文件上传靶场

文件上传前后端代码

后端采用Springboot实现,读者还需根据自己的本地环境进行更改。

前端代码

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Apache文件解析漏洞靶场</title>
</head>

<body>
	<form action="http://localhost:8082/fileload/up" enctype="multipart/form-data" method="POST">
		  <input name="file" type="file" id="file">
		  <input type="submit" value="提交">
	</form>

</body>
</html>

后端代码

package Orion.AAA.Controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;


/**
 * @Author: Orion
 * @Date: 2023/04/12/09:51
 * 少就是多,慢就是快
 */

@RestController
@RequestMapping("fileload")
public class FileLoadServlet extends HttpServlet {

    @PostMapping("/up")
    protected String service(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        if(file   != null && request.getContentLength() > 0){

            // 获取前端传过来文件的文件名
            String fileName = file.getOriginalFilename();

            // 指定上传路劲,我是mac,读者可以改为自己的路径
            String pathName = "/Applications/phpstudy/WWW/ApacheV/uploadfiles";

            String path =pathName+'/';
            // 生成上述路径文件
            File tempFile = new File(path);
            if (!tempFile.exists()) {
                tempFile.mkdirs();
            }

            // 通过父路径和子文件名创建文件
            File file2 = new File(tempFile,fileName);

            // 将前端发过来的文件输送给新文件 完成存入
            file.transferTo(file2);

            return "文件上传成功";

        }else{
            return "文件上传失败";
        }

    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值