文件下载漏洞
  DF5J4hb0hcmT 2023年11月13日 24 0

此漏洞可以下载服务器任何文件

源码如下

@RequestMapping("file")
public class FileDownloadController {
    
    @GetMapping("down")
    public void download(@RequestParam("p") String path, HttpServletResponse response) {
        try {
            File f = new File(path);
            String filename = f.getName();
            FileInputStream fileInputStream = new FileInputStream(f);
            InputStream inputStream = new BufferedInputStream(fileInputStream);
            byte[] buffer = new byte[inputStream.available()];
            inputStream.read(buffer);
            inputStream.close();
            response.reset();
            
            response.setCharacterEncoding("UTF-8");
            response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
            response.addHeader("Content-Length", "" + f.length());
            OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
            response.setContentType("application/octet-stream");
            outputStream.write(buffer);
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

模拟请求

http://127.0.0.1:8080/file/download?p=/root/a.txt

解决方案:

对传入参数进行判断


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月13日 0

暂无评论

推荐阅读
  3I1N9ysrcSyk   2023年12月08日   31   0   0 javahapi数据交换
  DF5J4hb0hcmT   2023年12月07日   50   0   0 javaArthas
DF5J4hb0hcmT