Commit 6eec98c3 by 罗胜

高危漏洞修复

parent 75185be9
...@@ -6,7 +6,6 @@ username=f387adfd9ac040d78061c890ead8e215 ...@@ -6,7 +6,6 @@ username=f387adfd9ac040d78061c890ead8e215
#username=esdk_user #username=esdk_user
#connection user password #connection user password
#password=Huawei@123
password=c49bc828b17297f1dbcfd394c7835dc6 password=c49bc828b17297f1dbcfd394c7835dc6
#gwIp #gwIp
......
...@@ -4,8 +4,6 @@ jdbc.type=mysql ...@@ -4,8 +4,6 @@ jdbc.type=mysql
jdbc.driver.class=com.mysql.jdbc.Driver jdbc.driver.class=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://81.69.44.115:5508/jd_foc?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull jdbc.url=jdbc:mysql://81.69.44.115:5508/jd_foc?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
jdbc.username=b849656b41d3eb136ad6a9d7328d4e6a jdbc.username=b849656b41d3eb136ad6a9d7328d4e6a
#jdbc.username=sms_develop
#jdbc.password=Develop2018!@#
jdbc.password=33c9745f057ba48a41d8043f1a007100 jdbc.password=33c9745f057ba48a41d8043f1a007100
#\u521d\u59cb\u5316\u8fde\u63a5 #\u521d\u59cb\u5316\u8fde\u63a5
jdbc.initialSize=0 jdbc.initialSize=0
......
...@@ -127,6 +127,9 @@ public class GConstants { ...@@ -127,6 +127,9 @@ public class GConstants {
Resource resource = null; Resource resource = null;
for (String location : resources) {// 加载配置文件 for (String location : resources) {// 加载配置文件
try { try {
if(StrUtil.contains(location,"../")||StrUtil.contains(location,"..\\")){
continue;
}
resourceLoader = new DefaultResourceLoader(); resourceLoader = new DefaultResourceLoader();
resource = resourceLoader.getResource(location); resource = resourceLoader.getResource(location);
is = resource.getInputStream(); is = resource.getInputStream();
...@@ -213,7 +216,7 @@ public class GConstants { ...@@ -213,7 +216,7 @@ public class GConstants {
* @return * @return
*/ */
public static String getValue(String key) { public static String getValue(String key) {
if(StrUtil.contains(key, "/")||StrUtil.contains(key, "\\")){ if(StrUtil.contains(key, "../")||StrUtil.contains(key, "..\\")){
return null; return null;
} }
if (key == null) if (key == null)
...@@ -222,7 +225,7 @@ public class GConstants { ...@@ -222,7 +225,7 @@ public class GConstants {
return P.getProperty(key); return P.getProperty(key);
} }
String property = System.getProperty(key); String property = System.getProperty(key);
if (StrUtil.isBlank(property)) { if (StrUtil.isBlank(property)||StrUtil.contains(property, "../")||StrUtil.contains(property, "..\\")) {
return null; return null;
} }
return property; return property;
......
...@@ -100,8 +100,11 @@ public class Html2File { ...@@ -100,8 +100,11 @@ public class Html2File {
// String md5 = DigestUtils.md5Hex(buf); // String md5 = DigestUtils.md5Hex(buf);
String baseDir=StrUtil.replace(StrUtil.replace(baseDatePath + GConstants.FS + GConstants.FILE_IMAGE_ACTUALS + GConstants.FS + basePath,"../",""),"..\\",""); String baseDir=StrUtil.replace(StrUtil.replace(baseDatePath + GConstants.FS + GConstants.FILE_IMAGE_ACTUALS + GConstants.FS + basePath,"../",""),"..\\","");
// 上传文件基本地址 // 上传文件基本地址
File baseUploadDir = new File(GConstants.FILE_UPLOAD_DIR, String path = GConstants.FILE_UPLOAD_DIR + baseDir;
baseDir); if(StrUtil.contains(path,"../")||StrUtil.contains(path,"..\\")){
throw new RuntimeException("文件路径非法");
}
File baseUploadDir = new File(path);
if (!baseUploadDir.exists()) {// 如果文件夹不存在则创建 if (!baseUploadDir.exists()) {// 如果文件夹不存在则创建
baseUploadDir.mkdirs(); baseUploadDir.mkdirs();
......
...@@ -14,6 +14,7 @@ import java.util.List; ...@@ -14,6 +14,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import cn.hutool.core.util.StrUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.geo.split.RegionEntity; import org.geo.split.RegionEntity;
import org.geo.split.RegionSplit; import org.geo.split.RegionSplit;
...@@ -78,8 +79,11 @@ public final class IPSeeker { ...@@ -78,8 +79,11 @@ public final class IPSeeker {
dir = file.getAbsolutePath()+GConstants.FS+"res"+GConstants.FS; dir = file.getAbsolutePath()+GConstants.FS+"res"+GConstants.FS;
} }
} }
String path = dir + "QQWry.dat";
File db = new File(dir+"QQWry.dat"); if (StrUtil.contains(path, "../")||StrUtil.contains(path, "..\\")) {
throw new RuntimeException("IP数据库文件QQWry.dat路径错误");
}
File db = new File(path);
LOG.info("加载QQWry.dat数据:"+db.getAbsolutePath()); LOG.info("加载QQWry.dat数据:"+db.getAbsolutePath());
if(db.exists()){ if(db.exists()){
this.ipFile = new RandomAccessFile(db, "r"); this.ipFile = new RandomAccessFile(db, "r");
...@@ -98,7 +102,11 @@ public final class IPSeeker { ...@@ -98,7 +102,11 @@ public final class IPSeeker {
e.printStackTrace(); e.printStackTrace();
} }
try { try {
File db = new File(dir+"GeoLite2-City.mmdb"); String path = dir + "GeoLite2-City.mmdb";
if (StrUtil.contains(path, "../")||StrUtil.contains(path, "..\\")) {
return ;
}
File db = new File(path);
LOG.info("加载GeoLite2-City.mmdb数据:"+db.getAbsolutePath()); LOG.info("加载GeoLite2-City.mmdb数据:"+db.getAbsolutePath());
if(db.exists()){ if(db.exists()){
reader = new DatabaseReader.Builder(db).build(); reader = new DatabaseReader.Builder(db).build();
......
...@@ -145,7 +145,11 @@ public final class ImageUtil { ...@@ -145,7 +145,11 @@ public final class ImageUtil {
src = FileManipulation.validateFile(src); src = FileManipulation.validateFile(src);
File srcfile = new File(src); File srcfile = new File(src);
if (!srcfile.exists()) { if (!srcfile.exists()) {
srcfile = new File(GConstants.FILE_UPLOAD_DIR + src); String path = GConstants.FILE_UPLOAD_DIR + src;
if (StrUtil.contains(path, "../")||StrUtil.contains(path, "..\\")) {
return null;
}
srcfile = new File(path);
if (!srcfile.exists()) { if (!srcfile.exists()) {
// System.out.println("文件不存在"); // System.out.println("文件不存在");
return null; return null;
...@@ -233,8 +237,11 @@ public final class ImageUtil { ...@@ -233,8 +237,11 @@ public final class ImageUtil {
bufferedImages.add(ImageUtil.resize(paths.get(i), 100, 100, true)); bufferedImages.add(ImageUtil.resize(paths.get(i), 100, 100, true));
realPaths.add(paths.get(i)); realPaths.add(paths.get(i));
} else { } else {
String path1 = GConstants.FILE_UPLOAD_DIR + paths.get(i);
f = new File(GConstants.FILE_UPLOAD_DIR + paths.get(i)); f = new File(path1);
if (StrUtil.contains(path1, "../")||StrUtil.contains(path1, "..\\")) {
continue;
}
if (f.exists()) { if (f.exists()) {
j++; j++;
realPaths.add(GConstants.FILE_UPLOAD_DIR + paths.get(i)); realPaths.add(GConstants.FILE_UPLOAD_DIR + paths.get(i));
...@@ -315,7 +322,11 @@ public final class ImageUtil { ...@@ -315,7 +322,11 @@ public final class ImageUtil {
if (StrUtil.contains(baseDatePath, "../")||StrUtil.contains(baseDatePath, "..\\")) { if (StrUtil.contains(baseDatePath, "../")||StrUtil.contains(baseDatePath, "..\\")) {
return null; return null;
} }
File baseUploadDir = new File(GConstants.FILE_UPLOAD_DIR, baseDatePath); String path = GConstants.FILE_UPLOAD_DIR + baseDatePath;
if (StrUtil.contains(path, "../")||StrUtil.contains(path, "..\\")) {
return null;
}
File baseUploadDir = new File(path);
if (!baseUploadDir.exists()) {// 如果文件夹不存在则创建 if (!baseUploadDir.exists()) {// 如果文件夹不存在则创建
baseUploadDir.mkdirs(); baseUploadDir.mkdirs();
......
...@@ -37,12 +37,12 @@ public class PlanUtil { ...@@ -37,12 +37,12 @@ public class PlanUtil {
public static List<ConnectionPlan> planlist(String fileName,String filePath){ public static List<ConnectionPlan> planlist(String fileName,String filePath){
//读取文件 //读取文件
try { try {
if (StrUtil.contains(filePath, "../")||StrUtil.contains(filePath, "..\\")||
StrUtil.contains(fileName, "../")||StrUtil.contains(fileName, "..\\")) {
return null;
}
//获取目标文件的绝对路径 //获取目标文件的绝对路径
String fullFileName = GConstants.FILE_UPLOAD_DIR+filePath; String fullFileName = GConstants.FILE_UPLOAD_DIR+filePath;
if (StrUtil.contains(fullFileName, "../")||StrUtil.contains(fullFileName, "..\\")) {
return null;
}
InputStream in = null; InputStream in = null;
in = new FileInputStream(fullFileName); in = new FileInputStream(fullFileName);
ImportExcel ei = new ImportExcel(fileName,in, 1, 0); ImportExcel ei = new ImportExcel(fileName,in, 1, 0);
......
package com.ejweb.core.util.ireport; package com.ejweb.core.util.ireport;
import cn.hutool.core.util.StrUtil;
import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.JasperReport;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
...@@ -85,7 +86,11 @@ public class JRView extends JasperReportsMultiFormatView { ...@@ -85,7 +86,11 @@ public class JRView extends JasperReportsMultiFormatView {
@Override @Override
public InputStream getInputStream() throws IOException { public InputStream getInputStream() throws IOException {
return new FileInputStream(String.valueOf(model.get("url"))); String url = String.valueOf(model.get("url"));
if (StrUtil.contains(url,"../")||StrUtil.contains(url,"..\\")) {
throw new RuntimeException("文件路径不合法");
}
return new FileInputStream(url);
} }
}); });
} }
......
...@@ -307,8 +307,11 @@ public class UploadController { ...@@ -307,8 +307,11 @@ public class UploadController {
// 设置Content-Disposition // 设置Content-Disposition
response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\""); response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\"");
// 获取目标文件的绝对路径 // 获取目标文件的绝对路径
// String fullFileName = GConstants.FILE_UPLOAD_DIR + bean.getPath(); String fullFileName = GConstants.FILE_UPLOAD_DIR + bean.getPath();
File downloadFile = new File(GConstants.FILE_UPLOAD_DIR, bean.getPath()); if(StrUtil.contains(fullFileName,"../")||StrUtil.contains(fullFileName,"..\\")) {
throw new RuntimeException("文件路径异常!");
}
File downloadFile = new File(fullFileName);
LOG.error("文件下载地址:" + downloadFile.getAbsolutePath()); LOG.error("文件下载地址:" + downloadFile.getAbsolutePath());
System.out.println("文件下载地址:" + downloadFile.getAbsolutePath()); System.out.println("文件下载地址:" + downloadFile.getAbsolutePath());
// 读取文件 // 读取文件
...@@ -420,16 +423,19 @@ public class UploadController { ...@@ -420,16 +423,19 @@ public class UploadController {
directory.createDocument("WordDocument", bais); directory.createDocument("WordDocument", bais);
// 文件保存地址 // 文件保存地址
File uploadFilePath = new File(GConstants.FILE_UPLOAD_DIR, filePath); String path = GConstants.FILE_UPLOAD_DIR + filePath;
if (StrUtil.contains(path,"../")||StrUtil.contains(path,"..\\")) {
throw new RuntimeException("文件路径非法");
}
File uploadFilePath = new File(path);
if (uploadFilePath.exists()) { if (uploadFilePath.exists()) {
return responseBean; return responseBean;
} }
String path = GConstants.FILE_UPLOAD_DIR + fileDir;
if (StrUtil.contains(filePath,"../")||StrUtil.contains(filePath,"..\\") if (StrUtil.contains(path,"../")||StrUtil.contains(path,"..\\")) {
||StrUtil.contains(fileDir,"../")||StrUtil.contains(fileDir,"..\\")) {
throw new RuntimeException("文件路径非法"); throw new RuntimeException("文件路径非法");
} }
File baseUploadDir = new File(GConstants.FILE_UPLOAD_DIR, fileDir); File baseUploadDir = new File(path);
if (!baseUploadDir.exists()) {// 如果文件夹不存在则创建 if (!baseUploadDir.exists()) {// 如果文件夹不存在则创建
baseUploadDir.mkdirs(); baseUploadDir.mkdirs();
} }
......
...@@ -356,7 +356,11 @@ public class UploadService extends BaseService<UploadDao>{ ...@@ -356,7 +356,11 @@ public class UploadService extends BaseService<UploadDao>{
} }
String basePath = moduleName+GConstants.FS+extesionName.replaceAll("\\.", "")+GConstants.FS; String basePath = moduleName+GConstants.FS+extesionName.replaceAll("\\.", "")+GConstants.FS;
// 上传文件基本地址 // 上传文件基本地址
File baseUploadDir = new File(GConstants.FILE_UPLOAD_DIR, baseDatePath+GConstants.FS+GConstants.FILE_IMAGE_ACTUALS+GConstants.FS+basePath); String path = GConstants.FILE_UPLOAD_DIR + baseDatePath + GConstants.FS + GConstants.FILE_IMAGE_ACTUALS + GConstants.FS + basePath;
if(StrUtil.contains(path,"../")||StrUtil.contains(path, "..\\")) {
throw new RuntimeException("文件路径不正确");
}
File baseUploadDir = new File(path);
if(!baseUploadDir.exists()){// 如果文件夹不存在则创建 if(!baseUploadDir.exists()){// 如果文件夹不存在则创建
baseUploadDir.mkdirs(); baseUploadDir.mkdirs();
} }
...@@ -374,7 +378,11 @@ public class UploadService extends BaseService<UploadDao>{ ...@@ -374,7 +378,11 @@ public class UploadService extends BaseService<UploadDao>{
// +System.currentTimeMillis()+":"+Util.getRandom(100, 999)); // +System.currentTimeMillis()+":"+Util.getRandom(100, 999));
// 文件保存地址 // 文件保存地址
File uploadFilePath = new File(baseUploadDir, md5); String path2 = baseUploadDir + md5;
if(StrUtil.contains(path2,"../")||StrUtil.contains(path2, "..\\")) {
throw new RuntimeException("文件路径不正确");
}
File uploadFilePath = new File(path2);
LOG.info("原文件服务器绝对路径:"+uploadFilePath); LOG.info("原文件服务器绝对路径:"+uploadFilePath);
// 将数据保存到指定文件 // 将数据保存到指定文件
os = new FileOutputStream(uploadFilePath); os = new FileOutputStream(uploadFilePath);
...@@ -396,9 +404,12 @@ public class UploadService extends BaseService<UploadDao>{ ...@@ -396,9 +404,12 @@ public class UploadService extends BaseService<UploadDao>{
int with = GConstants.getIntValue("file.image.thumb.width", 640); int with = GConstants.getIntValue("file.image.thumb.width", 640);
int height = GConstants.getIntValue("file.image.thumb.height", 640); int height = GConstants.getIntValue("file.image.thumb.height", 640);
if(image.getWidth()>with || image.getHeight()>height){ if(image.getWidth()>with || image.getHeight()>height){
String path1 = GConstants.FILE_UPLOAD_DIR +
File baseUploadThumbsDir = new File(GConstants.FILE_UPLOAD_DIR, baseDatePath + GConstants.FS + GConstants.FILE_IMAGE_THUMBS + GConstants.FS + basePath;
baseDatePath+GConstants.FS+GConstants.FILE_IMAGE_THUMBS+GConstants.FS+basePath); if (StrUtil.contains(path1,"../")||StrUtil.contains(path1, "..\\")) {
throw new RuntimeException("文件路径不正确");
}
File baseUploadThumbsDir = new File(path1);
if(!baseUploadThumbsDir.exists()){// 如果文件夹不存在则创建 if(!baseUploadThumbsDir.exists()){// 如果文件夹不存在则创建
baseUploadThumbsDir.mkdirs(); baseUploadThumbsDir.mkdirs();
} }
......
...@@ -737,7 +737,10 @@ public class AirlineVerifyController { ...@@ -737,7 +737,10 @@ public class AirlineVerifyController {
response.setHeader("Content-Disposition", "attachment; filename=" + downloadFileName); response.setHeader("Content-Disposition", "attachment; filename=" + downloadFileName);
//获取目标文件的绝对路径 //获取目标文件的绝对路径
String fullFileName = GConstants.FILE_UPLOAD_DIR + uploadFileBean.getPath(); String fullFileName = GConstants.FILE_UPLOAD_DIR + uploadFileBean.getPath();
if(StrUtil.contains(fullFileName,"../")||StrUtil.contains(fullFileName,"..\\")){
throw new RuntimeException("文件名包含非法字符");
}
//读取文件 //读取文件
in = new FileInputStream(fullFileName); in = new FileInputStream(fullFileName);
out = response.getOutputStream(); out = response.getOutputStream();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment