私はNVD XMLを使用していて、XMLを解析して分割し、最終的にDBに入るようにしています。値の前後に「または」を付けてください。私はこれらの文字列を分割することはできません。私はコードとそれが現在失敗しているエントリを含めました。期待される出力は、PythonのXML属性の解析と文字分割
{'vendor': "america's_first_federal_credit_union", 'name': "america's_first_fcu_mobile_banking"}
に失敗
<entry type="CVE" name="CVE-2017-5916" seq="2017-5916" published="2017-05-05" modified="2017-05-16" severity="Medium" CVSS_version="2.0" CVSS_score="4.3" CVSS_base_score="4.3" CVSS_impact_subscore="2.9" CVSS_exploit_subscore="8.6" CVSS_vector="(AV:N/AC:M/Au:N/C:P/I:N/A:N)">
<desc>
<descript source="cve">The America's First Federal Credit Union (FCU) Mobile Banking app 3.1.0 for iOS does not verify X.509 certificates from SSL servers, which allows man-in-the-middle attackers to spoof servers and obtain sensitive information via a crafted certificate.</descript>
</desc>
<loss_types>
<conf/>
</loss_types>
<range>
<network/>
</range>
<refs>
<ref source="MISC" url="https://medium.com/@chronic_9612/follow-up-76-popular-apps-confirmed-vulnerable-to-silent-interception-of-tls-protected-data-64185035029f" adv="1">https://medium.com/@chronic_9612/follow-up-76-popular-apps-confirmed-vulnerable-to-silent-interception-of-tls-protected-data-64185035029f</ref>
</refs>
<vuln_soft>
<prod name="america's_first_fcu_mobile_banking" vendor="america's_first_federal_credit_union">
<vers num="3.1.0" prev="1" edition=":~~~iphone_os~~"/>
</prod>
</vuln_soft>
エントリの構文解析されているXMLエントリの
product,america's_first_federal_credit_union,america's_first_fcu_mobile_banking
コード
#!/usr/bin/env python
import os
import sys
import time
from subprocess import call
import xml.etree.ElementTree
import re
range_from = 2017
range_to = 2017
def process_entry(entry):
cve = entry.attrib.get("name")
print cve
cpes = get_cpes_affected(entry)
def get_cpes_affected(entry):
child = []
for e in entry.iter():
if "}prod" in e.tag:
print e.attrib
print unichr(34)
if unichr(34) in e.attrib:
print "hey yo"
child.append("product," + str(e.attrib).split('"')[1] + "," + str(e.attrib).split('"')[3])
else:
child.append("product," + str(e.attrib).split("'")[3] + "," + str(e.attrib).split("'")[7])
#print e.tag, e.attrib
if "'prev'" in e.attrib:
child.append("version," + str(e.attrib).split("'")[7] + "," + str(e.attrib).split("'")[3])
if "}vers" in e.tag and "'prev'" not in e.attrib:
child.append("version," + str(e.attrib).split("'")[3] + ",")
#print e.tag, e.attrib
for derp in child:
print derp
for i in range(range_from, range_to+1):
os.system("wget -O tmp.zip https://nvd.nist.gov/download/nvdcve-%i.xml.zip" % i)
os.system("unzip -o tmp.zip")
e = xml.etree.ElementTree.parse('nvdcve-%i.xml' % i).getroot()
for entry in e:
process_entry(entry)
例です
そして、ちょうど問題なく、それを分割することができます文字列の例を含むように
{'vendor': 'emirates_nbd_bank_p.j.s.c', 'name': 'emirates_nbd_ksa'}
申し訳ありませんが
Traceback (most recent call last):
File "prev-version-load.py", line 49, in <module>
process_entry(entry)
File "prev-version-load.py", line 18, in process_entry
cpes = get_cpes_affected(entry)
File "prev-version-load.py", line 33, in get_cpes_affected
child.append("product," + str(e.attrib).split("'")[3] + "," + str(e.attrib).split("'")[7])
IndexError: list index out of range
そして、あなたが取得しているエラーがある...?例えば、私はこれはあなたが本当にやろうとしているものだと思います –
lxmlを使用していますか? –
そして、あなたが得ようとしている出力は何ですか? 'str'を' dict'して解析しようとすると、あなたがしたいことはほとんどありません。 –