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: 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.teamserver.update_server_stats()) return dict(listener_json)
def set(self, name: str, value: str): if not self.selected: raise CmdError("No listener selected") try: self.selected[name] = value except KeyError: raise CmdError(f"Unknown option '{name}'")
def generate(self, listener_name): if not self.selected: raise CmdError("No stager selected") for l in self.teamserver.contexts['listeners'].listeners: if l['Name'] == listener_name: return { "output": self.selected.generate(l), "suggestions": self.selected.suggestions, "extension": self.selected.extension } raise CmdError(f"No listener running with name '{listener_name}'")
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 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: # I'm still not sure if there's a way to dynamically cast Lists and Dicts using type hints 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 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"Listener named '{self.selected.name}' already running!") self.selected.start() self.listeners.append(self.selected) asyncio.create_task(self.teamserver.update_server_stats()) return dict(self.selected)
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 m in self.loaded: if m.name.lower() == name.lower(): self.selected = deepcopy(m) return dict(self.selected) raise CmdError(f"No module available named '{name.lower()}'")
def use(self, name: str): for l in self.loaded: if l.name.lower() == name.lower(): self.selected = deepcopy(l) #self.selected.name = f"{l.name}-{gen_random_string(6)}" return dict(self.selected) raise CmdError(f"No listener available named '{name.lower()}'")
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 start(self): if not self.selected: raise CmdError("No listener selected") self.selected.start() self.listeners.append(self.selected) asyncio.create_task(self.teamserver.update_user_stats()) return dict(self.selected)
def generate(self, listener_name): if not self.selected: raise CmdError("No stager selected") for l in self.teamserver.contexts['listeners'].listeners: if l['Name'] == listener_name: guid, psk, generated_stager = self.selected.generate(l) with STDatabase() as db: db.add_session(guid, psk) self.teamserver.contexts['sessions']._register(guid, psk) return { "output": generated_stager, "suggestions": self.selected.suggestions, "extension": self.selected.extension } raise CmdError(f"No listener running with name '{listener_name}'")
def register(self, guid, psk): if not guid: guid = uuid.uuid4() if not psk: psk = gen_stager_psk() try: uuid.UUID(str(guid)) except ValueError: raise CmdError("Invalid Guid") self._register(guid, psk) return {"guid": str(guid), "psk": psk}
def register(self, guid, psk): if not guid: guid = uuid.uuid4() if not psk: psk = gen_stager_psk() try: uuid.UUID(str(guid)) except ValueError: raise CmdError("Invalid Guid") with STDatabase() as db: db.add_session(guid, psk) self._register(guid, psk) return {"guid": str(guid), "psk": psk}
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("No listener selected") return self.selected.options
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, guid): try: return dict(self.get_session(guid)) except SessionNotFoundError: raise CmdError(f"No session named: {guid}")
def info(self): if not self.selected: raise CmdError("No module selected") return dict(self.selected)
def options(self): if not self.selected: raise CmdError("No module selected") return self.selected.options
def rename(self, guid, name): try: session = self.get_session(guid) session.guid = name except SessionNotFoundError: raise CmdError(f"No session with guid: {guid}")