コード例 #1
0
ファイル: parsers.py プロジェクト: muchrons/vmc
 def create(item: RestrictedElement) -> Asset:
     os = get_value(item.find(".//tag[@name='operating-system']"))
     asset, _ = Asset.objects.get_or_create(
         ip_address=item.find(".//tag[@name='host-ip']").text,
         mac_address=get_value(item.find(".//tag[@name='mac-address']")),
         os=os if os else 'Unknown')
     return asset
コード例 #2
0
ファイル: util.py プロジェクト: warmunger/exchangelib
def create_element(name, **attrs):
    # copy.deepcopy() is an order of magnitude faster than creating a new Element() every time
    if ':' in name:
        ns, name = name.split(':')
        name = '{%s}%s' % (ns_translation[ns], name)
    elem = RestrictedElement(**attrs)
    elem.tag = name
    return elem
コード例 #3
0
ファイル: util.py プロジェクト: ecederstrand/exchangelib
def create_element(name, **attrs):
    # copy.deepcopy() is an order of magnitude faster than creating a new Element() every time
    if ':' in name:
        ns, name = name.split(':')
        name = '{%s}%s' % (ns_translation[ns], name)
    elem = RestrictedElement(**attrs)
    elem.tag = name
    return elem
コード例 #4
0
def create_element(name, attrs=None, nsmap=None):
    # Python versions prior to 3.6 do not preserve dict or kwarg ordering, so we cannot pull in attrs as **kwargs if we
    # also want stable XML attribute output. Instead, let callers supply us with an OrderedDict instance.
    if ':' in name:
        ns, name = name.split(':')
        name = '{%s}%s' % (ns_translation[ns], name)
    elem = RestrictedElement(attrib=attrs, nsmap=nsmap)
    elem.tag = name
    return elem
コード例 #5
0
def create_element(name, attrs=None, nsmap=None):
    # Python versions prior to 3.6 do not preserve dict or kwarg ordering, so we cannot pull in attrs as **kwargs if we
    # also want stable XML attribute output. Instead, let callers supply us with an OrderedDict instance.
    if ':' in name:
        ns, name = name.split(':')
        name = '{%s}%s' % (ns_translation[ns], name)
    elem = RestrictedElement(nsmap=nsmap)
    if attrs:
        # Try hard to keep attribute order, to ensure deterministic output. This simplifies testing.
        for k, v in attrs.items():
            elem.set(k, v)
    elem.tag = name
    return elem
コード例 #6
0
    def description(item: RestrictedElement) -> [str, None]:
        desc_item = item.find('Description')

        summary = desc_item.find('Description_Summary')
        if summary is not None:
            return CWEFactory.remove_whitespaces(summary)
        return None
コード例 #7
0
ファイル: liasse_xml.py プロジェクト: betagouv/zam
def extract_from_node(node: RestrictedElement, *path: str) -> Optional[str]:
    element_path = "." + "/".join((NS + elem) for elem in path)
    elem: Optional[RestrictedElement] = node.find(element_path)
    if elem is None:
        return None
    text: str = elem.text
    return text
コード例 #8
0
 def extended_description(item: RestrictedElement) -> [str, None]:
     desc_item = item.find('Description')
     extended = desc_item.find('Extended_Description')
     if extended is not None:
         text = extended.find('Text')
         if text is not None:
             return CWEFactory.remove_whitespaces(text)
     return None
コード例 #9
0
 def references(item: RestrictedElement) -> str:
     references = item.find(
         '{http://cpe.mitre.org/dictionary/2.0}references')
     ref_list = []
     if references is not None:
         for ref in references:
             ref_list.append({
                 'name': ref.text,
                 'url': ref.attrib.get('href')
             })
     return json.dumps(ref_list)
コード例 #10
0
    def create(item: RestrictedElement) -> models.Cpe:
        name = item.find(
            '{http://scap.nist.gov/schema/cpe-extension/2.3}cpe23-item').get(
                'name')
        cpe = CpeFactory.get(name)

        for field in sorted(CpeFactory.FIELD_LIST):
            parser = getattr(CpeFactory, field, None)
            if parser:
                setattr(cpe, field, parser(item))

            cpe.save()
        return cpe
コード例 #11
0
    def create(item: RestrictedElement) -> models.Cwe:
        cwe_id = 'CWE-{}'.format(item.get('ID'))

        try:
            cwe = models.Cwe.objects.get(id=cwe_id)
        except models.Cwe.DoesNotExist:
            cwe = models.Cwe(id=cwe_id)

        for field in sorted(CWEFactory.FIELD_LIST):
            parser = getattr(CWEFactory, field, None)
            if parser:
                setattr(cwe, field, parser(item))
        if cwe.has_changed:
            cwe.save()
        return cwe
コード例 #12
0
    def create(item: RestrictedElement):
        cwe_id = 'CWE-{}'.format(item.get('ID'))
        old = CweDocument.search().filter(
            'term', id=cwe_id).sort('-modified_date')[0].execute()
        cwe = CweDocument(id=cwe_id)
        for field in CweDocument.get_fields_name():
            parser = getattr(CWEFactory, field, None)
            if parser:
                setattr(cwe, field, parser(item))

        if old.hits and cwe.has_changed(old.hits[0]):
            return old.hits[0].update(cwe, weak=True)
        elif not old.hits:
            return cwe.save(weak=True)
        return None
コード例 #13
0
 def vendor(item: RestrictedElement) -> str:
     return CpeFactory.get_field(item.get('name'), CpeFactory.VENDOR)
コード例 #14
0
ファイル: parsers.py プロジェクト: rajivraj/vmc
 def create(item: RestrictedElement, config) -> AssetDocument:
     ip_address = item.find(".//tag[@name='host-ip']").text
     return AssetDocument.get_or_create(ip_address, config)
コード例 #15
0
 def status(item: RestrictedElement) -> str:
     return item.get('Status')
コード例 #16
0
 def weakness_abstraction(item: RestrictedElement) -> str:
     return item.get('Weakness_Abstraction')
コード例 #17
0
 def name(item: RestrictedElement) -> str:
     return item.get('Name')
コード例 #18
0
 def title(item: RestrictedElement) -> str:
     return item.find('{http://cpe.mitre.org/dictionary/2.0}title').text