def add_argument(self, plugin, name, **kwargs): # TODO: make sure name is simple. name = '--' + plugin.slug + '.' + slugify(name) if self.argparse_group is None: self.argparse_group = self.argparse.add_argument_group('plugin arguments', description='These are optional arguments for certain plugins.') self.argparse_group.add_argument(name, **kwargs)
def get_option(self, name): # TODO: make sure name is simple. name = self.slug.replace('-', '_') + '.' + slugify(name).replace('-', '_') if name in vars(self.autorecon.args): return vars(self.autorecon.args)[name] else: return None
def get_global_option(self, name, default=None): name = 'global.' + slugify(name).replace('-', '_') if name in vars(self.autorecon.args): if vars(self.autorecon.args)[name] is None: if default: return default else: return None else: return vars(self.autorecon.args)[name] else: if default: return default return None
def register(self, plugin, filename): if plugin.disabled: return if plugin.name is None: fail('Error: Plugin with class name "' + plugin.__class__.__name__ + '" in ' + filename + ' does not have a name.') for _, loaded_plugin in self.plugins.items(): if plugin.name == loaded_plugin.name: fail('Error: Duplicate plugin name "' + plugin.name + '" detected in ' + filename + '.', file=sys.stderr) if plugin.slug is None: plugin.slug = slugify(plugin.name) elif not self.__slug_regex.match(plugin.slug): fail( 'Error: provided slug "' + plugin.slug + '" in ' + filename + ' is not valid (must only contain lowercase letters, numbers, and hyphens).', file=sys.stderr) if plugin.slug in config['protected_classes']: fail('Error: plugin slug "' + plugin.slug + '" in ' + filename + ' is a protected string. Please change.') if plugin.slug not in self.plugins: for _, loaded_plugin in self.plugins.items(): if plugin is loaded_plugin: fail('Error: plugin "' + plugin.name + '" in ' + filename + ' already loaded as "' + loaded_plugin.name + '" (' + str(loaded_plugin) + ')', file=sys.stderr) configure_function_found = False run_coroutine_found = False manual_function_found = False for member_name, member_value in inspect.getmembers( plugin, predicate=inspect.ismethod): if member_name == 'configure': configure_function_found = True elif member_name == 'run' and inspect.iscoroutinefunction( member_value): if len(inspect.getfullargspec(member_value).args) != 2: fail('Error: the "run" coroutine in the plugin "' + plugin.name + '" in ' + filename + ' should have two arguments.', file=sys.stderr) run_coroutine_found = True elif member_name == 'manual': if len(inspect.getfullargspec(member_value).args) != 3: fail('Error: the "manual" function in the plugin "' + plugin.name + '" in ' + filename + ' should have three arguments.', file=sys.stderr) manual_function_found = True if not run_coroutine_found and not manual_function_found: fail( 'Error: the plugin "' + plugin.name + '" in ' + filename + ' needs either a "manual" function, a "run" coroutine, or both.', file=sys.stderr) if issubclass(plugin.__class__, PortScan): if plugin.type is None: fail('Error: the PortScan plugin "' + plugin.name + '" in ' + filename + ' requires a type (either tcp or udp).') else: plugin.type = plugin.type.lower() if plugin.type not in ['tcp', 'udp']: fail('Error: the PortScan plugin "' + plugin.name + '" in ' + filename + ' has an invalid type (should be tcp or udp).') self.plugin_types["port"].append(plugin) elif issubclass(plugin.__class__, ServiceScan): self.plugin_types["service"].append(plugin) elif issubclass(plugin.__class__, Report): self.plugin_types["report"].append(plugin) else: fail('Plugin "' + plugin.name + '" in ' + filename + ' is neither a PortScan, ServiceScan, nor a Report.', file=sys.stderr) plugin.tags = [tag.lower() for tag in plugin.tags] # Add plugin tags to tag list. [self.taglist.append(t) for t in plugin.tags if t not in self.tags] plugin.autorecon = self if configure_function_found: plugin.configure() self.plugins[plugin.slug] = plugin else: fail('Error: plugin slug "' + plugin.slug + '" in ' + filename + ' is already assigned.', file=sys.stderr)