Exemplo n.º 1
0
    def do_help(self, args):
        """
        usage: help [COMMAND OR MODULE]

        Displays help information.
        """
        argv = shlex.split(args, comments=True)

        if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"):
            self.do_help("help")
            return

        if len(argv) > 0:
            if self.__module_name(argv[0]) in Module.all(
            ) or self.__module_name("." + argv[0]) in Module.all():
                self.do_run(" ".join([argv[0], "--help"]))
            else:
                try:
                    func = getattr(self, 'help_' + argv[0])
                except AttributeError:
                    try:
                        doc = getattr(self, 'do_' + argv[0]).__doc__
                        if doc:
                            self.stdout.write(
                                "%s\n" %
                                wrap(textwrap.dedent(str(doc)).strip(),
                                     width=console.get_size()[0]))
                            return
                    except AttributeError:
                        pass
                    self.stdout.write("%s\n" % str(self.nohelp) % (argv[0], ))
                    return
                func()
        else:
            cmd.Cmd.do_help(self, args)
Exemplo n.º 2
0
    def __modules(self):
        """
        Gets a full list of all module identifiers.
        """

        if self.__base == "":
            return Module.all()
        else:
            return filter(lambda m: m.startswith(self.__base), Module.all())
Exemplo n.º 3
0
    def __modules(self):
        """
        Gets a full list of all module identifiers.
        """

        if self.__base == "":
            return Module.all()
        else:
            return filter(lambda m: m.startswith(self.__base), Module.all())
Exemplo n.º 4
0
    def __modules(self, permissions=None):
        """
        Gets a full list of all module identifiers.
        """
        
        if permissions == "any":
            required_perms = None
        else:
            required_perms = self.permissions()

        if self.__base == "":
            return Module.all(required_perms)
        else:
            return filter(lambda m: m.startswith(self.__base), Module.all(required_perms))
Exemplo n.º 5
0
    def do_help(self, args):
        """
        usage: help [COMMAND OR MODULE]

        Displays help information.
        """
        argv = shlex.split(args, comments=True)

        if len(argv) == 1 and (argv[0] == "-h" or argv[0] == "--help"):
            self.do_help("help")
            return

        if len(argv) > 0:
            if self.__module_name(argv[0]) in Module.all() or self.__module_name("." + argv[0]) in Module.all():
                self.do_run(" ".join([argv[0], "--help"]))
            else:
                try:
                    func = getattr(self, 'help_' + argv[0])
                except AttributeError:
                    try:
                        doc = getattr(self, 'do_' + argv[0]).__doc__
                        if doc:
                            self.stdout.write("%s\n" % wrap(textwrap.dedent(str(doc)).strip(), width=console.get_size()[0]))
                            return
                    except AttributeError:
                        pass
                    self.stdout.write("%s\n" % str(self.nohelp) % (argv[0],))
                    return
                func()
        else:
            cmd.Cmd.do_help(self, args)
Exemplo n.º 6
0
    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])
Exemplo n.º 7
0
    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())
Exemplo n.º 8
0
    def __namespaces(self, global_scope=False):
        """
        Gets a full list of all namespace identifiers, either globally or in
        the current namespace scope.
        """

        if global_scope:
            return set(map(lambda m: self.__module("." + m).namespace(), Module.all()))
        else:
            return set(map(lambda m: self.__module("." + m).namespace(), self.__modules()))
Exemplo n.º 9
0
    def __namespaces(self, global_scope=False):
        """
        Gets a full list of all namespace identifiers, either globally or in
        the current namespace scope.
        """

        if global_scope:
            return set(
                map(lambda m: self.__module("." + m).namespace(),
                    Module.all()))
        else:
            return set(
                map(lambda m: self.__module("." + m).namespace(),
                    self.__modules()))
Exemplo n.º 10
0
    def __setBase(self, base):
        """
        Changes the user's namespace.

        Changing to:

            'str' - selects the 'str' namespace, within the currently active
                    namespace
           '.str' - selects the 'str' namespace, in the root namespace
             '..' - goes back on namespace
               '' - goes back to the root namespace
        """

        if base == "":
            self.__base = base
        else:
            if base == "..":
                path = self.__base.split(".")

                try:
                    path.pop(-2)
                except IndexError:
                    pass

                target = ".".join(path)
            elif base.startswith("."):
                target = base[1:] + "."
            else:
                target = self.__base + base + "."

            if True in map(lambda m: m.startswith(target), Module.all()):
                self.__base = target
            else:
                self.stderr.write("no such namespace: %s\n" % base)

        if base == "":
            self.prompt = "mercury> "
        else:
            self.prompt = "mercury#{}> ".format(
                self.__base[0:len(self.__base) - 1])

        return True
Exemplo n.º 11
0
    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])
Exemplo n.º 12
0
    def __setBase(self, base):
        """
        Changes the user's namespace.

        Changing to:

            'str' - selects the 'str' namespace, within the currently active
                    namespace
           '.str' - selects the 'str' namespace, in the root namespace
             '..' - goes back on namespace
               '' - goes back to the root namespace
        """

        if base == "":
            self.__base = base
        else:
            if base == "..":
                path = self.__base.split(".")

                try:
                    path.pop(-2)
                except IndexError:
                    pass

                target = ".".join(path)
            elif base.startswith("."):
                target = base[1:] + "."
            else:
                target = self.__base + base + "."

            if True in map(lambda m: m.startswith(target), Module.all()):
                self.__base = target
            else:
                self.stderr.write("no such namespace: %s\n"%base)

        if base == "":
            self.prompt = "mercury> "
        else:
            self.prompt = "mercury#{}> ".format(self.__base[0:len(self.__base)-1])

        return True
Exemplo n.º 13
0
 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())
     
Exemplo n.º 14
0
    def testItShouldListAllFromTheModuleLoader(self):
        Module._Module__loader = ModuleTestCase.MockModuleLoader()

        assert Module.all() == [
            "an.example.module", "an.other.module", "module.in.other.namespace"
        ]
Exemplo n.º 15
0
    def testItShouldListAllFromTheModuleLoader(self):
        Module._Module__loader = ModuleTestCase.MockModuleLoader()

        assert Module.all() == ["an.example.module", "an.other.module", "module.in.other.namespace"]