Ejemplo n.º 1
0
def parallel_scan_process(options, targets, scan_unique_id, process_number):
    active_threads = []
    verbose_event_info(
        messages("single_process_started").format(process_number))
    total_number_of_modules = len(targets) * len(options.selected_modules)
    total_number_of_modules_counter = 1
    for target in targets:
        for module_name in options.selected_modules:
            thread = Thread(target=perform_scan,
                            args=(options, target, module_name, scan_unique_id,
                                  process_number,
                                  total_number_of_modules_counter,
                                  total_number_of_modules))
            thread.name = f"{target} -> {module_name}"
            thread.start()
            verbose_event_info(
                messages("start_parallel_module_scan").format(
                    process_number, module_name, target,
                    total_number_of_modules_counter, total_number_of_modules))
            total_number_of_modules_counter += 1
            active_threads.append(thread)
            if not wait_for_threads_to_finish(
                    active_threads, options.parallel_module_scan, True):
                return False
    wait_for_threads_to_finish(active_threads, maximum=None, terminable=True)
    return True
Ejemplo n.º 2
0
    def start(self):
        from terminable_thread import Thread
        from core.utility import wait_for_threads_to_finish
        active_threads = []
        from core.alert import warn
        from core.alert import verbose_event_info
        from core.alert import messages

        # counting total number of requests
        total_number_of_requests = 0
        for payload in self.module_content['payloads']:
            if payload['library'] not in self.libraries:
                warn(
                    messages("library_not_supported").format(
                        payload['library']))
                return None
            for step in payload['steps']:
                for _ in step:
                    total_number_of_requests += 1
        request_number_counter = 0
        for payload in self.module_content['payloads']:
            protocol = getattr(
                __import__('core.module_protocols.{library}'.format(
                    library=payload['library']),
                           fromlist=['Engine']), 'Engine')
            for step in payload['steps']:
                for sub_step in step:
                    thread = Thread(
                        target=protocol.run,
                        args=(sub_step, self.module_name, self.target,
                              self.scan_unique_id, self.module_inputs,
                              self.process_number, self.module_thread_number,
                              self.total_module_thread_number,
                              request_number_counter,
                              total_number_of_requests))
                    thread.name = f"{self.target} -> {self.module_name} -> {sub_step}"
                    request_number_counter += 1
                    verbose_event_info(
                        messages("sending_module_request").format(
                            self.process_number, self.module_name, self.target,
                            self.module_thread_number,
                            self.total_module_thread_number,
                            request_number_counter, total_number_of_requests))
                    thread.start()
                    time.sleep(
                        self.module_inputs['time_sleep_between_requests'])
                    active_threads.append(thread)
                    wait_for_threads_to_finish(
                        active_threads,
                        maximum=self.module_inputs['thread_per_host'],
                        terminable=True)
        wait_for_threads_to_finish(active_threads,
                                   maximum=None,
                                   terminable=True)