def CreateFromXML(xml):
        sites = [
            site for site in get_children_of(xml, 'Sites')
            if site.tag == 'Site'
        ]

        service = get_attribute(get_element(xml, "Services/Service"), 'type')
        credential = SharedCredentialConfiguration()
        credential.id = int(get_attribute(xml, "id"))
        credential.name = get_content_of(xml, "Name")
        credential.description = get_content_of(xml, "Description")
        credential.credential = Credential.CreateFromXML(
            get_element(xml, "Account"), service)
        credential.restriction_host = get_content_of(
            xml, "Restrictions/Restriction/[@type='host']",
            credential.restriction_host)
        credential.restriction_port = int(
            get_content_of(xml, "Restrictions/Restriction/[@type='port']",
                           credential.restriction_port))
        credential.all_sites = get_attribute(get_element(xml, "Sites"),
                                             'all') == '1'
        credential.enabled_sites = [
            get_attribute(site, 'id') for site in sites
            if get_attribute(site, 'enabled') == '1'
        ]
        credential.disabled_sites = [
            get_attribute(site, 'id') for site in sites
            if get_attribute(site, 'enabled') != '1'
        ]
        return credential
	def CreateFromXML(xml_data):
		xml_description = get_element(xml_data, 'description')
		xml_solution = get_element(xml_data, 'solution')
		
		reference_generator = imap(lambda xml_reference: VulnerabilityReference.CreateFromXML(xml_reference), xml_data.iterfind('references/reference'))
		config = VulnerabilityDetail()
		config.InitalizeFromXML(xml_data)
		config.description = as_string(xml_description) if xml_description is not None else config.description
		config.references = list(reference_generator)
		config.solution = as_string(xml_solution) if xml_solution is not None else config.solution
		return config
	def CreateFromXML(xml_data):
		xml_devices = get_element(xml_data, 'Devices', None)
		print as_string(xml_data)
		config = AssetGroupConfiguration()
		config.InitializeFromXML(xml_data)
		config.description = config.short_description
		if xml_devices is not None:
			config.asset_summaries = [AssetSummary.CreateFromXML(xml_device) for xml_device in xml_devices.getchildren() if xml_device.tag == 'device']
		return config
Ejemplo n.º 4
0
	def CreateFromXML(xml_data):
		xml_event = get_element(xml_data, 'Event')
		event = TicketEvent()
		event.title = xml_event.text
		event.author = get_attribute(xml_data, 'author', event.author)
		event.created_on = get_attribute(xml_data, 'created-on', event.created_on) # TODO: datetime object!
		event.state = get_attribute(xml_event, 'state', TicketState.UNKNOWN)
		event.comment = get_content_of(xml_data, 'Comment', event.comment)
		return event
Ejemplo n.º 5
0
def counter(gt_obj, rs_det_list, IOU_threshold):
    """
    Purpose: counter of rs and tp
    Args: 
        gt_obj: from get_elements(gt_xml_root, "object")
        rs_det_list: list  from get_elements(rs_xml_root, "detection")
        IOU_threshold: threshold of IOU
    """
    # 当GT目标是gt_obj_name时
    gt_obj_name = get_element(gt_obj, "name").text
    c = categoryDict[gt_obj_name]
    c.bdb.gt_inc()
    c.obb.gt_inc()
    c.seg.gt_inc()
    # 遍历测试结果的检测标注
    for rs_det in rs_det_list:
        if get_element(rs_det, "name").text == gt_obj_name:
            c.bdb.rs_inc()
            c.obb.rs_inc()
            c.seg.rs_inc()
            # ============= bdb =============
            if get_IoU(gt_obj, rs_det, DETECTION.bndbox) >= IOU_threshold:
                c.bdb.tp_inc()
Ejemplo n.º 6
0
    def CreateFromXML(xml_data):
        config = SiteConfiguration()
        config.InitalizeFromXML(xml_data)
        config.description = get_content_of(xml_data, 'Description', config.description)
        config.is_dynamic = get_attribute(xml_data, 'isDynamic', config.is_dynamic) in ['1', 'true', True]
        config.hosts = [_host_to_object(host) for host in get_children_of(xml_data, 'Hosts')]
        config.alerting = [alert for alert in get_children_of(xml_data, 'Alerting')]
        config.credentials = [credential for credential in get_children_of(xml_data, 'Credentials')]
        config.users = [user for user in get_children_of(xml_data, 'Users')]

        # Use scanconfig elements for the SiteConfiguration
        scanconfig = get_element(xml_data, "ScanConfig")
        config.configid = scanconfig.get("configID")
        config.configtemplateid = scanconfig.get("templateID")
        config.configname = scanconfig.get("name")
        config.configversion = scanconfig.get("configVersion")
        config.configengineid = scanconfig.get("engineID")
        config.schedules = [schedule for schedule in get_children_of(scanconfig, 'Schedules')]

        return config
