scannotebook.py

来自「Ubuntu packages of security software。 相」· Python 代码 · 共 1,296 行 · 第 1/4 页

PY
1,296
字号
        """Go to host line on nmap output result"""        self.scan_result.scan_result_notebook.nmap_output.nmap_output.go_to_host(host)    def __create_scan_result(self):        self.scan_result = ScanResult()    def __create_toolbar(self):        self.toolbar = ScanToolbar()        self.empty_target = _("<target>")                self.toolbar.target_entry.connect('changed', self.refresh_command_target)        self.toolbar.profile_entry.connect('changed', self.refresh_command)        self.toolbar.scan_button.connect('clicked', self.start_scan_cb)        def __create_command_toolbar(self):        self.command_toolbar = ScanCommandToolbar()        self.command_toolbar.command_entry.connect('activate',                                    lambda x: self.toolbar.scan_button.clicked())        # This variable says if the command at command entry was edited by user        self.command_edited = False        # When user clicks insite the command entry for edition        self.command_toolbar.command_entry.connect("focus-in-event", self.remember_command)        # When user gets out of the command entry after edition        self.command_toolbar.command_entry.connect("focus-out-event", self.check_command)    def remember_command(self, widget, extra=None):        # User is inside command entry, probably editing it...                self.old_target = self.toolbar.target_entry.selected_target # Target may be empty        if not self.old_target:            self.old_target = self.empty_target        self.old_full_command = self.command_toolbar.command_entry.get_text()        self.old_command = self.old_full_command.split(self.old_target)[0]            def check_command(self, widget, extra=None):        # User has left command entry. Verify if something has changed!        new_command = self.command_toolbar.command        #print "New:", new_command        #print "Old:", self.old_full_command        #if new_command != self.old_full_command:        #    print "Gosh! Is different!! Now, what?"        #target = self.toolbar.target_entry.selected_target        #if self.saved_target:        #    self.saved_command = self.command_toolbar.command_entry.get_text().split(        #                                                                   self.saved_target)[0]        #else:        #    self.saved_command = self.command_toolbar.command_entry.get_text().split(        #                                                                      _("<target>"))[0]        #        #print self.saved_target        #print self.saved_command        def disable_widgets(self):        self.scan_result.set_sensitive(False)        def enable_widgets(self):        self.scan_result.set_sensitive(True)        def refresh_command_target(self, widget):        #log.debug(">>> Refresh Command Target")                profile = self.toolbar.selected_profile        #log.debug(">>> Profile: %s" % profile)                if profile != '':            target = self.toolbar.selected_target            #log.debug(">>> Target: %s" % target)            try:                cmd_profile = CommandProfile()                command = cmd_profile.get_command(profile) % target                del(cmd_profile)                                self.command_toolbar.command = command            except ProfileNotFound:                pass # Go without a profile            except TypeError:                pass # The target is empty...                #self.profile_not_found_dialog()        def refresh_command(self, widget):        #log.debug(">>> Refresh Command")        profile = self.toolbar.selected_profile        target = self.toolbar.selected_target        #log.debug(">>> Profile: %s" % profile)        #log.debug(">>> Target: %s" % target)                if target == '':            target = self.empty_target                try:            cmd_profile = CommandProfile()            command = cmd_profile.get_command(profile) % target            del(cmd_profile)                        self.command_toolbar.command = command        except ProfileNotFound:            pass            #self.profile_not_found_dialog()        except TypeError:            pass # That means that the command string convertion "%" didn't work    def profile_not_found_dialog(self):        warn_dialog = HIGAlertDialog(message_format=_("Profile not found!"),                                     secondary_text=_("The profile name you \selected/typed couldn't be found, and probably doesn't exist. Please, check the profile \name and try again."),                                     type=gtk.MESSAGE_QUESTION)        warn_dialog.run()        warn_dialog.destroy()    def get_tab_label(self):        return self.get_parent().get_tab_title(self)    def set_tab_label(self, label):        self.get_parent().set_tab_title(self, label)        def start_scan_cb(self, widget=None):        target = self.toolbar.selected_target        command = self.command_toolbar.command        profile = self.toolbar.selected_profile        log.debug(">>> Start Scan:")        log.debug(">>> Target: '%s'" % target)        log.debug(">>> Profile: '%s'" % profile)        log.debug(">>> Command: '%s'" % command)        if target and profile:            self.set_tab_label("%s on %s" %(profile, target))        elif target:            self.set_tab_label("Scan on %s" % target)        elif profile:            self.set_tab_label(profile)        if target != '':                self.toolbar.add_new_target(target)        if (command.find("-iR") == -1 and command.find("-iL") == -1):            if command.find("<target>") > 0:                warn_dialog = HIGAlertDialog(message_format=_("No Target Host!"),                                              secondary_text=_("Target specification \is mandatory. Either by an address in the target input box or through the '-iR' and \'-iL' nmap options. Aborting scan."),                                             type=gtk.MESSAGE_ERROR)                warn_dialog.run()                warn_dialog.destroy()                return        if command != '':            # Setting status to scanning            self.status.set_scanning()            self.execute_command(command)        else:            warn_dialog = HIGAlertDialog(message_format=_("Empty Nmap Command!"),                                         secondary_text=_("There is no command to  \execute! Maybe the selected/typed profile doesn't exist. Please, check the profile name \or type the nmap command you would like to execute."),                                         type=gtk.MESSAGE_ERROR)            warn_dialog.run()            warn_dialog.destroy()    def close_tab(self):        try:            gobject.source_remove(self.verify_thread_timeout_id)        except:            pass    def collect_umit_info(self):        profile = CommandProfile()        profile_name = self.toolbar.selected_profile                self.parsed.target = self.toolbar.get_target()        self.parsed.profile_name = profile_name        self.parsed.nmap_command = self.command_toolbar.get_command()        self.parsed.profile = profile.get_command(profile_name)        self.parsed.profile_hint = profile.get_hint(profile_name)        self.parsed.profile_description = profile.get_description(profile_name)        self.parsed.profile_annotation = profile.get_annotation(profile_name)        self.parsed.profile_options = profile.get_options(profile_name)        del(profile)        try:            self.parsed.nmap_output = self.command_execution.get_raw_output()        except:            self.parsed.nmap_output = self.scan_result.get_nmap_output()    def kill_scan(self):        try:            self.command_execution.kill()        except AttributeError:            pass        self.scan_result.clear_nmap_output()        self.scan_result.clear_host_view()        self.status.set_empty()        self.disable_widgets()        def execute_command(self, command):        log.critical("execute_command %s" % command)        try:            alive = self.command_execution.scan_state()            if alive:                warn_dialog = HIGAlertDialog(message_format=_("Scan has not finished yet"),                                             secondary_text=_("Another scan is running in \the background. To start another scan and kill the old one, click Ok. To wait for the \conclusion of the old scan, choose Cancel."),                                             type=gtk.MESSAGE_QUESTION,                                             buttons=gtk.BUTTONS_OK_CANCEL)                response = warn_dialog.run()                warn_dialog.destroy()                if response == gtk.RESPONSE_OK:                    # Kill current scan, and let the another one to be created                    self.kill_scan()                else:                    return        except:            pass        self.command_execution = NmapCommand(command)                try:            self.command_execution.run_scan()        except Exception, msg:            warn_dialog = HIGAlertDialog(message_format=_("Command is missing!"),                                         secondary_text=_("It seems that your profile's \command is missing or something else went wrong. Please, try to remove and recreate your profile."),                                         type=gtk.MESSAGE_ERROR)            warn_dialog.run()            warn_dialog.destroy()        # Ask NmapOutputViewer to show/refresh nmap output from given file        self.scan_result.show_nmap_output(self.command_execution.get_output_file())        # Set a "EXECUTING" icon to host list        self.scan_result.set_hosts({SCANNING:{'stock':gtk.STOCK_EXECUTE,'action':None}})        self.scan_result.set_services({SCANNING:{'action':None}})        # Clear port list, to remove old information        self.scan_result.clear_port_list()        # When scan starts, change to nmap output view tab and refresh output        self.scan_result.change_to_nmap_output_tab()        self.scan_result.refresh_nmap_output()                self.enable_widgets()        # Add a timeout function        self.verify_thread_timeout_id = gobject.timeout_add(2000, self.verify_execution)    def verify_execution(self):        # Using new subprocess style        try:            alive = self.command_execution.scan_state()        except:            self.disable_widgets()            self.status.set_scan_failed()            self.scan_result.set_nmap_output(self.command_execution.get_error())            return False        #log.debug(">>> Process alive? %s" % alive)        #log.debug(">>> Nmap output:\n %s" % self.command_execution.get_output())        # Maybe this automatic refresh should be eliminated to avoid processor burning        self.scan_result.refresh_nmap_output()                if alive:            return True        else:            self.parse_result(self.command_execution.get_xml_output_file())            return False    def load_result(self, file_to_parse):        ####        # Setting status to parsing_result        self.status.set_parsing_result()        ####        self._parse(file_to_parse=file_to_parse)        ####        # Setting status to loaded_unchanged        self.status.set_loaded_unchanged()        ####    def parse_result(self, file_to_parse):        ####        # Setting status to parsing_result        self.status.set_parsing_result()        ####        self._parse(file_to_parse=file_to_parse)        ####        # Setting status to unsaved_unchanged        self.status.set_unsaved_unchanged()        ####    def load_from_parsed_result(self, parsed_result):        ####        # Setting status to parsing_result        self.status.set_parsing_result()        ####        self._parse(parsed_result=parsed_result)        ####        # Setting status to unsaved_unchanged        self.status.set_unsaved_unchanged()        ####    def _parse(self, file_to_parse=None, parsed_result=None):        '''Called when scan is done. Verify if any host were found        '''

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?