コード例 #1
0
def main():
    try:
        TARGET_IP = "127.0.0.1"
        OPENVAS_HOST = "127.0.0.1"
        USER = "******"
        PASSWORD = "******"
        PORT = 9390
        TIMEOUT = None
        #profile = "empty"
        profile = "Full and fast"
        manager = VulnscanManager(OPENVAS_HOST, USER, PASSWORD)

        sem = Semaphore(0)

        # Launch
        scan_id, target_id = manager.launch_scan(
            target=TARGET_IP,
            profile=profile,
            callback_end=partial(lambda x: x.release(), sem),
            callback_progress=my_print_status)

        print "scan_id=%s , target_id=%s " % (scan_id, target_id)

        # Wait
        sem.acquire()

        # Finished scan
        print("finished")

        report_id = manager.get_report_id(scan_id)
        write_report(manager, report_id, TARGET_IP)
        manager.delete_scan(scan_id)
        manager.delete_target(target_id)

    except VulnscanException, e:
        print "Error:"
        print e
コード例 #2
0
ファイル: openvas.py プロジェクト: qiuyuanchunwei/golismero
    def recv_info(self, info):

        # Checks if connection was not set as down
        if not self.state.check("connection_down"):

            # Synchronization object to wait for completion.
            m_event = Event()

            # Get the config.
            m_user      = Config.plugin_args["user"]
            m_password  = Config.plugin_args["password"]
            m_host      = Config.plugin_args["host"]
            m_port      = Config.plugin_args["port"]
            m_timeout   = Config.plugin_args["timeout"]
            m_profile   = Config.plugin_args["profile"]

            # Sanitize the port and timeout.
            try:
                m_port = int(m_port)
            except Exception:
                m_port = 9390
            if m_timeout.lower().strip() in ("inf", "infinite", "none"):
                m_timeout = None
            else:
                try:
                    m_timeout = int(m_timeout)
                except Exception:
                    m_timeout = None

            # Connect to the scanner.
            try:
                Logger.log_more_verbose(
                    "Connecting to OpenVAS server at %s:%d" % (m_host, m_port))
                m_scanner = VulnscanManager(
                    m_host, m_user, m_password, m_port, m_timeout)
            except VulnscanException, e:
                t = format_exc()
                Logger.log_error("Error connecting to OpenVAS, aborting scan!")
                #Logger.log_error_verbose(str(e))
                Logger.log_error_more_verbose(t)

                # Set the openvas connection as down and remember it.
                self.state.put("connection_down", True)
                return

            m_scan_id   = None
            m_target_id = None
            try:
                # Launch the scanner.
                m_scan_id, m_target_id = m_scanner.launch_scan(
                    target = info.address,
                    profile = m_profile,
                    callback_end = partial(lambda x: x.set(), m_event),
                    callback_progress = OpenVASProgress(self.update_status)
                )
                Logger.log_more_verbose("OpenVAS task ID: %s" % m_scan_id)

                # Wait for completion.
                m_event.wait()

                # Get the scan results.
                m_openvas_results = m_scanner.get_results(m_scan_id)

                # Clear the info
                m_scanner.delete_scan(m_scan_id)
                m_scanner.delete_target(m_target_id)

            except Exception,e:
                t = format_exc()
                Logger.log_error_verbose(
                    "Error parsing OpenVAS results: %s" % str(e))
                Logger.log_error_more_verbose(t)
                return
コード例 #3
0
    def recv_info(self, info):



        # Checks if connection was not setted as down
        if not self.state.check("connection_down"):

            # Synchronization object to wait for completion.
            m_event = Event()

            # Get the config.
            m_user      = Config.plugin_args["user"]
            m_password  = Config.plugin_args["password"]
            m_host      = Config.plugin_args["host"]
            m_port      = Config.plugin_args["port"]
            m_timeout   = Config.plugin_args["timeout"]
            m_profile   = Config.plugin_args["profile"]

            # Sanitize the port and timeout.
            try:
                m_port = int(m_port)
            except Exception:
                m_port = 9390
            if m_timeout.lower().strip() in ("inf", "infinite", "none"):
                m_timeout = None
            else:
                try:
                    m_timeout = int(m_timeout)
                except Exception:
                    m_timeout = None

            # Connect to the scanner.
            try:
                Logger.log_more_verbose(
                    "Connecting to OpenVAS server at %s:%d" % (m_host, m_port))
                m_scanner = VulnscanManager(
                    m_host, m_user, m_password, m_port, m_timeout)
            except VulnscanException, e:
                t = format_exc()
                Logger.log_error("Error connecting to OpenVAS, aborting scan!")
                #Logger.log_error_verbose(str(e))
                Logger.log_error_more_verbose(t)

                # Set the openvas connection down and remember it.
                self.state.put("connection_down", True)
                return

            try:
                # Launch the scanner.
                m_scan_id, m_target_id = m_scanner.launch_scan(
                    target = info.address,
                    profile = m_profile,
                    callback_end = partial(lambda x: x.set(), m_event),
                    callback_progress = OpenVASProgress(self.update_status)
                )
                Logger.log_more_verbose("OpenVAS task ID: %s" % m_scan_id)

                # Wait for completion.
                m_event.wait()

                # Get the scan results.
                m_openvas_results = m_scanner.get_results(m_scan_id)

                # Clear the info

                m_scanner.delete_scan(m_scan_id)
                m_scanner.delete_target(m_target_id)

                # Convert the scan results to the GoLismero data model.
                return self.parse_results(m_openvas_results, info)
            except Exception,e:
                t = format_exc()
                Logger.log_error_verbose(
                    "Error parsing OpenVAS results: %s" % str(e))
                Logger.log_error_more_verbose(t)