Exemplo n.º 1
0
    def exec_payload(self, payload_name, args=()):
        """
        Execute ANOTHER payload, by providing the other payload name.

        :param payload_name: The name of the payload I want to run.
        :return: The payload result.
        """
        try:
            return payload_handler.exec_payload(self.shell, payload_name,
                                                args, use_api=True)
        except:
            #
            #    Run the payload name with any shell that has the capabilities
            #    we need, not the one we're already using (that failed because
            #    it doesn't have the capabilities).
            #
            try:
                return payload_handler.exec_payload(None, payload_name, args,
                                                    use_api=True)
            except:
                msg = 'The payload you are trying to run ("%s") can not be' \
                      ' run because it is trying to call another payload'\
                      ' ("%s") which is failing because there are no shells'\
                      ' that support the required system calls.'
                om.out.console(msg)

                # TODO: Should I raise an exception here?
                return msg % (self, payload_name)
Exemplo n.º 2
0
    def exec_payload(self, payload_name, args=()):
        """
        Execute ANOTHER payload, by providing the other payload name.

        :param payload_name: The name of the payload I want to run.
        :return: The payload result.
        """
        try:
            return payload_handler.exec_payload(self.shell,
                                                payload_name,
                                                args,
                                                use_api=True)
        except:
            #
            #    Run the payload name with any shell that has the capabilities
            #    we need, not the one we're already using (that failed because
            #    it doesn't have the capabilities).
            #
            try:
                return payload_handler.exec_payload(None,
                                                    payload_name,
                                                    args,
                                                    use_api=True)
            except:
                msg = 'The payload you are trying to run ("%s") can not be' \
                      ' run because it is trying to call another payload' \
                      ' ("%s") which is failing because there are no shells' \
                      ' that support the required system calls.'
                om.out.console(msg)

                # TODO: Should I raise an exception here?
                return msg % (self, payload_name)
Exemplo n.º 3
0
    def test_portscan(self):
        result = exec_payload(self.shell, 'portscan',
                              args=('localhost', '22'),
                              use_api=True)
        self.assertEquals(self.RESULT_22, result)

        result = exec_payload(self.shell, 'portscan',
                              args=('localhost', '23'),
                              use_api=True)
        self.assertEquals(self.RESULT_23, result)
Exemplo n.º 4
0
    def test_portscan(self):
        result = exec_payload(self.shell,
                              'portscan',
                              args=('localhost', '22'),
                              use_api=True)
        self.assertEquals(self.RESULT_22, result)

        result = exec_payload(self.shell,
                              'portscan',
                              args=('localhost', '23'),
                              use_api=True)
        self.assertEquals(self.RESULT_23, result)
Exemplo n.º 5
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.º 6
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.º 7
0
    def test_exec_payload_read(self):
        shell = FakeReadShell()
        result = exec_payload(shell, 'os_fingerprint', use_api=True)
        self.assertEquals({'os': 'Linux'}, result)

        result = exec_payload(shell, 'cpu_info', use_api=True)
        # On my box the result is:
        #
        # {'cpu_info': 'AMD Phenom(tm) II X4 945 Processor', 'cpu_cores': '4'}
        #
        # But because others will also run this, I don't want to make it so
        # strict
        self.assertTrue('cpu_info' in result)
        self.assertTrue('cpu_cores' in result)
        self.assertGreater(int(result['cpu_cores']), 0)
        self.assertLess(int(result['cpu_cores']), 12)
