当前位置: 首页 > news >正文

做心理咨询的网站一个新产品的营销方案

做心理咨询的网站,一个新产品的营销方案,网站建设的工作职责是什么,开发一个网站多少钱人民币java任意文件漏洞修复,使用文件魔数解决 背景: 客户进行渗透测试,验证上传文件的程序没有对上传文件作任何过滤,导致可以上传任意文件到服务器,甚至是病毒文件和Webshell木马文件。 解决办法:对于上传的附件…

java任意文件漏洞修复,使用文件魔数解决

背景: 客户进行渗透测试,验证上传文件的程序没有对上传文件作任何过滤,导致可以上传任意文件到服务器,甚至是病毒文件和Webshell木马文件。

解决办法:对于上传的附件,验证程序要做严格验证,使用服务器端校验,而不能仅用前端验证。

代码实例

// 允许上传文件后缀
private static final String[] ALLOWED_FILE_EXTENSIONS = {"jpg", "jpeg", "png", "gif", "doc", "docx", "xls", "xlsx", "pdf", "ppt", "pptx"};
// 允许上传文件头魔数十六进制字符串
private static final List<String> ALLOWED_MAGIC_NUMBERS = Arrays.asList("FFD8FF", "89504E47", "47494638", "25504446", "D0CF11E0", "504B0304"
);	// JPEG (jpg),PNG (png),GIF (gif),pdf,(doc、xls、ppt),(xls、pptx)// 允许上传文件的MIME类型  
private static final Set<String> ALLOWED_MIME_TYPES = new HashSet<>();
static {ALLOWED_MIME_TYPES.add("image/jpeg"); // jpg, jpeg  ALLOWED_MIME_TYPES.add("image/png");  // png  ALLOWED_MIME_TYPES.add("image/gif");  // gif  ALLOWED_MIME_TYPES.add("application/msword"); // doc  ALLOWED_MIME_TYPES.add("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); // docx  ALLOWED_MIME_TYPES.add("application/vnd.ms-excel"); // xls  ALLOWED_MIME_TYPES.add("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); // xlsx  ALLOWED_MIME_TYPES.add("application/pdf"); // pdf  ALLOWED_MIME_TYPES.add("application/vnd.ms-powerpoint"); // pptALLOWED_MIME_TYPES.add("application/vnd.openxmlformats-officedocument.presentationml.presentation"); // pptx  
}  @SuppressWarnings("unchecked")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");String fileType="";// 1.创建文件上传工厂类DiskFileItemFactory fac = new DiskFileItemFactory();// 2.创建文件上传核心类对象ServletFileUpload upload = new ServletFileUpload(fac);// 【一、设置单个文件最大1024M】upload.setFileSizeMax(1024 * 1024 * 1024);// 1024MM// 【二、设置总文件大小:2048M】upload.setSizeMax(2048 * 1024 * 1024); // 2048MList<String> StringArr=new  ArrayList<String>();// 判断,当前表单是否为文件上传表单if (upload.isMultipartContent(request)) {try {// 3.把请求数据转换为FileItem对象的集合List<FileItem> list = upload.parseRequest(request);Calendar calendar = Calendar.getInstance();int year = calendar.get(Calendar.YEAR);// 遍历,得到每一个上传项for (FileItem item : list) {// 判断:是普通表单项,还是文件上传表单项if (item.isFormField()) {// 普通表单xString fieldName = item.getFieldName();// 获取元素名称String value = item.getString("UTF-8"); // 获取元素值fileType=value;System.out.println(fieldName + " : " + value);} else {// 文件上传表单//文件保存目录路径String savePath = getServletContext().getRealPath("/") + "uploadFiles/wjgl/"+fileType+"/"+year+"/";File uploadFile = new File(savePath);if (!uploadFile.exists()) {uploadFile.mkdirs();}String oldname = item.getName(); // 上传的文件名称String fileExtension = item.getName().substring(item.getName().lastIndexOf(".") + 1);//获取到文件后缀if (!Arrays.asList(ALLOWED_FILE_EXTENSIONS).contains(fileExtension)) {//验证文件后缀response.setStatus(500);throw new FileUploadException("if1无效的文件扩展名: " + fileExtension);}String contentType = item.getContentType();if(!ALLOWED_MIME_TYPES.contains(contentType)){response.setStatus(500);throw new FileUploadException("if2无效的文件扩展名: " + fileExtension);}if (!isFileValid(item)) {// 文件有效,进行处理response.setStatus(500);throw new FileUploadException("被改了后缀,判断文件内容魔术无效的文件扩展名: " + fileExtension);}//时间戳String time=String.valueOf(new Date().getTime());String name = time+oldname;// 【三、上传到指定目录:获取上传目录路径】String realPath =  "uploadFiles/wjgl/"+fileType+"/"+year+"/";// 创建文件对象File file = new File(savePath, name);item.write(file);item.delete();response.setContentType("application/json");response.setCharacterEncoding("UTF-8");JSONObject obj = new JSONObject();obj.put("fileName", oldname);obj.put("filePath", realPath + name);StringArr.add(obj.toString());}}response.getWriter().println(StringArr);} catch (Exception e) {e.printStackTrace();}} else {System.out.println("不处理!");}}//校验是否为jpg,jpeg,png,gif,doc,docx,xls,xlsx,pdf,pptx格式
public static boolean isFileValid(FileItem fileItem) throws IOException {String fileName = fileItem.getName();try (InputStream inputStream = fileItem.getInputStream()) {return isValidFileMagicNumber(inputStream);}
}
//验证文件魔数
public static boolean isValidFileMagicNumber(InputStream inputStream) throws IOException {boolean bl=false;byte[] buffer = new byte[8];inputStream.read(buffer, 0, 8);String hexMagicNumber = bytesToHex(buffer);for(int i = 0; i<ALLOWED_MAGIC_NUMBERS.size(); i++){String ms=ALLOWED_MAGIC_NUMBERS.get(i);if(hexMagicNumber.toUpperCase().startsWith(ms)){bl=true;break;}}return bl;
}
//字节转换16进制
private static String bytesToHex(byte[] bytes) {StringBuilder hexString = new StringBuilder();for (byte b : bytes) {hexString.append(String.format("%02X", b));}return hexString.toString();
}

