FCKeditor.Net_2.2安全增强版.rar
FCKEditor是一款功能强大的在线编辑器,但美中不足的是该控件存在严重的安全漏洞;攻击者可利用该漏洞上传木马程序,严重的危害了网站的安全。本修改版对上传文件进行了严格限制,去除了该漏洞。
FCKEditor是一款功能强大的在线编辑器,但美中不足的是该控件存在严重的安全漏洞;攻击者可利用该漏洞上传木马程序,严重的危害了网站的安全。本修改版对上传文件进行了严格限制,去除了该漏洞。
修改前:攻击者可通过http://localhost/FCKeditor/editor/filemanager/browser/default/browser.html?Type=news&Connector=connectors/aspx/connector.aspx上传任意文件。

Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Web;

namespace FredCK.FCKeditorV2


{
class SafeCheck

{

说明#region 说明

/**//// <summary>
/// 2008.5.7 cyq建立;检查上传文件类型,确保安全;
///

/**//* 请保留该说明文字,以便可以得到技术支持!

1 本FCKEditor修改了源程序严重的上传漏洞,该漏洞可导致攻击者上传木马程序。

2 本程序版权归http://www.fckeditor.net/所有

3 本程序限于学习研究使用,本人不对该程序使用的一切后果负责

修改人:程银强

支持:http://aqiang.cnblogs.com

http://www.xitieshi.cn

2008.5.7
*/


/**//// </summary>
#endregion

属性#region 属性
private int _maxFileSize;
public int MaxFileSize

{

set
{ _maxFileSize = value; }
}


/**//// <summary>
/// 形式"gif|jpg|bmp|png|zip|rar"
/// </summary>
private string _allowFileExtens;
public string AllowFileExtens

{

set
{ _allowFileExtens = value; }
}
#endregion

方法#region 方法
protected string CaculatorSize(int s)

{
if (s < 1024)

{
return s + " B";
}
if (s / 1024 < 1024)

{
return s / 1024 + " KB";
}
if (s / 1024 / 1024 < 1024)

{
return s / 1024 / 1024 + " M";
}
if (s / 1024 / 1024 / 1024 < 1024)

{
return s / 1024 / 1024 / 1024 + " G";
}
else

{
return "";
}
}
protected string GetFileExtens(string p)

{
string fileName = p.Substring(p.LastIndexOf("\\")+1);
return fileName.Split('.')[1];
}
protected bool IsAllowFileExtens(string allowExtens, string nowExtens)

{
if (allowExtens.IndexOf(nowExtens) > -1)

{
return true;
}
else

{
return false;
}
}

protected Hashtable GetStandardExtentsFeater()

{
Hashtable extensTable = new Hashtable();
extensTable.Add("gif", "image/gif");
extensTable.Add("jpg", "image/pjpeg");
extensTable.Add("jpeg", "image/pjpeg");
extensTable.Add("bmp", "image/bmp");
extensTable.Add("png", "image/x-png");
extensTable.Add("tif", "image/tiff");
extensTable.Add("tiff", "image/tiff");
extensTable.Add("zip", "application/x-zip-compressed");
extensTable.Add("rar", "application/octet-stream");
return extensTable;
}

protected string GetExtentsFeatureString(string FileExtents)

{
Hashtable standardTable = GetStandardExtentsFeater();
string FileFeature = "";
foreach (DictionaryEntry de in standardTable)

{
if (de.Key.ToString() == FileExtents)

{
FileFeature = de.Value.ToString();
}
}
return FileFeature;
}

public bool IsRightFile(HttpPostedFile postedFile)

{
string nowExtens = GetFileExtens(postedFile.FileName);
string standardFeature = GetExtentsFeatureString(nowExtens);
if (postedFile.ContentType == standardFeature)

{
return true;
}
else

{
return false;
}
}
#endregion
}
}

源码下载
修改前:攻击者可通过http://localhost/FCKeditor/editor/filemanager/browser/default/browser.html?Type=news&Connector=connectors/aspx/connector.aspx上传任意文件。
修改内容
1 增加了SafeCheck.cs文件,用来检查上传文件是否合法
2 修改了FileBrowserConnector.cs,Uploader.cs文件;在上传时检查文件类型。
2008.5.7
新增文件SafeCheck.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Web;
namespace FredCK.FCKeditorV2

{
class SafeCheck
{
说明#region 说明
/**//// <summary>
/// 2008.5.7 cyq建立;检查上传文件类型,确保安全;
/// 
/**//* 请保留该说明文字,以便可以得到技术支持!
1 本FCKEditor修改了源程序严重的上传漏洞,该漏洞可导致攻击者上传木马程序。
2 本程序版权归http://www.fckeditor.net/所有
3 本程序限于学习研究使用,本人不对该程序使用的一切后果负责
修改人:程银强
支持:http://aqiang.cnblogs.com
http://www.xitieshi.cn
2008.5.7
*/

/**//// </summary>
#endregion
属性#region 属性
private int _maxFileSize;
public int MaxFileSize
{
set
{ _maxFileSize = value; }
}

/**//// <summary>
/// 形式"gif|jpg|bmp|png|zip|rar"
/// </summary>
private string _allowFileExtens;
public string AllowFileExtens
{
set
{ _allowFileExtens = value; }
}
#endregion
方法#region 方法
protected string CaculatorSize(int s)
{
if (s < 1024)
{
return s + " B";
}
if (s / 1024 < 1024)
{
return s / 1024 + " KB";
}
if (s / 1024 / 1024 < 1024)
{
return s / 1024 / 1024 + " M";
}
if (s / 1024 / 1024 / 1024 < 1024)
{
return s / 1024 / 1024 / 1024 + " G";
}
else
{
return "";
}
}
protected string GetFileExtens(string p)
{
string fileName = p.Substring(p.LastIndexOf("\\")+1);
return fileName.Split('.')[1];
}
protected bool IsAllowFileExtens(string allowExtens, string nowExtens)
{
if (allowExtens.IndexOf(nowExtens) > -1)
{
return true;
}
else
{
return false;
}
}
protected Hashtable GetStandardExtentsFeater()
{
Hashtable extensTable = new Hashtable();
extensTable.Add("gif", "image/gif");
extensTable.Add("jpg", "image/pjpeg");
extensTable.Add("jpeg", "image/pjpeg");
extensTable.Add("bmp", "image/bmp");
extensTable.Add("png", "image/x-png");
extensTable.Add("tif", "image/tiff");
extensTable.Add("tiff", "image/tiff");
extensTable.Add("zip", "application/x-zip-compressed");
extensTable.Add("rar", "application/octet-stream");
return extensTable;
}
protected string GetExtentsFeatureString(string FileExtents)
{
Hashtable standardTable = GetStandardExtentsFeater();
string FileFeature = "";
foreach (DictionaryEntry de in standardTable)
{
if (de.Key.ToString() == FileExtents)
{
FileFeature = de.Value.ToString();
}
}
return FileFeature;
}
public bool IsRightFile(HttpPostedFile postedFile)
{
string nowExtens = GetFileExtens(postedFile.FileName);
string standardFeature = GetExtentsFeatureString(nowExtens);
if (postedFile.ContentType == standardFeature)
{
return true;
}
else
{
return false;
}
}
#endregion
}
}

源码下载

浙公网安备 33010602011771号