def test_upload_file_mock(self):
        exec_method = commands.getoutput
        os = 'linux'

        create_temp_dir()
        cf.cf.save('interface', 'lo')
        cf.cf.save('local_ip_address', '127.0.0.1')
        inbound_port = self.get_usable_port('127.0.0.1')
        echo_linux = ClientlessReverseHTTP(exec_method, os, inbound_port)

        self.assertTrue(echo_linux.can_transfer())

        file_len = 8195
        file_content = 'A' * file_len
        echo_linux.estimate_transfer_time(file_len)

        temp_file_inst = tempfile.NamedTemporaryFile()
        temp_fname = temp_file_inst.name
        upload_success = echo_linux.transfer(file_content, temp_fname)

        self.assertTrue(upload_success)
    def test_upload_file_mock(self):
        exec_method = commands.getoutput
        os = 'linux'

        create_temp_dir()
        cf.cf.save('interface', 'lo')
        cf.cf.save('local_ip_address', '127.0.0.1')
        inbound_port = self.get_usable_port('127.0.0.1')
        echo_linux = ClientlessReverseHTTP(exec_method, os, inbound_port)

        self.assertTrue(echo_linux.can_transfer())

        file_len = 8195
        file_content = 'A' * file_len
        echo_linux.estimate_transfer_time(file_len)

        temp_file_inst = tempfile.NamedTemporaryFile()
        temp_fname = temp_file_inst.name
        upload_success = echo_linux.transfer(file_content, temp_fname)

        self.assertTrue(upload_success)
Exemplo n.º 3
0
            if not inbound_port:
                inbound_port = self._es.get_inbound_port()
        except BaseFrameworkException, w3:
            msg = 'The extrusion scan failed, no reverse connect transfer methods'
            msg += ' can be used. Trying inband echo transfer method. Error: "%s"'
            om.out.error(msg % w3)
        except Exception, e:
            om.out.error('Unhandled exception: ' + str(e))
        else:
            to_test.append(ReverseFTP(self._exec_method, os, inbound_port))
            if os == 'windows':
                # FIXME: Need to add something here!
                pass
            elif os == 'linux':
                to_test.append(
                    ClientlessReverseHTTP(self._exec_method, os, inbound_port))

            # Test the fastest first and return the fastest one...
            def sort_function(x, y):
                return cmp(y.get_speed(), x.get_speed())

            to_test.sort(sort_function)

        for method in to_test:

            om.out.debug(
                'Testing if "%s" is able to transfer a file to the compromised host.'
                % method)
            if method.can_transfer():
                om.out.debug(
                    '%s is able to transfer a file to the compromised host.' %