def run(self): if not self.options_parser.options.disable_ui: print "press h for help." try: while self.running: (read_fds, write_fds, err_fds) = select([sys.stdin, self.receive], [], []) for rfd in read_fds: if rfd == sys.stdin: command = sys.stdin.read(1) if command == 'h': self.print_help() elif command == 'l': self.print_active_scan_jobs() elif command == 'a': self.abort_group() elif command == '+': self.increase_number_of_jobs() elif command == '-': self.decrease_number_of_jobs() else: self.print_progress_report() else: self.running = False break termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, self.old_settings) self.fini_mutex.release() except KeyboardInterrupt: print "keyboard-interrupt received, quitting" termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, self.old_settings) stopParserThread(self.scanner.parser) sys.exit(1)
def run(self): # (1) Create initial trigger-jobs. hosts_to_scan = self.options_parser.get_hosts_to_scan() self.options_parser.gen_list_of_single_ports() # we have now initialized self.initialized_sem.release() if not self.options_parser.options.only_discover: print "+++ Will scan " + str(self.options_parser.options.nports_to_scan_per_job), print "ports on " + str(len(hosts_to_scan)) + " hosts. +++" # Each host we want to scan has to be triggered first self.pending_trigger_jobs = hosts_to_scan self.create_trigger_jobs() # (2) Wait for finished jobs while self.running: target_mode_tuple = self.scanner.poll_for_finished_jobs() if not target_mode_tuple: # Empty tuples are returned when the logic # should terminate. return (target, mode) = target_mode_tuple # Handle errors if target == 'ERROR': print "scanner-module returned an error. Quitting." # Shut down the scanner stopParserThread(self.scanner.parser) stopUserEventHandler(self.event_handler,self.options_parser) return """ Handle finished Jobs """ if mode == 'FLOOD': # A flood-job has finished: Output results, # delete the flood-jobs and execute the next # pending job self.output_flood_job_summary(target) self.scanner.free_scanjob(target, mode) self.nactive_flood_jobs = self.nactive_flood_jobs - 1 # Submit a pending job if self.pending_flood_jobs != []: self.scanner.parser.dont_read = False self.create_flood_jobs() elif mode == 'TRIGGER': # A trigger-job has finished. Output results, # execute the next pending trigger-job. # If no more pending trigger-jobs exist, # start creating flood-jobs # self.output_trigger_job_summary(target) host_is_up = self.scanner.is_trigger_job_up(target) and self.scanner.triggerJobs[target].triggers != [] self.nactive_trigger_jobs = self.nactive_trigger_jobs - 1 if host_is_up and not self.options_parser.options.only_discover: self.pending_flood_jobs.append(target) # Execute a pending trigger-job if there is one. if self.pending_trigger_jobs != []: self.scanner.parser.dont_read = False self.create_trigger_jobs() elif self.nactive_trigger_jobs == 0: # No pending-trigger-jobs left, no active # trigger-jobs left, execute flood-jobs banner_printed = False nhosts = 0 for trig_job in self.scanner.triggerJobs: if not banner_printed: print "+++ Trigger-Phase done. The following hosts are up: +++" banner_printed = True if self.scanner.triggerJobs[trig_job].triggers == []: if self.scanner.triggerJobs[trig_job].got_arp_rsp: print trig_job + " NO-TRIGGERS" nhosts = nhosts + 1 continue else: trigger_job = self.scanner.triggerJobs[trig_job] print trigger_job.target + " " + trigger_job.triggers[0].method + " " + trigger_job.triggers[0].rnd nhosts = nhosts + 1 if not banner_printed: print "All hosts seem down." else: print str(nhosts) + " hosts total." self.scanner.parser.dont_read = False self.create_flood_jobs() # No jobs left, exit. if self.nactive_trigger_jobs + self.nactive_flood_jobs == 0: print "All done" # Shut down the scanner stopUserEventHandler(self.event_handler,self.options_parser) stopParserThread(self.scanner.parser) return else: self.scanner.parser.dont_read = False