检测文件是否存在木马字眼

/// <summary>        

/// 检测文件是否存在木马字眼        

/// </summary>        

/// <param name="path">文件字符串路径</param>        

/// <returns>true:安全、false:危险</returns>        

private bool CheckFileSafe(string path)        

{            

    var file=new FileInfo(path);            

    var sr = file.OpenText();            

    var text = sr.ReadToEnd();            

    var DangerString =          ".getfolder|.createfolder|.deletefolder|.createdirectory|.deletedirectory|.saveas|wscript.shell|script.encode|server.|.createobject|execute|activexobject|language=|include|filesystemobject|shell.application";

         

    Array arrDangerArray = DangerString.Split('|').ToArray();            

    //var isSafe = true;           

    if (arrDangerArray.Cast<string>().Any(item => text.IndexOf(item) >= 0))            

    {                

        sr.Close();                

        sr.Dispose();                

        return false;            

    }                        

    sr.Close();            

    sr.Dispose();            

    return true;        

}

 

posted @ 2018-08-30 14:22  qishidz  阅读(272)  评论(0编辑  收藏  举报