def start(self): if not self.selected: raise CmdError("No listener selected") if len( list( filter(lambda l: l['Name'] == self.selected['Name'], self.listeners))): raise CmdError( f"A listener named \'{self.selected['Name']}\' already running! (Change the name and try again)" ) try: self.selected.start() logging.info( f"Started {self.selected.name} listener ({self.selected['BindIP']}:{self.selected['Port']})" ) except Exception as e: traceback.print_exc() raise CmdError( f"Failed to start {self.selected.name} listener: {e}") else: self.listeners.append(self.selected) listener_json = dict(self.selected) self.use(self.selected.name) asyncio.create_task(self.wss.update_server_stats()) return dict(listener_json)
def set(self, name: str, value: str): if not self.selected: raise CmdError("OPERATOR ERROR Message: No module selected") try: self.selected[name] = value except KeyError: raise CmdError(f"OPERATOR ERROR Message: Unknown Command '{name}'")
def set(self, name: str, value: str): if not self.selected: raise CmdError("No stager selected") try: self.selected[name] = value except KeyError: raise CmdError(f"Unknown option '{name}'")
def use(self, name: str): for s in self.loaded: if s.name.lower() == name.lower(): self.selected = deepcopy(s) return dict(self.selected) raise CmdError(f"No stager available named '{name.lower()}'")
def use(self, name: str): for c in self.loaded: if c.name.lower() == name.lower(): self.selected = c return dict(self.selected) raise CmdError(f"OPERATOR ERROR Message: use technique; status: TTP, '{name.lower()}' is uknown")
def wrapper(*args, **kwargs): cmd_args = kwargs["args"] validated_args = {} for name, hint in get_type_hints(func).items(): if name == 'response': continue try: value = cmd_args[f'<{name}>'] except KeyError: try: value = cmd_args[f'--{name}'] except KeyError: raise CmdError( f"Unable to find '{name}' argument in command definition" ) try: validated_args[name] = hint(value) except TypeError: if hint == List[int]: validated_args[name] = [int(x) for x in value] elif hint == List[str]: validated_args[name] = [str(x) for x in value] else: raise NotImplementedError( f"Casting for type '{hint}' has not been implemented") return func(args[0], **validated_args, response=kwargs["response"] ) if args[0].__class__._remote is True else func( args[0], **validated_args)
def kill(self, guid): try: session = self.get_session(guid) session.jobs.add(Job(command=('Exit', []))) return {'guid': guid, 'status': 'Tasked to exit'} except SessionNotFoundError: raise CmdError(f"No session named: {guid}")
def use(self, name: str): for l in self.loaded: if l.name.lower() == name.lower(): self.selected = deepcopy(l) return dict(self.selected) raise CmdError(f"No listener available named '{name.lower()}'")
def generate(self, listener_name, location): if not self.selected: raise CmdError("No stager selected") for l in self.wss.contexts['listeners'].listeners: if l['Name'] == listener_name: guid, psk, generated_stager = self.selected.generate(l) self.wss.contexts['sessions']._register(guid, psk) self.wss.contexts['sessions']._add_location(guid, location) return { "output": generated_stager, "suggestions": self.selected.suggestions, "extension": self.selected.extension, } raise CmdError(f"No listener running with name '{listener_name}'")
def jitter(self, guid, max, min): try: session = self.get_session(guid) if min: session.jobs.add(Job(command=('Jitter', [int(max), int(min)]))) else: session.jobs.add(Job(command=('Jitter', [int(max)]))) except SessionNotFoundError: raise CmdError(f"No session named: {guid}")
def unregister(self, guid): self.guid_is_valid(guid) if guid in self.sessions: raise CmdError( "You can't unregister an active session. Kill then purge the session first." ) with AsyncARTIC2db() as db: db.remove_session(guid) logging.info(f"Unregistering session: {guid}") return {"guid": str(guid)}
def sleep(self, guid, interval): try: session = self.get_session(guid) session.jobs.add(Job(command=('Sleep', [int(interval)]))) except SessionNotFoundError: raise CmdError(f"No session named: {guid}")
def options(self): if not self.selected: raise CmdError("OPERATOR ERROR Message: No module selected") return self.selected.options
def options(self): if not self.selected: raise CmdError("No stager selected") return self.selected.options
def info(self): if not self.selected: raise CmdError("OPERATOR ERROR Message: No module selected") return dict(self.selected)
def guid_is_valid(self, guid): try: uuid.UUID(str(guid)) except ValueError: raise CmdError("Invalid Guid")
def rename(self, guid, name): try: session = self.get_session(guid) session.name = name except SessionNotFoundError: raise CmdError(f"No session with guid: {guid}")
def checkin(self, guid): try: session = self.get_session(guid) session.jobs.add(Job(command=('CheckIn', []))) except SessionNotFoundError: raise CmdError(f"No session named: {guid}")
def info(self): if not self.selected: raise CmdError("No listener selected") return self.selected.options
def info(self, guid): try: return dict(self.get_session(guid)) except SessionNotFoundError: raise CmdError(f"No session named: {guid}")