本文探讨如何使用Python的ElementTree库解析CVE(Common Vulnerabilities and Exposures)文档,通过XPath表达式提取关键信息,提升安全分析效率。
摘要由CSDN通过智能技术生成
2014-1-5 17:50
#-*- coding:utf-8 -*-
from xml.etree import ElementTree
import xml.etree.ElementTree as xml
tree = xml.parse('allitems-cvrf-year-1999.xml')
for elems in tree.iter("{http://www.icasi.org/CVRF/schema/vuln/1.1}Vulnerability"):
for firstchild in elems:
if(firstchild.tag == "{http://www.icasi.org/CVRF/schema/vuln/1.1}Title"):
print "Title:",firstchild.text
if(firstchild.tag == "{http://www.icasi.org/CVRF/schema/vuln/1.1}Notes"):
for i in firstchild:
print "Notes",i.text
if(firstchild.tag == "{http://www.icasi.org/CVRF/schema/vuln/1.1}CVE"):
print "CVE",firstchild.text
if(firstchild.tag == "{http://www.icasi.org/CVRF/schema/vuln/1.1}References"):
for Reference in firstchild: