Beispiel #1
0
def launch_scanner(target):
    print("start scan " + target)
    sem = Semaphore(0)

    # Configure
    manager = VulnscanManager("localhost", "admin", "openvas")

    # Launch
    scan_id, target_id = manager.launch_scan(target = target,
                        profile = "Full and fast",
                        callback_end = partial(lambda x: x.release(), sem),
                        callback_progress = print_status)

    # Wait
    sem.acquire()

    # Finished scan
    print("finished")
    openvas_results = manager.get_results(scan_id)
    results = []
    for opr in openvas_results:
        results.append({
            "id": opr.id,
            "subnet": opr.subnet,
            "host": opr.host,
            "port": {
                "port_name": opr.port.port_name,
                "number": opr.port.number,
                "proto": opr.port.proto
            },
            "nvt": {
                "oid" : opr.nvt.oid,
                "name" : opr.nvt.name,
                "cvss_base" : opr.nvt.cvss_base,
                "cvss_base_vector" : opr.nvt.cvss_base_vector,
                "risk_factor" : opr.nvt.risk_factor,
                "category" : opr.nvt.category,
                "summary" : opr.nvt.summary,
                "description" : opr.nvt.description,
                "family" : opr.nvt.family,
                "cves" : opr.nvt.cve,
                "bids" : opr.nvt.bid,
                "bugtraqs" : opr.nvt.bugtraq,
                "xrefs" : opr.nvt.xrefs,
                "fingerprints" : opr.nvt.fingerprints,
                "tags" : opr.nvt.tags
            },
            "threat": opr.threat,
            "description": opr.raw_description,
            "notes": opr.notes,
            "overrides": opr.overrides,
            "impact": opr.impact,
            "summary": opr.summary,
            "vulnerability_insight": opr.vulnerability_insight,
            "affected_software": opr.affected_software,
            "solution": opr.solution
        })
    return results
Beispiel #2
0
def scan_entity(ip,openvas_conf):
    
    Sem = Semaphore(0)
    # Configure
    print "ip is",ip
    #print "openvas addr is",openvas_conf['addr']
    #print "openvas pass is",openvas_conf['pass']
    
    manager = VulnscanManager(openvas_conf['addr'].encode("utf-8"),\
                             openvas_conf['user'].encode("utf-8"),\
                             openvas_conf['pass'].encode("utf-8"))
    # Launch
    scan_id,target_id = manager.launch_scan(ip,
				profile = "Full and fast",
				callback_end = partial(lambda x: x.release(), Sem),
				callback_progress = my_print_status)
    # Wait
    Sem.acquire()
    # Finished scan
    print "finished"
    #scan_id=""
    #pdb.set_trace()
    #if get all results set False or set True 
    res_list= manager.get_results(scan_id,True)
    
    svc_name=''

    # initial requests
    requests.packages.urllib3.disable_warnings()
    #host_vuln = host_sample()

    for res in res_list:
        if not res.description:
            desc = ''
        else:
            desc = res.description
        create_time = str(int(time.mktime(datetime.datetime.now().timetuple())) * 1000)
        resentity['VulnerID'] = str(uuid.uuid1())
        resentity['Name'] = res.name
        resentity['HostIP'] = res.host
        resentity['Severity'] = res.severity
        resentity["Family"]=res.nvt.family
        resentity["Port"]=res.port.number
        resentity["Protocol"]=res.port.proto
        resentity["SvcName"]=str(res.port.number) + res.port.proto
        resentity["QOD"]=res.qod
        resentity["CVE"]=res.nvt.raw_cves
        resentity["BID"]=res.nvt.raw_bids
        resentity["CvssBase"]=res.nvt.cvss_base_vector
        resentity["CERT"]=res.nvt.cert
        resentity["Impact"]=res.nvt.impact
        resentity["Desc"]=desc
        resentity["Solution"]=res.nvt.solution
        resentity["Refer"]=res.nvt.raw_xrefs
        resentity["source"]="0"
        resentity["Time"]=create_time
		print "size of result list is ============", resentity
Beispiel #3
0
def my_launch_scanner():
    sem = Semaphore(0)

    # Configure
    manager = VulnscanManager("localhost", "admin", "admin")

    # Launch
    task, target = manager.launch_scan('10.10.10.130',
                        profile="empty",
                        callback_end=partial(lambda x: x.release(), sem),
                        callback_progress=my_print_status)

    # Wait
    sem.acquire()

    # Finished scan
    print("finished")
    print(task)
    print(target)
    manager.get_results(task_id=task)
Beispiel #4
0
def my_launch_scanner():
    sem = Semaphore(0)
    #
    # # Configure
    manager = VulnscanManager("localhost", "admin", "123456")

    # Launch
    scan_id, target_id = manager.launch_scan('192.168.86.12',
                                             profile="Full and fast",
                                             callback_end=partial(
                                                 lambda x: x.release(), sem),
                                             callback_progress=my_print_status)
    print(scan_id)
    sem.acquire()
    res = manager.get_results(scan_id)
    for flag in res:
        print(
            '------------------------------------------------------------------------------------------------------------'
        )
        # print('impact:' + flag.impact + '  summary:' + flag.summary + '  vulnerability:' + flag.vulnerability_insight)
        print('vulnerability:' + str(flag.vulnerability_insight) +
              '  affected_software:' + str(flag.affected_software) +
              '  notes:' + str(flag.notes))
        print('raw_description:' + str(flag.raw_description) + '  overrides:' +
              str(flag.overrides))
        print('port:' + str(flag.port) + '  threat:' + str(flag.threat) +
              '  severity:' + str(flag.severity))
        print('nvt_name:' + str(flag.nvt.name) + '  cvss_base_vector:' +
              str(flag.nvt.cvss_base_vector) + '  cvss_base:' +
              str(flag.nvt.cvss_base))
        print('risk_factor' + str(flag.nvt.risk_factor) + '  summary:' +
              str(flag.nvt.summary) + '  description:' +
              str(flag.nvt.description))
        print('family:' + str(flag.nvt.family) + '  category:' +
              str(flag.nvt.category) + '  cve:' + str(flag.nvt.cve))
        print('bugtrap: ' + str(flag.nvt.bugtraq) + '  xrefs:' +
              str(flag.nvt.xrefs) + 'fingerprints:' +
              str(flag.nvt.fingerprints))
        print(
            '---------------------------------------------------------------------------------------------------------'
        )
    # Finished scan
    print("finished")
Beispiel #5
0
    def run(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 VulnscanVersionError:
                Logger.log_error(
                    "Remote host is running an unsupported version of OpenVAS."
                    " Only OpenVAS 6 is currently supported.")

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

            except VulnscanException, e:
                t = format_exc()
                Logger.log_error("Error connecting to OpenVAS, aborting scan!")
                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)

            except Exception, e:
                t = format_exc()
                Logger.log_error_verbose("Error parsing OpenVAS results: %s" %
                                         str(e))
                Logger.log_error_more_verbose(t)
                return
Beispiel #6
0
    def run(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 VulnscanVersionError:
                Logger.log_error(
                    "Remote host is running an unsupported version of OpenVAS."
                    " Only OpenVAS 6 is currently supported.")

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

            except VulnscanException, e:
                t = format_exc()
                Logger.log_error("Error connecting to OpenVAS, aborting scan!")
                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)

            except Exception, e:
                t = format_exc()
                Logger.log_error_verbose(
                    "Error parsing OpenVAS results: %s" % str(e))
                Logger.log_error_more_verbose(t)
                return