• fckeditor文件上传漏洞(.NET)


        前一段时间,由于用了fckeditor,没有修改fckeditor的漏洞,被人家上传了木马,使得网站上出现不良信息,服务器被封半个月,心理很郁闷,所以今天把fckeditor的漏洞以及能彻底解决这些漏洞的办法写出来。

        你到网上搜索一下fckeditor漏洞,可以出现很多文章,都是关于它的很多漏洞,可能是转为他太出名了吧。漏洞太多。

        你仔细看看,所有漏洞,都是是关于一些上传文件的。原理是由于IIS对一些改名的文件解析所导致的。

        由于Fckeditor对第一次上传123.asp;123.jpg 这样的格式做了过滤。也就是IIS6解析漏洞。
        上传第一次。被过滤为123_asp;123.jpg 从而无法运行。
        但是第2次上传同名文件123.asp;123.jpg后。由于"123_asp;123.jpg"已经存在。
        文件名被命名为123.asp;123(1).jpg 123.asp;123(2).jpg这样的编号方式。
        所以。IIS6的漏洞继续执行了。。。
        然后通过抓包。获取上传后地址即可。。

        这样,就会上传一个木马了。我的网站就出现这样的漏洞,使得整台服务器被封IP。
      
        现在我想了一个办法,修改上传文件,把上传的文件自动以日期来命名。
       修改方法如下:

        首先找到FCKeditor.Net_2.6.3的源码。打开FileBrowser目录里的FileWorkerBase.cs文件。
       
        找到如下代码:
    int iErrorNumber = 0;
       int iCounter = 0;

       while ( true )
       {
        string sFilePath = System.IO.Path.Combine( sServerDir, sFileName );

        if ( System.IO.File.Exists( sFilePath ) )
        {
         iCounter++;
         sFileName =
          System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +
          "(" + iCounter + ")." +
          sExtension;

         iErrorNumber = 201;
        }
        else
        {
         oFile.SaveAs( sFilePath );
         break;
        }
       }

       TypeConfig typeConfig = this.Config.TypeConfig[resourceType] ;

       string sFileUrl = isQuickUpload ? typeConfig.GetQuickUploadPath() : typeConfig.GetFilesPath() ;
       sFileUrl += sFileName;

       this.SendFileUploadResponse( iErrorNumber, isQuickUpload, sFileUrl, sFileName );


    改成如下代码:
    int iErrorNumber = 0;
       //int iCounter = 0;

                sFileName = this.SanitizeFileName(this.getfilename() + "." + sExtension);
                string sFilePath = System.IO.Path.Combine(sServerDir, sFileName);
                oFile.SaveAs(sFilePath);


      TypeConfig typeConfig = this.Config.TypeConfig[resourceType] ;

                string sFileUrl = "uploadfile/";//isQuickUpload ? typeConfig.GetQuickUploadPath() : typeConfig.GetFilesPath();
       sFileUrl += sFileName;

    上面用到的getfilename()类是文件新的文件名。类代码如下:
            public string getfilename()
            {
                System.DateTime currentTime = new System.DateTime();
                currentTime = System.DateTime.Now;
                Random rnd = new Random();
                string rndStr = "";
                for (int i = 0; i <= 4; i++)
                {
                    rndStr += rnd.Next(10).ToString();
                }

                return currentTime.ToString("yyyyMMddhhmmssffffff") + rndStr;
            }

    这样所有上传的文件都重新命名,不会有重复,而且文件后缀是程序获得的后缀.JPG。

  • 相关阅读:
    属性选择器
    优先级
    hj_html&css
    hj_解决gpedit.msc不存在的问题
    hj_designPatterns
    hj_ssm
    hj-springmvc
    hj_mybatis
    hj_Python踩坑之旅
    hj_Python学习笔记
  • 原文地址:https://www.cnblogs.com/lear/p/2077872.html
Copyright © 2020-2023  润新知