Ejemplo n.º 7
0
 def CreateFromXML(xml_data):
     summary = ScanSummary()
     summary.id = int(get_attribute(xml_data, 'scan-id', summary.id))
     summary.site_id = int(
         get_attribute(xml_data, 'site-id', summary.site_id))
     summary.engine_id = int(
         get_attribute(xml_data, 'engine-id', summary.engine_id))
     summary.scan_status = get_attribute(xml_data, 'status',
                                         summary.scan_status)
     summary.start_time = get_attribute(xml_data, 'startTime',
                                        summary.start_time)
     summary.end_time = get_attribute(xml_data, 'endTime', summary.end_time)
     summary.name = get_attribute(xml_data, 'name', summary.name)
     if get_content_of(xml_data, 'message') is not None:
         summary.message = get_content_of(xml_data, 'message',
                                          summary.message)
     else:
         summary.message = get_content_of(xml_data, 'Message',
                                          summary.message)
     if get_element(xml_data, 'tasks') is not None:
         summary.task_counts = ScanSummaryTaskCounts.CreateFromXML(
             get_element(xml_data, 'tasks', summary.task_counts))
     else:
         summary.task_counts = ScanSummaryTaskCounts.CreateFromXML(
             get_element(xml_data, 'TaskSummary', summary.task_counts))
     if get_element(xml_data, 'nodes') is not None:
         summary.node_counts = ScanSummaryNodeCounts.CreateFromXML(
             get_element(xml_data, 'nodes', summary.node_counts))
     else:
         summary.node_counts = ScanSummaryNodeCounts.CreateFromXML(
             get_element(xml_data, 'NodeSummary', summary.node_counts))
     if get_element(xml_data, 'vulnerabilities') is not None:
         summary.vulnerabilities = map(
             ScanSummaryVulnerability.CreateFromXML,
             xml_data.findall('vulnerabilities'))
     else:
         summary.vulnerabilities = map(
             ScanSummaryVulnerability.CreateFromXML,
             xml_data.findall('VulnerabilitySummary'))
     return summary
Ejemplo n.º 8
0
def get_IoU(gt_obj, rs_det, detection):
    """
    Purpose: return a IoU of groundtruth and result  
    Args: 
        gt_obj: element in groundtruth xml 
        rs_det: element in result xml 
        detection: bndbox, rotbox, seg
    Returns: 
        iou: the IOU of groundtruth and result 
    """
    if detection is DETECTION.bndbox:
        # 获得GT的gun的bbox
        gt_bdb = get_element(gt_obj, "bndbox")
        gt_bdb_xmin = int(get_element(gt_bdb, "xmin").text)
        gt_bdb_ymin = int(get_element(gt_bdb, "ymin").text)
        gt_bdb_xmax = int(get_element(gt_bdb, "xmax").text)
        gt_bdb_ymax = int(get_element(gt_bdb, "ymax").text)
        gt_bbox = xyxy2xywh(
            [gt_bdb_xmin, gt_bdb_ymin, gt_bdb_xmax, gt_bdb_ymax])
        # 获得测试结果的gun的bbox
        rs_bdb = get_element(rs_det, "bndbox")
        rs_bdb_x = int(get_element(rs_bdb, "x").text)
        rs_bdb_y = int(get_element(rs_bdb, "y").text)
        rs_bdb_w = int(get_element(rs_bdb, "w").text)
        rs_bdb_h = int(get_element(rs_bdb, "h").text)
        rs_bbox = [rs_bdb_x, rs_bdb_y, rs_bdb_w, rs_bdb_h]
        # 获得GT和res的交并比
        iou = get_IoU_rect(gt_bbox, rs_bbox)
    elif detection is DETECTION.rotbox:
        gt_obb_poly = text2polygon(get_element(gt_obj, "rotbox").text)
        rs_obb_poly = text2polygon(get_element(rs_det, "rotationbox").text)
        iou = get_IoU_polygon(gt_obb_poly, rs_obb_poly)
    elif detection is DETECTION.seg:
        gt_seg_poly = text2polygon(get_element(gt_obj, "segmentation").text)
        rs_seg_poly = text2polygon(get_element(rs_det, "segmentation").text)
        iou = get_IoU_polygon(gt_seg_poly, rs_seg_poly)
    else:
        raise Exception("Unknow detection!")
    return iou