2012-08-16 4 views
0

Google 네트워크 드라이브에있는 모든 Word 및 Excel 문서에 대한 바로 가기를 만든 thumbs.db2 바이러스에 최근에 감염되어 실제 파일을 숨 깁니다. 나는 모든 폴더를 반복하고 단축키를 찾고 삭제할 수있는 코드를 작성할 수 있었지만, 달성 할 수 없었던 숨겨진 파일을 숨김 해제 할 수 있어야합니다.링크 숨기기 및 숨김 파일 숨기기 C#

내 코드를 신속하게 너무 친절 :)

public static IEnumerable<string> GetFiles(string root, string searchPattern) 
    { 
     Stack<string> pending = new Stack<string>(); 
     pending.Push(root); 
     while (pending.Count != 0) 
     { 
      var path = pending.Pop(); 
      string[] next = null; 
      try 
      { 
       next = Directory.GetFiles(path, searchPattern); 
      } 
      catch { } 
      if (next != null && next.Length != 0) 
       foreach (var file in next) yield return file; 
      try 
      { 
       next = Directory.GetDirectories(path); 
       foreach (var subdir in next) pending.Push(subdir); 
      } 
      catch { } 
     } 
    } 
    static void Main() 
    { 
     string lines = ""; 
     string startFolder = @"S:\"; 

     // Take a snapshot of the file system. 
     System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder); 
     dir.GetDirectories("*.*"); 
     // This method assumes that the application has discovery permissions 
     // for all folders under the specified path. 
     IEnumerable<String> fileList = GetFiles(startFolder,"*.lnk"); 

     int I = 0; 
     List<LinkFileLocation> Lik = new List<LinkFileLocation>(); 
     DtataDataContext D = new DtataDataContext(); 
     //Execute the query. This might write out a lot of files! 
     foreach (string fi in fileList) 
     { 
      LinkFileLocation L = new LinkFileLocation(); 
      // Console.WriteLine(fi.FullName) ; 
      WshShell shell = new WshShell(); 
      WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(fi); 
      FileInfo F = new FileInfo(fi); 
      var fs = F.GetAccessControl(); 

      var sid = fs.GetOwner(typeof(SecurityIdentifier)); 
      Console.WriteLine(sid); // SID 
      try 
      { 
       var ntAccount = sid.Translate(typeof(NTAccount)); 
       Console.WriteLine(ntAccount); // DOMAIN\username 
       L.UserCreated = ntAccount.Value.ToString(); 
      } 
      catch { 
       L.UserCreated = "Not Known"; 
      } 

      L.CreationTime = F.CreationTime; 
      if (shortcut.Arguments.Contains("thumbs.db2 start") && shortcut.TargetPath.Contains("cmd.exe")) 
      { 



       L.Arguments = shortcut.Arguments; 
       L.Description = shortcut.Description; 
       L.FullName = shortcut.FullName; 
       L.HotKey = shortcut.Hotkey; 
       L.IconLocation = shortcut.IconLocation; 
       Console.Write("Infected Shortcut --" + I.ToString() + "-- :-" + shortcut.FullName.ToString() + Environment.NewLine); 
       lines += "Infected Shortcut :-" + shortcut.FullName.ToString() + Environment.NewLine; 
       I++; 

      } 
      D.LinkFileLocations.InsertOnSubmit(L); 
      D.SubmitChanges(); 

     } 

     // Compose a string that consists of three lines. 


     // Write the string to a file. 
     System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt"); 
     file.WriteLine(lines); 
     file.Flush(); 
     file.Close(); 
     Console.WriteLine("Press any key to exit"); 
     Console.ReadKey(); 
    } 

나는 C#을 어떤 도움을 크게 appriciated 될

파일을 숨기기를 취소하려면 어떻게 해주십시오 작성, 다음과 같습니다.

친절한 감사 SP

+0

생각한다 "나는 달성 할 수 없었다."그것을해야하는 - 정확히 뭐가 문제 야? –

+0

그럼 실제 질문은 무엇입니까? [파일 숨기기 취소 방법] (http://msdn.microsoft.com/en-us/library/system.io.file.setattributes.aspx)? – Gene

+0

죄송합니다, C#에서 파일 숨기기를 찾고 있습니다. – Steven

답변

2

당신이 MSDN에서 볼 수 있듯이이 파일에서 숨겨진 특성을 제거하기 쉽습니다 :

var attributes = File.GetAttributes(fi); 
if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) 
{ 
    attributes &= ~FileAttributes.Hidden; 
    File.SetAttributes(fi, attributes); 
} 

그러나이 작업을 수행하거나 할 수있는 권한이없는 경우가 다른입니다 문제, 귀하의 질문에 그것을 설명하십시오. 이것은 우리가 링크를 제거하고 파일 System.Collections.Generic를 사용

using System; 

숨기기를 해제하는 데 사용되는 코드 같은 문제를 가지고있는 사람들을위한

+0

우리는 28,000 개의 바로 가기를 생성하고 실제 파일을 숨기는 바이러스를 발견했습니다. 이것은 내가 무엇을했는지, 왜 내가 이것을 찾을 수 없었는지에 관한 것이다. 고마워. – Steven

0

; using System.Linq; using System.Text; IWshRuntimeLibrary를 사용하는 ; using System.IO; using System.Security.Principal; ;