Exemplo n.º 8
0
 def test_pixy(self):
     temp_dir = tempfile.mkdtemp()
     result = exec_payload(self.shell,
                           'pixy',
                           args=(temp_dir, temp_dir),
                           use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 9
0
    def test_uptime(self):
        result = exec_payload(self.shell, 'uptime', use_api=True)

        for key in self.EXPECTED_RESULT:
            for time_unit in self.EXPECTED_RESULT[key]:
                self.assertTrue(
                    self.EXPECTED_RESULT[key][time_unit].isdigit())
Exemplo n.º 10
0
    def test_exec_payload_read(self):
        shell = FakeReadShell()
        result = exec_payload(shell, 'os_fingerprint', use_api=True)
        self.assertEquals({'os': 'Linux'}, result)

        result = exec_payload(shell, 'cpu_info', use_api=True)
        # On my box the result is:
        #
        # {'cpu_info': 'AMD Phenom(tm) II X4 945 Processor', 'cpu_cores': '4'}
        #
        # But because others will also run this, I don't want to make it so
        # strict
        self.assertTrue('cpu_info' in result)
        self.assertTrue('cpu_cores' in result)
        self.assertGreater(int(result['cpu_cores']), 0)
        self.assertLess(int(result['cpu_cores']), 12)
Exemplo n.º 11
0
 def test_apache_mod_security(self):
     result = exec_payload(self.shell, 'apache_mod_security', use_api=True)
     
     self.assertEquals(self.EXPECTED_RESULT['version'], result['version'])
     self.assertIn('/etc/apache2/mods-available/mod-security.conf', result['file'])
     
     file_content = result['file']['/etc/apache2/mods-available/mod-security.conf']
     self.assertIn('<IfModule security2_module>', file_content)
Exemplo n.º 12
0
    def test_udp(self):
        result = exec_payload(self.shell, 'udp', use_api=True)

        local_addresses = []
        for key, conn_data in result.iteritems():
            local_addresses.append(conn_data['local_address'])

        self.assertEqual(self.EXPECTED_RESULT, set(local_addresses))
Exemplo n.º 13
0
    def test_udp(self):
        result = exec_payload(self.shell, 'udp', use_api=True)

        local_addresses = []
        for key, conn_data in result.iteritems():
            local_addresses.append(conn_data['local_address'])

        self.assertTrue(set(local_addresses).issuperset(self.EXPECTED_RESULT))
    def test_current_user(self):
        result = exec_payload(self.shell, "current_user", use_api=True)

        user = result["current"]["user"]
        self.assertEquals(self.EXPECTED_RESULT["current"]["user"], user)

        home = result["current"]["home"]
        self.assertTrue(home.startswith(self.EXPECTED_RESULT["current"]["home"]), home)
Exemplo n.º 15
0
    def test_tcp(self):
        result = exec_payload(self.shell, 'tcp', use_api=True)

        local_addresses = []
        for key, conn_data in result.iteritems():
            local_addresses.append(conn_data['local_address'])

        self.assertTrue(set(local_addresses).issuperset(self.EXPECTED_RESULT))
Exemplo n.º 16
0
    def test_apache_mod_security(self):
        result = exec_payload(self.shell, 'apache_mod_security', use_api=True)

        self.assertEquals(self.EXPECTED_RESULT['version'], result['version'])
        self.assertIn('/etc/apache2/mods-available/mod-security.conf', result['file'])

        file_content = result['file']['/etc/apache2/mods-available/mod-security.conf']
        self.assertIn('<IfModule security2_module>', file_content)
Exemplo n.º 17
0
    def test_tcp(self):
        result = exec_payload(self.shell, 'tcp', use_api=True)

        local_addresses = []
        for key, conn_data in result.iteritems():
            local_addresses.append(conn_data['local_address'])

        for expected_local_address in self.EXPECTED_RESULT:
            self.assertIn(expected_local_address, local_addresses)
Exemplo n.º 18
0
    def test_current_user(self):
        result = exec_payload(self.shell, 'current_user', use_api=True)

        user = result['current']['user']
        self.assertEquals(self.EXPECTED_RESULT['current']['user'], user)

        home = result['current']['home']
        self.assertTrue(
            home.startswith(self.EXPECTED_RESULT['current']['home']), home)
Exemplo n.º 19
0
    def test_list_processes(self):
        result = exec_payload(
            self.shell, 'list_processes', args=(2000,), use_api=True)

        cmds = []
        for _, pid_data in result.iteritems():
            cmds.append(pid_data['cmd'])

        for expected in self.EXPECTED_RESULT:
            self.assertIn(expected, cmds)
Exemplo n.º 20
0
    def test_list_processes(self):
        result = exec_payload(self.shell,
                              'list_processes',
                              args=(2000, ),
                              use_api=True)

        cmds = []
        for _, pid_data in result.iteritems():
            cmds.append(pid_data['cmd'])

        for expected in self.EXPECTED_RESULT:
            self.assertIn(expected, cmds)
Exemplo n.º 21
0
    def test_get_source_code(self):
        temp_dir = tempfile.mkdtemp()
        result = exec_payload(self.shell, 'get_source_code', args=(temp_dir,),
                              use_api=True)

        self.assertEqual(len(self.EXPECTED_RESULT.keys()), 1)

        expected_url = self.EXPECTED_RESULT.keys()[0]
        downloaded_url = result.items()[0][0].url_string
        self.assertEquals(expected_url, downloaded_url)

        downloaded_file_path = result.items()[0][1][1]
        downloaded_file_content = file(downloaded_file_path).read()
        self.assertTrue(self.CONTENT in downloaded_file_content)

        shutil.rmtree(temp_dir)
Exemplo n.º 22
0
    def test_route(self):
        result = exec_payload(self.shell, 'route', use_api=True)
        routes = result['route']

        for route_info in routes:
            dest = route_info['Destination']
            gw = route_info['Gateway']
            iface = route_info['Iface']
            mask = route_info['Mask']

            self.assertEqual(dest.count('.'), 3)
            self.assertEqual(gw.count('.'), 3)
            self.assertEqual(mask.count('.'), 3)

            self.assertTrue(
                iface.startswith('eth') or iface.startswith('wlan')
                or iface.startswith('ppp') or iface.startswith('vbox')
                or iface.startswith('lxcbr') or iface.startswith('docker')
                or iface.startswith('lo'), iface)
Exemplo n.º 23
0
    def test_route(self):
        result = exec_payload(self.shell, 'route', use_api=True)
        routes = result['route']

        for route_info in routes:
            dest = route_info['Destination']
            gw = route_info['Gateway']
            iface = route_info['Iface']
            mask = route_info['Mask']

            self.assertEqual(dest.count('.'), 3)
            self.assertEqual(gw.count('.'), 3)
            self.assertEqual(mask.count('.'), 3)
            
            self.assertTrue(iface.startswith('eth') or
                            iface.startswith('wlan') or
                            iface.startswith('ppp') or
                            iface.startswith('vbox') or
                            iface.startswith('lxcbr') or
                            iface.startswith('lo'), iface)
Exemplo n.º 24
0
    def test_route(self):
        result = exec_payload(self.shell, "route", use_api=True)
        routes = result["route"]

        for route_info in routes:
            dest = route_info["Destination"]
            gw = route_info["Gateway"]
            iface = route_info["Iface"]
            mask = route_info["Mask"]

            self.assertEqual(dest.count("."), 3)
            self.assertEqual(gw.count("."), 3)
            self.assertEqual(mask.count("."), 3)

            self.assertTrue(
                iface.startswith("eth")
                or iface.startswith("wlan")
                or iface.startswith("ppp")
                or iface.startswith("vbox")
                or iface.startswith("lxcbr")
                or iface.startswith("docker")
                or iface.startswith("lo"),
                iface,
            )
Exemplo n.º 25
0
 def test_root_login_allowed(self):
     result = exec_payload(self.shell, 'root_login_allowed', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 26
0
 def test_apache_htaccess(self):
     result = exec_payload(self.shell, 'apache_htaccess', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 27
0
 def test_w3af_agent(self):
     result = exec_payload(self.shell, 'w3af_agent', args=(get_local_ip(),),
                           use_api=True)
     self.assertEquals('Successfully started the w3afAgent.', result)
Exemplo n.º 28
0
 def test_running_vm(self):
     result = exec_payload(self.shell, 'running_vm', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 29
0
 def test_apache_config_directory(self):
     result = exec_payload(self.shell,
                           'apache_config_directory',
                           use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 30
0
 def test_php_sca(self):
     result = exec_payload(self.shell, 'php_sca', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result.keys()[0])
Exemplo n.º 31
0
 def test_iis_root_directory(self):
     result = exec_payload(self.shell, 'iis_root_directory', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 32
0
 def test_dhcp_config_files(self):
     result = exec_payload(self.shell, 'dhcp_config_files', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 33
0
 def test_get_hashes(self):
     result = exec_payload(self.shell, 'get_hashes', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 34
0
 def test_exec_payload_exec(self):
     shell = FakeExecShell()
     result = exec_payload(shell, 'os_fingerprint', use_api=True)
     self.assertEquals({'os': 'Linux'}, result)
Exemplo n.º 35
0
 def test_filesystem(self):
     result = exec_payload(self.shell, 'filesystem', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result.keys())
Exemplo n.º 36
0
    def test_kernel_version(self):
        result = exec_payload(self.shell, 'kernel_version', use_api=True)

        self.assertTrue(result['kernel_version'].startswith('3.2.'))
        self.assertTrue('buildd' in result['kernel_version'])
Exemplo n.º 37
0
 def test_os_fingerprint(self):
     result = exec_payload(self.shell, 'os_fingerprint', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 38
0
 def test_root_login_allowed(self):
     result = exec_payload(self.shell, 'root_login_allowed', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 39
0
 def test_ssh_version(self):
     result = exec_payload(self.shell, 'ssh_version', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 40
0
 def test_log_reader(self):
     result = exec_payload(self.shell, 'log_reader', use_api=True)
     logs = set(result.keys())
     self.assertTrue(self.EXPECTED_RESULT.issubset(logs), logs)
Exemplo n.º 41
0
 def test_log_reader(self):
     result = exec_payload(self.shell, 'log_reader', use_api=True)
     logs = set(result.keys())
     self.assertTrue(self.EXPECTED_RESULT.issubset(logs), logs)
Exemplo n.º 42
0
 def test_list_kernel_modules(self):
     result = exec_payload(self.shell, 'list_kernel_modules', use_api=True)
     self.assertTrue(
         set(result.keys()).issuperset(self.EXPECTED_RESULT), result.keys())
Exemplo n.º 43
0
 def test_netcat_installed(self):
     result = exec_payload(self.shell, 'netcat_installed', use_api=True)
     
     self.assertIn(result, [self.EXISTS_EXPECTED_RESULT,
                            self.NOTEXISTS_EXPECTED_RESULT])
Exemplo n.º 44
0
 def test_dhcp_config_files(self):
     result = exec_payload(self.shell, 'dhcp_config_files', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 45
0
 def test_firefox_stealer(self):
     result = exec_payload(self.shell, 'firefox_stealer', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 46
0
 def test_hostname(self):
     result = exec_payload(self.shell, "hostname", use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 47
0
 def test_is_root(self):
     result = exec_payload(self.shell, 'is_root', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 48
0
 def test_arp_cache(self):
     result = exec_payload(self.shell, "arp_cache", use_api=True)
     for ip_address, (mac, iface) in result.iteritems():
         self.assertEquals(ip_address.count("."), 3)
         self.assertEquals(mac.count(":"), 5)
         self.assertTrue(iface.startswith("eth"))
Exemplo n.º 49
0
 def test_apache_run_group(self):
     result = exec_payload(self.shell, 'apache_run_group', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 50
0
 def test_rootkit_hunter(self):
     result = exec_payload(self.shell, 'rootkit_hunter', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 51
0
 def test_rootkit_hunter(self):
     result = exec_payload(self.shell, "rootkit_hunter", use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result)
Exemplo n.º 52
0
 def test_spider(self):
     result = exec_payload(self.shell, "spider", args=(2,), use_api=True)
     self.assertTrue("/home/moth/keys.txt" in result)
     self.assertTrue(result["/home/moth/keys.txt"])
Exemplo n.º 53
0
 def test_ssh_config_files(self):
     result = exec_payload(self.shell, 'ssh_config_files', use_api=True)
     self.assertTrue('/etc/ssh/sshd_config' in result)
     self.assertTrue('PermitRootLogin' in result['/etc/ssh/sshd_config'])
Exemplo n.º 54
0
 def test_hosts(self):
     result = exec_payload(self.shell, 'hosts', use_api=True)
     self.assertEquals(self.EXPECTED_RESULT, result.keys())