def _show_templates(self, *args, **kwargs):
     modulename = type(self.current_module).__name__
     for template in [
             template for template in self.saved_templates
             if template.startswith(modulename)
     ]:
         print_info(template.replace('.', os.sep))
    def command_add(self, *args, **kwargs):
        key = args[0]
        if key in self.current_module.options:
            templist = getattr(self.current_module, key)
            print_info("Header name:")
            value = input()
            print_info("Header value:")
            templist[value] = input()
            setattr(self.current_module, key, templist)
            self.current_module.module_attributes[key][0][value] = templist[
                value]

            print_success("{} => {}: {}".format(key, value, templist[value]))
Exemple #3
0
    def get(self):

        try:
            self._assert_valid()
            print_info("Aiming for: " + self.scheme + "://" + self.host +
                       self.path)
            self.path = self._forge_path_params()
            r = requests.get(self.scheme + "://" + self.host + self.path,
                             headers=self.headers)
            for key in r.headers:
                print_info(key, r.headers[key])
            print("Body:" + r.text)
        except Exception as ex:
            print_error(str(ex))
 def command_run(self, *args, **kwargs):
     print_status("Running module {}...".format(self.current_module))
     sub_command = args[0]
     try:
         getattr(self.current_module, sub_command)()
     except KeyboardInterrupt:
         print_info()
         print_error("Operation cancelled by user")
     except AttributeError:
         if sub_command is '':
             print_error("Usage: run <request method: {}>".format(
                 "get, post, put, delete"))
         else:
             print_error("Unknown command [{}]".format(sub_command))
     except Exception as ex:
         print_error(str(ex))
 def start(self):
     print_info(self.banner)
     printer_queue.join()
     while True:
         try:
             command, args, kwargs = self.parse_line(input(self.prompt))
             if not command:
                 continue
             command_handler = self.get_command_handler(command)
             command_handler(args, **kwargs)
         except CurlFrameworkException as err:
             print_error(err)
         except (EOFError, KeyboardInterrupt, SystemExit):
             print_info()
             print_error("Curly stopped")
             break
         finally:
             printer_queue.join()
    def nonInteractive(self, argv):
        module = ""
        set_opts = []

        try:
            opts, args = getopt.getopt(argv[1:], "hm:s",
                                       ["help=", "module=", "set="])
        except getopt.GetoptError:
            print_info("{} -m <module> -s \"<option> <value>\"".format(
                argv[0]))
            printer_queue.join()
            return

        for opt, arg in opts:
            if opt in ("-h", "--help"):
                print_info("{} -m <module> -s \"<option> <value>\"".format(
                    argv[0]))
                printer_queue.join()
                return
            elif opt in ("-m", "--module"):
                module = arg
            elif opt in ("-s", "--set"):
                set_opts.append(arg)

        if not len(module):
            print_error('A module is required when running non-interactively')
            printer_queue.join()
            return

        self.command_use(module)

        for opt in set_opts:
            self.command_set(opt)

        self.command_run()

        printer_queue.join()

        return
    def _show_options(self, *args, **kwargs):
        # TODO: WILL NEED UPDATE
        # target_names = ["target", "port", "ssl", "rhost", "rport", "lhost", "lport"]
        target_opts = [opt for opt in self.current_module.options]
        module_opts = [opt for opt in self.current_module.options]
        headers = ("Name", "Current settings")

        print_info("\nTarget options:")
        print_table(headers, *self.get_opts(*target_opts))

        if module_opts:
            print_info("\Module options:")
            print_table(headers, *self.get_opts(*module_opts))

        print_info()
    def _show_advanced(self, *args, **kwargs):
        target_names = [
            "target", "port", "ssl", "rhsot", "rport", "lhost", "lport"
        ]
        target_opts = [
            opt for opt in self.current_module.options if opt in target_names
        ]
        module_opts = [
            opt for opt in self.current_module.options
            if opt not in target_opts
        ]
        headers = ("Name", "Current settings", "Description")

        print_info("\nTarget options:")
        print_table(headers, *self.get_opts(*target_opts))

        if module_opts:
            print_info("\nModule options:")
            print_table(headers, *self.get_opts_adv(*module_opts))

        print_info()
    def command_search(self, *args, **kwargs):
        mod_type = ''
        mod_detail = ''
        mod_vendor = ''
        existing_modules = [
            name for _, name, _ in pkgutil.iter_modules([MODULES_DIR])
        ]
        # TODO: Probably gonna need refactoring
        devices = [
            name for _, name, _ in pkgutil.iter_modules(
                [os.path.join(MODULES_DIR, 'modules')])
        ]
        payloads = [
            name for _, name, _ in pkgutil.iter_modules(
                [os.path.join(MODULES_DIR, 'payloads')])
        ]

        try:
            keyword = args[0].strip("'\"").lower()
        except IndexError:
            keyword = ''

        if not (len(keyword) or len(kwargs.keys())):
            print_error("Please specify at least one search keyword")
            print_error(
                "You can specify options, eg 'search type=modules etc'")

        for (key, value) in kwargs.items():
            if key == 'type':
                if value not in existing_modules:
                    print_error("Unknown module type")
                    return
                mod_type = "{}.".format(value)
            elif key in ['device', 'language', 'payload']:
                if key == 'device' and (value not in devices):
                    print_error("Unknown module type")
                    return
                elif key == 'payload' and (value not in payloads):
                    print_error("Unknown payload type")
                    return
                mod_detail = ".{}.".format(value)
            elif key == 'vendor':
                mod_vendor = ".{}.".format(value)

        for module in self.modules:
            if mod_type not in str(module):
                continue
            if mod_detail not in str(module):
                continue
            if mod_vendor not in str(module):
                continue
            if not all(word in str(module) for word in keyword.split()):
                continue

            found = humanize_path(module)

            if len(keyword):
                for word in keyword.split():
                    found = found.replace(word,
                                          "\033[31m{}\033[0m".format(word))

            print_info(found)
 def command_help(self, *args, **kwargs):
     print_info(self.global_help)
     if self.current_module:
         print_info("\n", self.module_help)
 def _show_modules(self, root=''):
     for module in [
             module for module in self.modules if module.startswith(root)
     ]:
         print_info(module.replace('.', os.sep))
 def _show_info(self, *args, **kwargs):
     pprint_dict_in_order(
         self.module_metadata,
         ("name", "description", "devices", "authors", "references"),
     )
     print_info()