def execute_command(self, command, target = None, profile = None): """Run the given Nmap command. Add it to the list of running scans. Schedule a timer to refresh the output and check the scan for completion.""" command_execution = NmapCommand(command) command_execution.profile = profile try: command_execution.run_scan() except Exception, e: text = str(e) if isinstance(e, OSError): # Handle ENOENT specially. if e.errno == errno.ENOENT: # nmap_command_path comes from zenmapCore.NmapCommand. text += "\n\n" + _("This means that the nmap executable was not found in your system PATH, which is") + "\n\n" + os.getenv("PATH", _("<undefined>")) path_env = os.getenv("PATH") if path_env is None: default_paths = [] else: default_paths = path_env.split(os.pathsep) extra_paths = get_extra_executable_search_paths() extra_paths = [p for p in extra_paths if p not in default_paths] if len(extra_paths) > 0: if len(extra_paths) == 1: text += "\n\n" + _("plus the extra directory") else: text += "\n\n" + _("plus the extra directories") text += "\n\n" + os.pathsep.join(extra_paths) warn_dialog = HIGAlertDialog(message_format=_("Error executing command"), secondary_text=text, type=gtk.MESSAGE_ERROR) warn_dialog.run() warn_dialog.destroy() return
def execute_command(self, command, target = None, profile = None): """Run the given Nmap command. Add it to the list of running scans. Schedule a timer to refresh the output and check the scan for completion.""" command_execution = NmapCommand(command) command_execution.profile = profile try: command_execution.run_scan() except Exception, e: text = str(e) if isinstance(e, OSError): # Handle ENOENT specially. if e.errno == errno.ENOENT: # nmap_command_path comes from zenmapCore.NmapCommand. text += "\n\n" + _("This means that the nmap executable was not found in your system PATH, which is") + "\n\n" + os.getenv("PATH", _("<undefined>")) path_env = os.getenv("PATH") if path_env is None: default_paths = [] else: default_paths = path_env.split(os.pathsep) extra_paths = get_extra_executable_search_paths() extra_paths = [p for p in extra_paths if p not in default_paths] if len(extra_paths) > 0: if len(extra_paths) == 1: text += "\n\n" + _("plus the extra directory") else: text += "\n\n" + _("plus the extra directories") text += "\n\n" + os.pathsep.join(extra_paths) warn_dialog = HIGAlertDialog(message_format=_("Error executing command"), secondary_text=text, type=gtk.MESSAGE_ERROR) warn_dialog.run() warn_dialog.destroy() return
def get_script_list(self, rules, callback): """Start an Nmap subprocess in the background with "--script-help=<rules> -oX -", and set it up to call the given callback when finished.""" ops = NmapOptions() ops.executable = paths_config.nmap_command_path ops["--script-help"] = rules ops["-oX"] = "-" command_string = ops.render_string() # Separate stderr to avoid breaking XML parsing with "Warning: File # ./nse_main.lua exists, but Nmap is using...". stderr = tempfile.TemporaryFile(mode="rb", prefix=APP_NAME + "-script-help-stderr-") log.debug("Script interface: running %s" % repr(command_string)) nmap_process = NmapCommand(command_string) try: nmap_process.run_scan(stderr=stderr) except Exception as e: callback(False, None) stderr.close() return stderr.close() self.script_list_widget.set_sensitive(False) gobject.timeout_add(self.NMAP_DELAY, self.script_list_timer_callback, nmap_process, callback)
def execute_command(self, command, target=None, profile=None): """Run the given Nmap command. Add it to the list of running scans. Schedule a timer to refresh the output and check the scan for completion.""" try: command_execution = NmapCommand(command) except IOError, e: warn_dialog = HIGAlertDialog( message_format=_("Error building command"), secondary_text=_("Error message: %s") % str(e), type=gtk.MESSAGE_ERROR) warn_dialog.run() warn_dialog.destroy() return
def execute_command(self, command, target=None, profile=None): """If scan state is alive and user responds OK, stop the currently active scan and allow creation of another, and if user responds Cancel, wait the current scan to finish. Invokes NmapCommand for execution. Verifies if a valid nmap executable exists in PATH, if not, displays error with the offending PATH. Refreshes and changes to nmap output view from given file.""" command_execution = NmapCommand(command) command_execution.target = target command_execution.profile = profile try: command_execution.run_scan() except Exception, e: text = str(e) if type(e) == OSError: # Handle ENOENT specially. if e.errno == errno.ENOENT: # nmap_command_path comes from zenmapCore.NmapCommand. text += "\n\n" + _( "This means that the nmap executable was not found in your system PATH, which is" ) + "\n\n" + os.getenv("PATH", _("<undefined>")) path_env = os.getenv("PATH") if path_env is None: default_paths = [] else: default_paths = path_env.split(os.pathsep) extra_paths = get_extra_executable_search_paths() extra_paths = [ p for p in extra_paths if p not in default_paths ] if len(extra_paths) > 0: if len(extra_paths) == 1: text += "\n\n" + _("plus the extra directory") else: text += "\n\n" + _("plus the extra directories") text += "\n\n" + os.pathsep.join(extra_paths) warn_dialog = HIGAlertDialog( message_format=_("Error executing command"), secondary_text=text, type=gtk.MESSAGE_ERROR) warn_dialog.run() warn_dialog.destroy() return