Advertisement
Linkcabin

NanoCore Detect

Apr 13th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using Microsoft.Win32;
  6. using System.Diagnostics;
  7.  
  8. namespace DetectNanoCore
  9. {
  10.     class Program
  11.     {
  12.  
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.  
  17.             string key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography";
  18.             string serial = (string)Registry.GetValue(key, "MachineGuid", (object)"default");
  19.             int pid = Process.GetCurrentProcess().Id;
  20.             var netPid = new List<int>();
  21.             string appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), serial);
  22.             bool procdump = false;
  23.  
  24.  
  25.  
  26.  
  27.             if(Directory.Exists(appDataFolder))
  28.             {
  29.                 Console.WriteLine("GUID Folder Exists..");
  30.                 if(File.Exists(appDataFolder + "\\storage.dat") || File.Exists(appDataFolder + "\\run.dat") || Directory.Exists(appDataFolder + "\\Logs"))
  31.                 {
  32.                     Console.WriteLine("Significant Indicators to Nanocore available.");
  33.                     Process[] processlist = Process.GetProcesses();
  34.  
  35.                     foreach(Process theprocess in processlist){
  36.                         if (theprocess.Id != pid)
  37.                         {
  38.                             try
  39.                             {
  40.                                 foreach (ProcessModule module in theprocess.Modules)
  41.                                 {
  42.                                     string mod = module.FileName;
  43.                                     if (mod.Contains("Microsoft.NET"))
  44.                                     {
  45.                                         Console.WriteLine("Process has .NET Module. PID: " + theprocess.Id);
  46.                                         if (!netPid.Contains(theprocess.Id))
  47.                                         {
  48.                                             System.Diagnostics.Process process = new System.Diagnostics.Process();
  49.                                             System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  50.                                             startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
  51.                                             startInfo.FileName = "cmd.exe";
  52.                                             startInfo.Arguments = "/c strings2 -pid " + theprocess.Id + " > " + theprocess.Id + ".txt";
  53.                                             process.StartInfo = startInfo;
  54.                                             process.Start();
  55.                                             netPid.Add(theprocess.Id);
  56.                                             procdump = true;
  57.                                         }
  58.  
  59.                                     }
  60.  
  61.                                 }
  62.                             }
  63.                             catch (Exception e)
  64.                             {
  65.                                 Console.WriteLine("Process modules unable to be listed. PID: " + theprocess.Id);
  66.                             }
  67.                         }
  68.                        }
  69.  
  70.                  if(procdump == true)
  71.                  {
  72.                      System.Threading.Thread.Sleep(15000);
  73.                      foreach(int ids in netPid)
  74.                      {
  75.                          var filez = File.ReadAllText(ids + ".txt");
  76.                          if(filez.Contains("PrimaryConnectionHost") && filez.Contains("ConnectionPort") && filez.Contains("NtSetInformationProcess"))
  77.                          {
  78.                              int pos = filez.IndexOf("PrimaryConnectionHost");
  79.                              int pos2 = filez.IndexOf("ConnectionPort");
  80.                              string host = filez.Substring(pos, pos2 - pos);
  81.  
  82.                              Console.WriteLine("Suspected PID: " + ids + " has matching memory signatures for NanoCore");
  83.                              Console.WriteLine("Suspected Host connecting to\r\n: " + host);
  84.  
  85.                        
  86.  
  87.                          }
  88.  
  89.                      }
  90.                  }
  91.  
  92.  
  93.  
  94.                 }
  95.             }
  96.             Console.WriteLine("Serial for this computer: " + serial);
  97.             Console.ReadLine();
  98.  
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement