File Upload Vulnerability

Author: wrndmzmnqCreated Feb 10, 2026Updated Feb 10, 2026

1.Code segment: the upload function in:src/main/java/ltd/newbee/mall/controller/common/UploadController.java中的upload函数 `@Controller @RequestMapping("/admin") public class UploadController {

@Autowired
private StandardServletMultipartResolver standardServletMultipartResolver;

@PostMapping({"/upload/file"})
@ResponseBody
public Result upload(HttpServletRequest httpServletRequest, @RequestParam("file") MultipartFile file) throws URISyntaxException, IOException {
    String fileName = file.getOriginalFilename();
    BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
    if (bufferedImage == null) {
        return ResultGenerator.genFailResult("请上传图片类型的文件");
    }
    String suffixName = fileName.substring(fileName.lastIndexOf("."));
    //生成文件名称通用方法
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
    Random r = new Random();
    StringBuilder tempName = new StringBuilder();
    tempName.append(sdf.format(new Date())).append(r.nextInt(100)).append(suffixName);
    String newFileName = tempName.toString();
    File fileDirectory = new File(Constants.FILE_UPLOAD_DIC);
    //创建文件
    File destFile = new File(Constants.FILE_UPLOAD_DIC + newFileName);
    try {
        if (!fileDirectory.exists()) {
            if (!fileDirectory.mkdir()) {
                throw new IOException("文件夹创建失败,路径为:" + fileDirectory);
            }
        }
        file.transferTo(destFile);
        Result resultSuccess = ResultGenerator.genSuccessResult();
        resultSuccess.setData(NewBeeMallUtils.getHost(new URI(httpServletRequest.getRequestURL() + "")) + "/upload/" + newFileName);
        return resultSuccess;
    } catch (IOException e) {
        e.printStackTrace();
        return ResultGenerator.genFailResult("文件上传失败");
    }
}`

No validation of file extensions is performed.

2.The frontend validates whether the file format is JPG, PNG, or GIF

ImageImage 3.Upload an image directly, then use Burp Suite to capture the request, modify the file extension, and add the corresponding payload at the end of the file (the file must contain an image, as the backend validates this).ImageImageImage 3.Uploading a JSP file is also possible, but it won't be parsed and will be directly downloaded. This depends on the server configurationImageImage