def __vulnerabilities(self): """ Find all vulnerability definition modules under 'vulnerabilities'. """ return filter( lambda m: m.startswith(self.vulnerabilities) and hasattr( Module.get(m), '_vulnerability_definition') and Module.get(m). _vulnerability_definition, Module.all())
def do_list(self, args): """ usage: list [FILTER] Displays a list of the available modules, optionally filtered by name. Examples: mercury> list activity.forintent activity.info ... snip ... mercury> list debug information.debuggable mercury> """ argv = shlex.split(args, comments=True) if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"): self.do_help("list") return term = len(argv) > 0 and argv[0] or None print console.format_dict(dict(map(lambda m: [m, Module.get(m).name], filter(lambda m: term == None or m.find(term.lower()) >= 0, self.__modules()))))
def __vulnerabilities(self): """ Find all vulnerability definition modules under 'vulnerabilities'. """ return filter(lambda m: m.startswith(self.vulnerabilities) and hasattr(Module.get(m), '_vulnerability_definition') and Module.get(m)._vulnerability_definition, Module.all())
def do_contributors(self, args): """ Display a list of Mercury contributors. """ argv = shlex.split(args, comments=True) if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"): self.do_help("contributors") return contributors = map(lambda m: Module.get(m).author, Module.all()) contribution = [ (c[0], len(list(c[1]))) for c in itertools.groupby(sorted(flatten(contributors))) ] self.stdout.write("Core Contributors:\n") for contributor in [ 'MWR InfoSecurity (@mwrlabs)', 'Luander ([email protected])', 'Rodrigo Chiossi ([email protected])' ]: self.stdout.write(" %s\n" % contributor) self.stdout.write("\nModule Contributors:\n") for contributor in sorted(contribution, key=lambda c: -c[1]): self.stdout.write(" %s\n" % contributor[0])
def do_list(self, args): """ usage: list [FILTER] Displays a list of the available modules, optionally filtered by name. Examples: mercury> list activity.forintent activity.info ... snip ... mercury> list debug information.debuggable mercury> """ argv = shlex.split(args, comments=True) if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"): self.do_help("list") return term = len(argv) > 0 and argv[0] or None self.stdout.write( console.format_dict( dict( map( lambda m: [m, Module.get(m).name], filter( lambda m: term == None or m.find(term.lower()) >= 0, self.__modules())))) + "\n")
def do_list(self, args): """ usage: list [FILTER] Displays a list of the available modules, optionally filtered by name. Examples: mercury> list activity.forintent activity.info ... snip ... mercury> list debug information.debuggable mercury> optional arguments: --unsupported include a list of the modules that are not available on your device """ argv = shlex.split(args, comments=True) if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"): self.do_help("list") return if "--unsupported" in argv: argv.remove("--unsupported") term = len(argv) > 0 and argv[0] or None s_modules = filter(lambda m: term == None or m.find(term.lower()) >= 0, self.__modules()) u_modules = filter(lambda m: (term == None or m.find(term.lower()) >= 0) and not m in s_modules, self.__modules("any")) else: term = len(argv) > 0 and argv[0] or None s_modules = filter(lambda m: term == None or m.find(term.lower()) >= 0, self.__modules()) u_modules = [] self.stdout.write(console.format_dict(dict(map(lambda m: [m, Module.get(m).name], s_modules))) + "\n") if len(u_modules) > 0: self.stdout.write("\nUnsupported Modules:\n\n") self.stdout.write(console.format_dict(dict(map(lambda m: [m, Module.get(m).name], u_modules))) + "\n")
def __module(self, key): """ Gets a module instance, by identifier, and initialises it with the required session parameters. """ module = None try: module = Module.get(self.__module_name(key)) except KeyError: pass if module == None: try: module = Module.get(key) except KeyError: pass if module == None: raise KeyError(key) else: return module(self.__reflector, self.stdout, self.stderr)
def execute(self, arguments): """ Implementation of the Module execute() method. Each included vulnerability test is executed in turn, and printed out as 'Vulnerable', 'Not Vulnerable', or 'Exception'. """ for vulnerability in self.__vulnerabilities(): try: check = Module.get(vulnerability)(self._Module__reflector, self.stdout, self.stderr) result = check.isVulnerable(arguments) self.stdout.write("%s - %s\n" % (check.label, result and "[color red]Vulnerable[/color]" or "[color green]Not Vulnerable[/color]")) except: self.stdout.write("%s - %s\n" % (check.label, "[color blue]Exception[/color]"))
def do_contributors(self, args): """ Display a list of Mercury contributors. """ argv = shlex.split(args, comments=True) if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"): self.do_help("contributors") return contributors = map(lambda m: Module.get(m).author, Module.all()) contribution = [(c[0], len(list(c[1]))) for c in itertools.groupby(sorted(flatten(contributors)))] self.stdout.write("Core Contributors:\n") for contributor in ['MWR InfoSecurity (@mwrlabs)', 'Luander ([email protected])', 'Rodrigo Chiossi ([email protected])']: self.stdout.write(" %s\n"%contributor) self.stdout.write("\nModule Contributors:\n") for contributor in sorted(contribution, key=lambda c: -c[1]): self.stdout.write(" %s\n"%contributor[0])
def execute(self, arguments): """ Implementation of the Module execute() method. Each included vulnerability test is executed in turn, and printed out as 'Vulnerable', 'Not Vulnerable', or 'Exception'. """ for vulnerability in self.__vulnerabilities(): try: check = Module.get(vulnerability)(self._Module__reflector, self.stdout, self.stderr) label = hasattr(check, 'label') and check.label or check.fqmn() result = check.isVulnerable(arguments) self.stdout.write( "%s - %s\n" % (label, result and "[color red]Vulnerable[/color]" or "[color green]Not Vulnerable[/color]")) except: self.stdout.write("%s - %s\n" % (label, "[color blue]Exception[/color]"))
def do_list(self, args): """ usage: list [FILTER] Displays a list of the available modules, optionally filtered by name. Examples: mercury> list activity.forintent activity.info ... snip ... mercury> list debug information.debuggable mercury> """ argv = shlex.split(args, comments=True) if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"): self.do_help("list") return term = len(argv) > 0 and argv[0] or None # recalculate the sizing, depending on the size of the user's terminal window width = { 'gutter': 2, 'total': console.getSize()[0] } width['label'] = width['total'] / 3 width['desc'] = width['total'] - (width['gutter'] + width['label']) for module in filter(lambda m: term == None or m.find(term.lower()) >= 0, self.__modules()): name = wrap(Module.get(module).name, width['desc']).split("\n") if len(module[len(self.__base):]) > width['label']: self.stdout.write(("{:<%d}\n" % width['label']).format(module[len(self.__base):])) self.stdout.write(("{:<%d} {:<%d}\n" % (width['label'], width['desc'])).format("", name.pop(0))) else: self.stdout.write(("{:<%d} {:<%d}\n" % (width['label'], width['desc'])).format(module[len(self.__base):], name.pop(0))) for line in name: self.stdout.write(("{:<%d} {:<%d}\n" % (width['label'], width['desc'])).format("", line))
def testItShouldReturnNoneIfTheModuleLoaderHasNoModule(self): Module._Module__loader = ModuleTestCase.MockModuleLoader("aModule") assert Module.get("an.example.module") == "aModule"
def testItShouldGetAModuleFromTheModuleLoader(self): Module._Module__loader = ModuleTestCase.MockModuleLoader() assert Module.get("an.example.module") == None