Example #1
0
def qualys_parser(qualys_xml_file):
    parser = etree.XMLParser()
    tree = etree.parse(qualys_xml_file, parser)
    host_list = tree.find('HOST_LIST')
    finding_list = []
    if host_list is not None:
        for host in host_list:
            finding_list += parse_finding(host, tree)
    return finding_list
def qualys_parser(qualys_xml_file):
    parser = etree.XMLParser(resolve_entities=False,
                             remove_blank_text=True,
                             no_network=True,
                             recover=True)
    d = etree.parse(qualys_xml_file, parser)
    r = d.xpath('//ASSET_DATA_REPORT/HOST_LIST/HOST')
    master_list = []

    for issue in r:
        master_list += issue_r(issue, d)
    return master_list
Example #3
0
                    default=None,
                    help="output file.")
parser.add_argument("-d",
                    "--dtd",
                    type=str,
                    default=None,
                    help="The dtd file. All avaliable files will be listed")
args = parser.parse_args()


class UnescapeEntity():
    def __getitem__(self, key):
        return html.unescape(key)


parser = DET.XMLParser()
parser.parser.UseForeignDTD(True)
parser.entity = UnescapeEntity()


def read_dtd_line(dtd):
    line = ""
    mark = 0
    while True:
        c = dtd.read(1)
        if c == "":
            break
        elif c == "<":
            mark += 1
        elif c == ">":
            mark -= 1
Example #4
0
 def get_findings(self, xml_output, test):
     tree = etree.parse(xml_output, etree.XMLParser())
     return self.get_items(tree, test)
Example #5
0
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as badET
import defusedxml.ElementTree as goodET

xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"

# unsafe
tree = badET.fromstring(xmlString)
print(tree)
badET.parse("filethatdoesntexist.xml")
badET.iterparse("filethatdoesntexist.xml")
a = badET.XMLParser()

# safe
tree = goodET.fromstring(xmlString)
print(tree)
goodET.parse("filethatdoesntexist.xml")
goodET.iterparse("filethatdoesntexist.xml")
a = goodET.XMLParser()
Example #6
0
from ..semi_structured_xml_to_dict import DictBuilder
import defusedxml.ElementTree as DET
from io import BytesIO

a = b'<animals><i>John the <b>real</b> chicken</i><i>John the <b>real</b> chicken</i></animals>\n'
parser = DET.XMLParser(target=DictBuilder())
root = DET.fromstring(a, parser)
print(type(root))

b = BytesIO('''
<animals><i>John the <b>real</b> chicken</i></animals>
'''.encode('utf-8'))

parser = DET.XMLParser(target=DictBuilder())
tree = DET.parse(b, parser)
root = tree.getroot()
print(type(root))