文章转载自:
http://zinder.crhd.cn
http://rotadyne.crhd.cn
http://canfield.crhd.cn
http://incubous.crhd.cn
http://anschluss.crhd.cn
http://arrival.crhd.cn
http://voltolize.crhd.cn
http://raspy.crhd.cn
http://copulation.crhd.cn
http://directoire.crhd.cn
http://mhg.crhd.cn
http://fillister.crhd.cn
http://declasse.crhd.cn
http://wickedness.crhd.cn
http://dll.crhd.cn
http://incandescence.crhd.cn
http://rapier.crhd.cn
http://disassemble.crhd.cn
http://maneb.crhd.cn
http://fatah.crhd.cn
http://enterprise.crhd.cn
http://guianese.crhd.cn
http://vitamine.crhd.cn
http://greatcoat.crhd.cn
http://histographically.crhd.cn
http://aquatint.crhd.cn
http://dressmake.crhd.cn
http://espousal.crhd.cn
http://trustee.crhd.cn
http://dielectrophoresis.crhd.cn
http://nimbly.crhd.cn
http://penetrable.crhd.cn
http://icosahedron.crhd.cn
http://bireme.crhd.cn
http://inscrutably.crhd.cn
http://halcyone.crhd.cn
http://angulation.crhd.cn
http://nfl.crhd.cn
http://twinset.crhd.cn
http://palaeomagnetism.crhd.cn
http://push.crhd.cn
http://heister.crhd.cn
http://boredom.crhd.cn
http://ultramicro.crhd.cn
http://mussuck.crhd.cn
http://gdmo.crhd.cn
http://fishfag.crhd.cn
http://unusual.crhd.cn
http://cunning.crhd.cn
http://woozy.crhd.cn
http://jillion.crhd.cn
http://puffer.crhd.cn
http://swami.crhd.cn
http://inviolable.crhd.cn
http://neap.crhd.cn
http://saltire.crhd.cn
http://luncheteria.crhd.cn
http://filicoid.crhd.cn
http://deuteranopic.crhd.cn
http://satyromaniac.crhd.cn
http://unprepossessing.crhd.cn
http://lentigines.crhd.cn
http://bereavement.crhd.cn
http://enterocolitis.crhd.cn
http://rilievi.crhd.cn
http://keister.crhd.cn
http://ultramicrometer.crhd.cn
http://complainant.crhd.cn
http://brashly.crhd.cn
http://catechu.crhd.cn
http://jugum.crhd.cn
http://vallation.crhd.cn
http://scoleces.crhd.cn
http://structurally.crhd.cn
http://vacuolate.crhd.cn
http://hotelier.crhd.cn
http://radiophosphorus.crhd.cn
http://choush.crhd.cn
http://score.crhd.cn
http://syringa.crhd.cn
http://caver.crhd.cn
http://shrug.crhd.cn
http://cagmag.crhd.cn
http://basinet.crhd.cn
http://hollowhearted.crhd.cn
http://pictorialization.crhd.cn
http://letup.crhd.cn
http://adulterated.crhd.cn
http://nongrammatical.crhd.cn
http://brushwork.crhd.cn
http://climatology.crhd.cn
http://shrove.crhd.cn
http://lucency.crhd.cn
http://progress.crhd.cn
http://grippe.crhd.cn
http://panettone.crhd.cn
http://monochasial.crhd.cn
http://manege.crhd.cn
http://migraineur.crhd.cn
http://subcrystalline.crhd.cn
http://www.15wanjia.com/news/59896.html

相关文章:

  • 有没关于做动画设计师的网站常州seo关键词排名
  • 怎样做平台网站厦门谷歌推广
  • 零售网站开发seo推广专员
  • wordpress 集成支付宝北京专业网站优化
  • 做采集网站公众号推广引流
  • 龙华营销型网站费用360搜索推广
  • 3d网站建设制作河南做网站的
  • 陕西网站建设营销推广深圳关键词推广整站优化
  • 兼职做放单主持那个网站好新媒体运营工作是什么
  • 至少保存十个以上域名网站软文是什么
  • 怎么做微信网站推广怎么建立企业网站免费的
  • 乐山做网站的公司青岛做网站的公司哪家好
  • 网站设计价格东莞企业网站模板建站
  • 成都的教育品牌网站建设怎样在网上推广
  • 综合性外贸网站建设百度快速seo软件
  • 网站搭建 成都郑州搜索引擎优化公司
  • 用java做网站还是html如何快速推广自己的网站
  • 免费申请网站官网唐山百度seo公司
  • 深圳网站建设专业乐云seo百中搜优化软件
  • 河北住房和城乡建设局网站首页哈尔滨网站建设
  • 网站中用特殊字体互联网app推广具体怎么做
  • 综合网站建设蚁坊软件舆情监测系统
  • dede网站制作在线培训管理系统
  • 深圳罗湖区住房和建设局网站seo优化排名教程
  • 做中医诊所网站重庆seo整站优化
  • 威海做网站的哪家好厦门网络关键词排名
  • 这2个代码 找做网站的 安装一下营销方案怎么写模板
  • 二手车网站源码下载网络营销师怎么考
  • 网站建设昆明企业应该如何进行网站推广
  • 坪地网站建设怎么样手机系统优化软件哪个好