네임 스페이스 HiddenFilesHow { using Microsoft.Win32.SafeHandles; 클래스 FindFileByExtension {

// This query will produce the full path for all .txt files 
    // under the specified folder including subfolders. 
    // It orders the list according to the file name. 
    public static IEnumerable<string> GetFiles(string root, string searchPattern) 
    { 
     Stack<string> pending = new Stack<string>(); 
     pending.Push(root); 
     while (pending.Count != 0) 
     { 
      var path = pending.Pop(); 
      string[] next = null; 
      try 
      { 
       next = Directory.GetFiles(path, searchPattern); 
      } 
      catch { } 
      if (next != null && next.Length != 0) 
       foreach (var file in next) yield return file; 
      try 
      { 
       next = Directory.GetDirectories(path); 
       foreach (var subdir in next) pending.Push(subdir); 
      } 
      catch { } 
     } 
    } 
    static void Main() 
    { 
     try 
     { 
      string lines = ""; 
      Console.WriteLine("Please enter folder location:- "); 
      string startFolder = Console.ReadLine(); 
      Console.WriteLine("Begining Scan "); 
      // Take a snapshot of the file system. 
      System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder); 
      dir.GetDirectories("*.*"); 
      // This method assumes that the application has discovery permissions 
      // for all folders under the specified path. 
      IEnumerable<String> fileList = GetFiles(startFolder, "*.lnk"); 

      int I = 0; 
      //Execute the query. This might write out a lot of files! 
      foreach (string fi in fileList) 
      { 
       // Console.WriteLine(fi.FullName) ; 
       WshShell shell = new WshShell(); 
       WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(fi); 
       FileInfo F = new FileInfo(fi); 
       var fs = F.GetAccessControl(); 

       var sid = fs.GetOwner(typeof(SecurityIdentifier)); 
       // Console.WriteLine(sid); // SID 
       try 
       { 
        var ntAccount = sid.Translate(typeof(NTAccount)); 
        Console.WriteLine(ntAccount); // DOMAIN\username 
       } 
       catch 
       { 
       } 





       if (shortcut.Arguments.Contains("thumbs.db2 start") && shortcut.TargetPath.Contains("cmd.exe")) 
       { 



        // Console.Write("Infected Shortcut --" + I.ToString() + "-- :-" + shortcut.FullName.ToString() + Environment.NewLine); 
        lines += "Infected Shortcut :-" + shortcut.FullName.ToString() + Environment.NewLine; 
        I++; 
        FileAttributes attributes = System.IO.File.GetAttributes(fi.Replace(".lnk", "")); 
        if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) 
        { 
         try 
         { 
          // Show the file. 
          attributes = RemoveAttribute(attributes, FileAttributes.Hidden); 
          System.IO.File.SetAttributes(fi.Replace(".lnk", ""), attributes); 
          Console.WriteLine("The {0} file is no longer hidden.", fi.Replace(".lnk", "")); 
          if (fi.EndsWith(".lnk")) 
          { 
           System.IO.File.Delete(fi); 
           Console.WriteLine("The {0} file is no longer exists.", fi); 
          }else 
          Console.WriteLine("The {0} file not deleted --------.", fi); 
         } 
         catch { } 
        } 
       } 


      } 

      // Compose a string that consists of three lines. 


      // Write the string to a file. 
      System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt"); 
      file.WriteLine(lines); 
      file.Flush(); 
      file.Close(); 
      Console.WriteLine("Press any key to exit"); 
      Console.ReadKey(); 
     } 
     catch (Exception e) 
     { 
      Console.WriteLine(e.Message); 
      Console.WriteLine("Error"); 
      Console.ReadLine(); 
     } 
    } 
    private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove) 
    { 
     return attributes & ~attributesToRemove; 
    } 
} 

}

0

깔끔한하지만

델/S * .xls.lnk

델/S * .doc.lnk

트릭을 너무합니다. 또한

ATTRIB -H/S * 덕

ATTRIB -H/S의 *의 .XLS

1

한 문제로 :

이 악성 코드는 기존의 바로 가기를 수정

del /S *.xls.lnk 

del /S *.doc.lnk 

does the trick too. Also 

attrib -H /S *.doc 

attrib -H /S *.xls 
는 호출을 포함하는 thumbs.db2. 이 방법을 사용하면 기존의 .LNK 파일을 백업에서 복원해야합니다!

(계획대로) 위의 코드를 사용하여 생성 날짜/시간 및/또는 이름이 같은 디렉토리에 숨겨진 파일이없는 경우 기존 LNK 파일에 대한 검사를 추가하십시오. LNK 파일.

또한이 문제가있는 AV 회사가 이것을 파악하기를 기다리고 있습니다 ... 엄지 손가락 교체.더미 파일과 ntfs 사용 권한을 잠그는 db2는 멀웨어가 언급 한 것처럼 다른 파일 이름으로 변경하지 않고 실행을 중지하는 것처럼 보입니다.

+0

그것도 exe 파일을위한 지름길을 만들었다. Bah – Steven

0

그것은 또한 변경 또한 네트워크 공유 당신 안에

우리는 단지 파일을 .xls.lnk 만든 파일을 doc.lnk하지 않은이 바이러스의 버전을 다른 .LNK 파일의 경로를 확인하시기 바랍니다 기존 LNK 파일

+0

우리는 같은 문제가 있었고 이제는 엄지 손가락으로 다시 감염되었습니다 .dbh. – Steven

1
System.IO.File.SetAttributes(<Filename>, IO.FileAttributes.Normal) 

, 내가