2012-08-16 3 views
0

Nous avons été récemment infectés par le virus thumbs.db2 qui a créé des raccourcis vers tous nos documents Word et Excel sur nos lecteurs réseau et cache les vrais fichiers. J'ai été capable d'écrire du code pour parcourir tout le dossier et trouver les raccourcis et supprimer, mais je dois être capable d'afficher les fichiers cachés que j'ai été incapable d'atteindre.Supprimer les liens et afficher les fichiers cachés C#

Mon code est ci-dessous, écrit rapidement si s'il vous plaît être gentil :)

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(); 
    } 

Comment puis-je Démasquer les fichiers C#

Toute aide serait grandement appriciated.

Cordialement Sp

+0

« que je suis incapable d'atteindre. » - Quel est le problème exactement? –

+0

Alors, quelle est votre vraie question? Comment [afficher les fichiers] (http://msdn.microsoft.com/en-us/library/system.io.file.setattributes.aspx)? – Gene

+0

Désolé, je cherche à afficher le fichier dans C#. – Steven

Répondre

2

Comme vous pouvez le voir dans MSDN il est facile de supprimer l'attribut caché du fichier:

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

Mais si vous n'avez pas accès à le faire ou est-il un autre problèmes, veuillez l'expliquer dans votre question.

+0

Nous avons eu un virus qui a créé 28 000 raccourcis et cacher les vrais fichiers. C'est ce que j'étais après, je ne sais pas pourquoi je ne pouvais pas trouver cela .. Merci – Steven

0

Pour toute personne qui a la même question c'est le code que nous avons utilisé pour supprimer les liens et afficher les fichiers

using System; 

utilisant System.Collections.Generic; en utilisant System.Linq; en utilisant System.Text; en utilisant IWshRuntimeLibrary; en utilisant System.IO; en utilisant System.Security.Principal;

namespace HiddenFilesHow { en utilisant Microsoft.Win32.SafeHandles; classe 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

Neat ... mais

del/S * .xls.lnk

del/S * .doc.lnk

fait le tour aussi. Aussi

attrib -H/S * .doc

attrib -H/S * .xls

1

Un problème avec:

del /S *.xls.lnk 

del /S *.doc.lnk 

does the trick too. Also 

attrib -H /S *.doc 

attrib -H /S *.xls 

Ce malware modifie également des raccourcis existants pour inclure l'appel à thumbs.db2. Cette méthode nécessiterait également de restaurer les fichiers .LNK existants à partir de la sauvegarde! Alternativement (comme je prévois de le faire), prenez le code ci-dessus et ajoutez un contrôle pour les fichiers LNK existants - basé sur la date/heure de création et/ou l'absence d'un fichier caché dans le même répertoire avec le nom correspondant Fichier LNK.

En outre, pour ceux qui ont ce problème en attente d'une entreprise AV pour comprendre cela ... Remplacer les pouces.db2 avec le fichier fictif et le verrouillage des permissions ntfs semble arrêter l'exécution sans que le malware ne change de nom de fichier comme certains l'ont mentionné.

+0

Il a également commencé à créer des raccourcis pour les fichiers exe. Bah – Steven

0

S'il vous plaît vérifier également les chemins d'autres fichiers .lnk en vous partage réseau

La version de ce virus, nous avons non seulement créé des fichiers .xls.lnk et doc.lnk fichiers, il a également modifié les fichiers LNK existants

+0

Nous avons eu le même problème et il est maintenant ré infecté comme thumbs.dbh. – Steven

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

qui devrait le faire, je pense que

Questions connexes