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.teamserver.update_server_stats())
            return dict(listener_json)
示例#2
0
    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}'")
示例#3
0
 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}")
示例#4
0
    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)
                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}'")
示例#5
0
    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 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)
示例#7
0
    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()}'")
示例#8
0
    def use(self, name: str):
        for m in self.loaded:
            if m.name.lower() == name.lower():
                #self.selected = deepcopy(m)
                self.selected = m
                return dict(self.selected)

        raise CmdError(f"No module available named '{name.lower()}'")
示例#9
0
 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}")
示例#10
0
    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 STDatabase() as db:
            db.remove_session(guid)

        logging.info(f"Unregistering session: {guid}")

        return {"guid": str(guid)}
示例#11
0
    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}
示例#12
0
 def options(self):
     if not self.selected:
         raise CmdError("No listener selected")
     return self.selected.options
示例#13
0
 def guid_is_valid(self, guid):
     try:
         uuid.UUID(str(guid))
     except ValueError:
         raise CmdError("Invalid Guid")
示例#14
0
 def rename(self, guid, name):
     try:
         session = self.get_session(guid)
         session.name = name
     except SessionNotFoundError:
         raise CmdError(f"No session with guid: {guid}")
示例#15
0
 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}")
示例#16
0
 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}")
示例#17
0
 def options(self):
     if not self.selected:
         raise CmdError("No module selected")
     return self.selected.options
示例#18
0
 def info(self, guid):
     try:
         return dict(self.get_session(guid))
     except SessionNotFoundError:
         raise CmdError(f"No session named: {guid}")
示例#19
0
 def info(self):
     if not self.selected:
         raise CmdError("No module selected")
     return dict(self.selected)