Пример #1
0
    def get_data(self, data_len):
        '''
        :param data_len: The data length to retrieve
        :return: A string with the XML data!

        HTTP library exceptions are not handled in order to make the code
        clearer.
        '''
        data = [None] * data_len

        mod_get_char = return_args(self.get_char_in_pos)
        imap_unordered = self.worker_pool.imap_unordered
        len_iter = xrange(data_len)

        for (pos, ), char in imap_unordered(mod_get_char, len_iter):
            data[pos] = char

        clean_data = []
        current = ''

        for char in data:
            if char is None:
                current = current.strip()
                if current != '':
                    clean_data.append(current)
                current = ''
            else:
                current += char

        return '\n'.join(clean_data)
Пример #2
0
    def get_data(self, data_len):
        '''
        :param data_len: The data length to retrieve
        :return: A string with the XML data!

        HTTP library exceptions are not handled in order to make the code
        clearer.
        '''
        data = [None] * data_len
        
        mod_get_char = return_args(self.get_char_in_pos)
        imap_unordered = self.worker_pool.imap_unordered
        len_iter = xrange(data_len)
        
        for (pos,), char in imap_unordered(mod_get_char, len_iter):
            data[pos] = char
        
        clean_data = []
        current = ''
        
        for char in data:
            if char is None:
                current = current.strip()
                if current != '':
                    clean_data.append(current)
                current = ''
            else:
                current += char
        
        return '\n'.join(clean_data)
Пример #3
0
 def read_multi(self, fname_iter):
     '''
     :param fname_iter: An iterator that yields all the file names to read.
     '''
     read_file = return_args(self.shell.read)
     results = self.worker_pool.imap_unordered(read_file, fname_iter)
     for (file_name,), content in results:
         yield file_name, content
Пример #4
0
    def _send_in_threads(self, base_url, vhosts):
        base_url_repeater = repeat(base_url)
        args_iterator = izip(base_url_repeater, vhosts)
        http_get = return_args(one_to_many(self._http_get_vhost))
        pool_results = self.worker_pool.imap_unordered(http_get, args_iterator)

        for ((base_url, vhost), ), vhost_response in pool_results:
            yield vhost, vhost_response
Пример #5
0
 def read_multi(self, fname_iter):
     '''
     :param fname_iter: An iterator that yields all the file names to read.
     '''
     read_file = return_args(self.shell.read)
     results = self.worker_pool.imap_unordered(read_file, fname_iter)
     for (file_name, ), content in results:
         yield file_name, content
Пример #6
0
 def _send_mutants_in_threads(self, func, iterable, callback, **kwds):
     '''
     Please note that this method blocks from the caller's point of view
     but performs all the HTTP requests in parallel threads.
     '''
     func = return_args(func, **kwds)
     for (mutant,), http_response in self.worker_pool.imap_unordered(func, iterable):
         callback(mutant, http_response)
Пример #7
0
    def _send_in_threads(self, base_url, vhosts):
        base_url_repeater = repeat(base_url)
        args_iterator = izip(base_url_repeater, vhosts)
        http_get = return_args(one_to_many(self._http_get_vhost))
        pool_results = self.worker_pool.imap_unordered(http_get,
                                                          args_iterator)

        for ((base_url, vhost),), vhost_response in pool_results:
            yield vhost, vhost_response
Пример #8
0
    def _consume(self, work_unit):

        for plugin in self._consumer_plugins:
            om.out.debug('%s plugin is testing: "%s"' % (
                plugin.get_name(), work_unit))

            self._threadpool.apply_async(return_args(self._bruteforce),
                                        (plugin, work_unit,),
                                         callback=self._plugin_finished_cb)
Пример #9
0
    def _consume(self, work_unit):

        for plugin in self._consumer_plugins:
            om.out.debug('%s plugin is testing: "%s"' %
                         (plugin.get_name(), work_unit))

            self._threadpool.apply_async(return_args(self._bruteforce), (
                plugin,
                work_unit,
            ),
                                         callback=self._plugin_finished_cb)
Пример #10
0
    def api_read(self):
        self.result = {}
        self.result['bad_kernel_modules'] = []
        self.result['backdoor_files'] = []
        self.k = 400

        self._check_kernel_modules()

        read_file = return_args(self._read_with_progress)
        fname_iter = self.fname_generator()
        for (file_name,), content in self.worker_pool.imap_unordered(read_file, fname_iter):
            if content:
                self.result['backdoor_files'].append(file_name)

        return self.result
Пример #11
0
    def api_read(self):
        self.result = {}
        self.result['bad_kernel_modules'] = []
        self.result['backdoor_files'] = []
        self.k = 400

        self._check_kernel_modules()

        read_file = return_args(self._read_with_progress)
        fname_iter = self.fname_generator()
        for (file_name, ), content in self.worker_pool.imap_unordered(
                read_file, fname_iter):
            if content:
                self.result['backdoor_files'].append(file_name)

        return self.result
Пример #12
0
    def _consume(self, work_unit):
        for plugin in self._consumer_plugins:

            if plugin in self._disabled_plugins:
                continue

            if not self._running:
                return

            om.out.debug('%s plugin is testing: "%s"' % (plugin.get_name(), work_unit))

            # TODO: unittest what happens if an exception (which is not handled
            #       by the exception handler) is raised. Who's doing a .get()
            #       on those ApplyResults generated here?
            self._threadpool.apply_async(
                return_args(self._discover_worker), (plugin, work_unit), callback=self._plugin_finished_cb
            )
            self._route_all_plugin_results()
Пример #13
0
    def _consume(self, work_unit):
        for plugin in self._consumer_plugins:

            if plugin in self._disabled_plugins:
                continue

            if not self._running:
                return

            om.out.debug('%s plugin is testing: "%s"' %
                         (plugin.get_name(), work_unit))

            # TODO: unittest what happens if an exception (which is not handled
            #       by the exception handler) is raised. Who's doing a .get()
            #       on those ApplyResults generated here?
            self._threadpool.apply_async(return_args(self._discover_worker), (
                plugin,
                work_unit,
            ),
                                         callback=self._plugin_finished_cb)
            self._route_all_plugin_results()
Пример #14
0
 def test_kwds(self):
     args_int_two = return_args(int, base=2)
     self.assertEqual((("1",), 1), args_int_two("1"))
Пример #15
0
 def test_two_params(self):
     args_replace = return_args("foo123bar".replace)
     self.assertEqual((("123", ""), "foobar"), args_replace("123", ""))
Пример #16
0
 def test_basic(self):
     args_int = return_args(int)
     self.assertEqual((("3",), 3), args_int("3"))
Пример #17
0
 def test_two_params(self):
     args_replace = return_args('foo123bar'.replace)
     self.assertEqual((('123', ''), 'foobar'), args_replace('123', ''))
Пример #18
0
 def test_kwds(self):
     args_int_two = return_args(int, base=2)
     self.assertEqual((('1', ), 1), args_int_two('1'))
Пример #19
0
 def test_basic(self):
     args_int = return_args(int)
     self.assertEqual((('3', ), 3), args_int('3'))