def run(self): self.running = True while self.running: try: line = self.prompt.prompt().strip() if line == "": continue self.dispatch_line(line) # We used to catch only KeyboardException, but this prevents a # badly written command from completely killing our remote # connection. except EOFError: # We don't have a connection yet, just exit if pwncat.victim is None or pwncat.victim.client is None: break # We have a connection! Go back to raw mode pwncat.victim.state = State.RAW self.running = False except (Exception, KeyboardInterrupt): console.print_exception(width=None) continue
def run(self): """Execute the pwncat REPL. This will continue running until an :class:`InteractiveExit` exception or a :class:`EOFError` exception are raised.""" if self.prompt is None: self.setup_prompt() running = True while running: try: if self.manager.config.module: self.prompt.message = [ ( "fg:ansiyellow bold", f"({self.manager.config.module.name}) ", ), ("fg:ansimagenta bold", "pwncat"), ("", "$ "), ] else: self.prompt.message = [ ("fg:ansiyellow bold", "(local) "), ("fg:ansimagenta bold", "pwncat"), ("", "$ "), ] line = self.prompt.prompt().strip() if line == "": continue self.dispatch_line(line) # We used to catch only KeyboardException, but this prevents a # badly written command from completely killing our remote # connection. except EOFError: # C-d was pressed. Assume we want to exit the prompt. running = False except KeyboardInterrupt: # Normal C-c from a shell just clears the current prompt continue except ChannelClosed as exc: # A channel was unexpectedly closed self.manager.log( f"[yellow]warning[/yellow]: {exc.channel}: channel closed") # Ensure any existing sessions are cleaned from the manager exc.cleanup(self.manager) except pwncat.manager.InteractiveExit: # We don't want this caught below, so we catch it here # then re-raise it to be caught by the interactive method raise except (Exception, KeyboardInterrupt): console.print_exception(width=None) continue
def run(self, args): if args.module is None and pwncat.config.module is None: console.log("[red]error[/red]: no module specified") return elif args.module is None: args.module = pwncat.config.module.name # Parse key=value pairs values = {} for arg in args.args: if "=" not in arg: values[arg] = True else: name, value = arg.split("=") values[name] = value # pwncat.config.locals.update(values) config_values = pwncat.config.locals.copy() config_values.update(values) try: result = pwncat.modules.run(args.module, **config_values) pwncat.config.back() except pwncat.modules.ModuleFailed as exc: if args.traceback: console.print_exception() else: console.log(f"[red]error[/red]: module failed: {exc}") return except pwncat.modules.ModuleNotFound: console.log(f"[red]error[/red]: {args.module}: not found") return except pwncat.modules.ArgumentFormatError as exc: console.log(f"[red]error[/red]: {exc}: invalid argument") return except pwncat.modules.MissingArgument as exc: console.log(f"[red]error[/red]: missing argument: {exc}") return except pwncat.modules.InvalidArgument as exc: console.log(f"[red]error[/red]: invalid argument: {exc}") return if args.raw: console.print(result) else: if result is None or (isinstance(result, list) and not result): console.log( f"Module [bold]{args.module}[/bold] completed successfully" ) return if not isinstance(result, list): result = [result] self.display_item(title=args.module, results=result)
def run(self): self.running = True while self.running: try: if pwncat.config.module: self.prompt.message = [ ( "fg:ansiyellow bold", f"({pwncat.config.module.name}) ", ), ("fg:ansimagenta bold", "pwncat"), ("", "$ "), ] else: self.prompt.message = [ ("fg:ansiyellow bold", "(local) "), ("fg:ansimagenta bold", "pwncat"), ("", "$ "), ] line = self.prompt.prompt().strip() if line == "": continue self.dispatch_line(line) # We used to catch only KeyboardException, but this prevents a # badly written command from completely killing our remote # connection. except pwncat.util.CommandSystemExit: raise except EOFError: # We don't have a connection yet, just exit if pwncat.victim is None or pwncat.victim.client is None: break # We have a connection! Go back to raw mode pwncat.victim.state = State.RAW self.running = False except KeyboardInterrupt: continue except (Exception, KeyboardInterrupt): console.print_exception(width=None) continue