您的位置:首页 > 运维架构 > Shell

FH Admin框架WebShell漏洞发现

2018-02-24 11:17 2536 查看
经过分析发现,网上广为流传的FH Admin框架(SSM框架 SSM项目源码 SSM源码 fh admin模版下载,fh adjava框架整合Springmvc+mybatis+shiro+bootstrap)可能存在webshell 漏洞。
如果发现使用该框架下面包含如下文件
plugins/uploadify/uploadFile.jsp,即在项目下面存在文件夹plugins,其下面存在文件夹uploadify,而uploadify文件夹下面同时存在uploadFile.jsp文件;那么该项目非常有可能存在webshell 漏洞。
uploadFile.jsp文件内容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.*, java.util.*, org.apache.commons.fileupload.*, java.util.*" %>
<%@ page import="org.apache.commons.fileupload.disk.*, org.apache.commons.fileupload.servlet.*" %>
<%!

public void upload(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
String savePath = this.getServletConfig().getServletContext().getRealPath("");
savePath = savePath + request.getParameter("uploadPath");
File f1 = new File(savePath);
//这里接收了uploadPath的值  System.out.println(request.getParameter("uploadPath"));
if (!f1.exists()) {
f1.mkdirs();
}
DiskFileItemFactory fac = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(fac);
upload.setHeaderEncoding("utf-8");
List fileList = null;
try {
fileList = upload.parseRequest(request);
} catch (FileUploadException ex) {
return;
}

String fileNmae = request.getParameter("fileNmae");
Iterator<FileItem> it = fileList.iterator();
String name = "";
String extName = "";
while (it.hasNext()) {
FileItem item = it.next();
if (!item.isFormField()) {
name = item.getName();
long size = item.getSize();
String type = item.getContentType();
//System.out.println(size + " " + type);
if (name == null || name.trim().equals("")) {
continue;
}

// 扩展名格式:
if (name.lastIndexOf(".") >= 0) {
extName = name.substring(name.lastIndexOf("."));
}

File file = null;
if(null != fileNmae && !"".equals(fileNmae)){
file = new File(savePath + fileNmae);
}else{
do {
if(null != fileNmae && !"".equals(fileNmae)){
file = new File(savePath + fileNmae);
}else{
name = new java.text.SimpleDateFormat("yyyyMMddhhmmss").format(new Date());	//获取当前日期
name = name + (int)(Math.random()*90000+10000);
file = new File(savePath + name + extName);
}
} while (file.exists());
}

File saveFile = new File(savePath + name + extName);
try {
item.write(saveFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
response.getWriter().print((name.trim() + extName.trim()).trim());
}
%>
<%
upload(request, response);
%>
分析此文件源码,访问此文件,可以上传任意文件到服务器上,这就是一种典型的webshell漏洞,webshell就是一种可以在web服务器上执行的后台脚本或者命令执行环境,黑客通过入侵网站上传webshell后获得服务器的执行操作权限,比如执行系统命令、窃取用户数据、删除web页面、修改主页等,其危害不言而喻。
该漏洞如何预防和杜绝:
方法一:最直接,直接删除uploadFile.jsp文件;
方法二:如果有用到uploadFile.jsp文件,可以修改其保存文件源码,进行文件类型控制,防止上传jsp,asp,aspx,php等可执行文件,同时对文件保存路径进行限制,对上传文件进行访问控制;
方法三:对上传文件进行过滤,防止上传jsp,asp,aspx,php等可执行文件。
总结:针对于服务端的文件上传功能,尽量不要暴露上传功能到外网。如果是需要外网上传文件,一定要进行访问控制、类型控制和执行监控。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息