Exemplo n.º 1
0
    def _payload(self, parameters):
        '''
        Handle the payload command:
            - payload desc list_processes -> return payload description
            - payload list_processes      -> run payload

        :param payload_name: The name of the payload I want to run.
        :param parameters: The parameters as sent by the user.
        '''
        #
        #    Handle payload desc xyz
        #
        if len(parameters) == 2:
            if parameters[0] == 'desc':
                payload_name = parameters[1]

                if payload_name not in payload_handler.get_payload_list():
                    return 'Unknown payload name: "%s"' % payload_name

                return payload_handler.get_payload_desc(payload_name)

        #
        #    Handle payload xyz
        #
        payload_name = parameters[0]
        parameters = parameters[1:]

        if payload_name not in payload_handler.get_payload_list():
            return 'Unknown payload name: "%s"' % payload_name

        if payload_name in payload_handler.runnable_payloads(self):
            om.out.debug(
                'Payload %s can be run. Starting execution.' % payload_name)

            # Note: The payloads are actually writing to om.out.console
            # so there is no need to get the result. If someone wants to
            # get the results in a programatic way they should execute the
            # payload with use_api=True.
            try:
                payload_handler.exec_payload(self, payload_name, parameters)
                result = None
            except TypeError:
                # We get here when the user calls the payload with an incorrect
                # number of parameters:
                payload = payload_handler.get_payload_instance(
                    payload_name, self)
                result = payload.get_desc()
            except ValueError, ve:
                # We get here when one of the parameters provided by the user is
                # not of the correct type, or something like that.
                result = str(ve)
Exemplo n.º 2
0
    def _payload(self, parameters):
        '''
        Handle the payload command:
            - payload desc list_processes -> return payload description
            - payload list_processes      -> run payload

        :param payload_name: The name of the payload I want to run.
        :param parameters: The parameters as sent by the user.
        '''
        #
        #    Handle payload desc xyz
        #
        if len(parameters) == 2:
            if parameters[0] == 'desc':
                payload_name = parameters[1]

                if payload_name not in payload_handler.get_payload_list():
                    return 'Unknown payload name: "%s"' % payload_name

                return payload_handler.get_payload_desc(payload_name)

        #
        #    Handle payload xyz
        #
        payload_name = parameters[0]
        parameters = parameters[1:]

        if payload_name not in payload_handler.get_payload_list():
            return 'Unknown payload name: "%s"' % payload_name

        if payload_name in payload_handler.runnable_payloads(self):
            om.out.debug(
                'Payload %s can be run. Starting execution.' % payload_name)

            # Note: The payloads are actually writing to om.out.console
            # so there is no need to get the result. If someone wants to
            # get the results in a programatic way they should execute the
            # payload with use_api=True.
            try:
                payload_handler.exec_payload(self, payload_name, parameters)
                result = None
            except TypeError:
                # We get here when the user calls the payload with an incorrect
                # number of parameters:
                payload = payload_handler.get_payload_instance(
                    payload_name, self)
                result = payload.get_desc()
            except ValueError, ve:
                # We get here when one of the parameters provided by the user is
                # not of the correct type, or something like that.
                result = str(ve)
Exemplo n.º 3
0
    def test_runnable_payloads_exec(self):
        shell = FakeExecShell()
        runnable = runnable_payloads(shell)

        EXCEPTIONS = set([
            'portscan',
        ])
        all_payloads = get_payload_list()
        all_but_exceptions = set(all_payloads) - EXCEPTIONS

        self.assertEquals(set(runnable), all_but_exceptions)
Exemplo n.º 4
0
 def test_runnable_payloads_exec(self):
     shell = FakeExecShell( None )
     runnable = runnable_payloads(shell)
     
     EXCEPTIONS = set(['portscan',])
     all = get_payload_list()
     all_but_exceptions = set(all) - EXCEPTIONS
     
     self.assertEquals(
                       set(runnable),
                       all_but_exceptions
                       )
Exemplo n.º 5
0
    def _analyze_unittests(self, plugin_type):
        payloads = get_payload_list()

        missing = []

        for payload in payloads:
            if not self._has_test(payload):
                missing.append(payload)

        if missing:
            msg = 'The following payloads dont have unittests: %s' %  \
                  (', '.join(sorted(missing)))
            self.assertTrue(False, msg)
Exemplo n.º 6
0
    def _analyze_unittests(self, plugin_type):
        payloads = get_payload_list()

        missing = []

        for payload in payloads:
            if not self._has_test(payload):
                missing.append(payload)

        if missing:
            msg = 'The following payloads dont have unittests: %s' %  \
                  (', '.join(sorted(missing)))
            self.assertTrue(False, msg)
Exemplo n.º 7
0
    def test_get_payload_list(self):
        payload_list = get_payload_list()

        KNOWN_NAMES = (
            'cpu_info',
            'arp_cache',
            'current_user',
            'users',
            'udp',
        )

        for known_name in KNOWN_NAMES:
            self.assertTrue(known_name in payload_list,
                            '%s not in %s' % (known_name, payload_list))

        self.assertTrue(len(payload_list), len(set(payload_list)))

        self.assertFalse('__init__' in payload_list)
        self.assertFalse('__init__.py' in payload_list)
Exemplo n.º 8
0
 def test_get_payload_list(self):
     payload_list = get_payload_list()
     
     KNOWN_NAMES = (
                    'cpu_info',
                    'arp_cache',
                    'current_user',
                    'users',
                    'udp',
                    )
     
     for known_name in KNOWN_NAMES:
         self.assertTrue( known_name in payload_list, 
                          '%s not in %s' % (known_name, payload_list) )
     
     self.assertTrue( len(payload_list), len(set(payload_list)))
     
     self.assertFalse( '__init__' in payload_list )
     self.assertFalse( '__init__.py' in payload_list )
Exemplo n.º 9
0
    def test_get_payload_instance(self):
        shell = FakeExecShell()
        for payload_name in get_payload_list():
            payload_inst = get_payload_instance(payload_name, shell)

            self.assertTrue(payload_inst.require() in ('linux', 'windows'))
Exemplo n.º 10
0
 def test_get_payload_instance(self):
     for payload_name in get_payload_list():
         payload_inst = get_payload_instance(payload_name, None)
         
         self.assertTrue( payload_inst.require() in ('linux', 'windows') )
Exemplo n.º 11
0
    def test_get_payload_instance(self):
        shell = FakeExecShell()
        for payload_name in get_payload_list():
            payload_inst = get_payload_instance(payload_name, shell)

            self.assertTrue(payload_inst.require() in ('linux', 'windows'))