zoukankan      html  css  js  c++  java
  • Java代码审计-路径遍历 目录覆盖 举例:解压zip文件,未对zip目录进行验证

    举例:项目中在解压zip文件时,未对zip条目进行验证,存在路径遍历的风险,为了系统安全,应加上安全黑名单特殊字符过滤。

    示例 代码如下:
      String name= zipEntry getName O
      通过上述语句获取zip条目的名字,
      File unzipFile- new File(path+ name)
      随后通过获取的zip条目名字直接创建文件夹或文件。

        Web应用接收恶意zip压缩包,会造成受保护的文件或目录被覆盖等危险。


      修复建议:在解压zip文件时,对zip条目名称进行危险字符过滤,禁止解压缩路径中包含(.)等特殊字符


    //获取压文件对象,gbk解决中文文件夹乱码   zip =
    new ZipFile(zipFile, Charset forName("GBK)):   Enumeration <? extends ZipEntry> entries=zip. entries();
      ExcellmportData excellmportData
    null:   while(entries.hasMoreElements(){     zipEntry zipEntry = entries.nextElement();     String name = zpEntry.getName();
        File unzipFiles =
    new File(path name);     if (unzipFile.isDirectory || unzipFile.getName().contains(".")){       unzipFile.mkdirs();     }else       File parentFile unzipFilegetParentFileo:     if (parentFileexists){       parentFilemkdirsO:       bis new BufferedInputstream(zip. getinpu tstream(zipEntry2):       bos new Bufferedoutputstream(new FileOutputStream(unzip File));
          ... ...
          ... ...




  • 相关阅读:
    SVN cleanup操作反复失败解决办法
    mysql常用命令之-用户密码修改
    properties 配置文件中值换行的问题
    在每一行行尾添加内容
    Java 毫秒转换为日期类型、日期转换为毫秒
    SimpleDateFormat 12小时制以及24小时制的写法
    java校验时间格式 HH:MM
    ClassLoader 详解及用途(写的不错)
    ObjectInputStream类和ObjectInputStream类的使用
    logback 详解
  • 原文地址:https://www.cnblogs.com/jayus/p/11423769.html
Copyright © 2011-2022 走看看