iNoob
iNoob

Reputation: 1395

Python XML Parsing with ElementTree

Firstly I have checked out loads of posts regarding the issue I am having and have tried various methods of getting the value I require, even though I have identified the tag from the XML doc I cant seem to work out how to print the value held in <cve>VALUE</cve>. All the posts I have seen are related to items with attrib values and as my tag doesnt hold an attrib value Im not sure how to get the value I am after.

I am parsing a nessus file with Elementtree and python.

I can identify the tag that contains the value but I cant get the value out, very frustrating. There doesnt seem to be an attrib value (its blank) but as you can see by the XML example there is a value (but im assuming its not an attrib value). Any pointers would be appreciated.

Example XML

<SNIP>
<ReportItem port="445" svc_name="cifs" protocol="tcp" severity="0" pluginID="10398" pluginName="Microsoft Windows SMB LsaQueryInformationPolicy Function NULL Session Domain SID Enumeration" pluginFamily="Windows">
<bid>959</bid>
<cve>CVE-2000-1200</cve>
<description>By emulating the call to LsaQueryInformationPolicy() it was possible to obtain the domain SID (Security Identifier).
The domain SID can then be used to get the list of users of the domain</description>
<fname>smb_dom2sid.nasl</fname>
<osvdb>715</osvdb>
<plugin_modification_date>2015/01/12</plugin_modification_date>
<plugin_name>Microsoft Windows SMB LsaQueryInformationPolicy Function NULL Session Domain SID Enumeration</plugin_name>
<plugin_publication_date>2000/05/09</plugin_publication_date>
<plugin_type>local</plugin_type>
<risk_factor>None</risk_factor>
<script_version>$Revision: 1.51 $</script_version>
<solution>n/a</solution>
<synopsis>It is possible to obtain the domain SID.</synopsis>
<xref>OSVDB:715</xref>
<plugin_output>The remote domain SID value is :
FAKESTUFF HERE</plugin_output>
</ReportItem>
<SNIP>

Current Code

import elementtree.ElementTree as ET

def getCVE(nessus_file):
try:
    tree = ET.parse(nessus_file)
    doc = tree.getroot()
    walk = doc.getiterator('cve')
    for cve in walk:
        print cve
except:
    pass


getCVE('file.nessus')

Example Output From Code

<Element cve at 10fd05170>
<Element cve at 10fd20f38>
<Element cve at 10fd2c200>
<Element cve at 10fd3ea70>
<Element cve at 10fd44a70>
<Element cve at 10fd44b00>
<Element cve at 10fd5c170>
<Element cve at 10fd767e8>
<Element cve at 10fdbf290>
<Element cve at 10fdce440>
<Element cve at 10fdce4d0>
<SNIP>

Upvotes: 0

Views: 535

Answers (1)

iNoob
iNoob

Reputation: 1395

I Have worked it out ^_^. I simply need the text value lol YAY! took hours to work that out

so new working code is

import elementtree.ElementTree as ET

def getCVE(nessus_file):
try:
    tree = ET.parse(nessus_file)
    doc = tree.getroot()
    walk = doc.getiterator('cve')
    for cve in walk:
        print cve.text
except:
    pass

getCVE('file.nessus')

Upvotes: 1

Related Questions