Beispiel #1
0
 def __init__(self, xml, validate_xml=True):
     self.__xml = xml
     Script.__init__(self, xml, validate_xml)
     self.__kex_algorithms = []
     self.__server_host_key_algorithms = []
     self.__encryption_algorithms = []
     self.__mac_algorithms = []
     self.__compression_algorithms = []
     self.__other = {}
     self.__parse_xml()
Beispiel #2
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('port')
        if None != d.get('protocol', None):
            xml.attrib['protocol'] = d.get('protocol', None)
        if None != d.get('port', None):
            xml.attrib['portid'] = str(d.get('port', None))

        if None != d.get('state', None):
            xml.append(State.dict_to_xml(d['state'], validate_xml))

        if None != d.get('owner', None):
            owner_xml = etree.Element('owner')
            owner_xml.attrib['name'] = d.get('owner', None)
            xml.append(owner_xml)

        if None != d.get('service', None):
            xml.append(Service.dict_to_xml(d['service'], validate_xml))

        if None != d.get('scripts', None):
            for script_dict in d['scripts']:
                xml.append(Script.dict_to_xml(script_dict, validate_xml))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
Beispiel #3
0
    def equals(self, other):
        status = isinstance(other, ReverseIndex) \
                 and Script.equals(self, other) \
                 and len(self.__port_ip_map) == len(other.get_port_ip_map())

        if status:
            other_elements_other = other.get_port_ip_map()
            for other_key in self.__port_ip_map:
                if not compare_lists(self.__port_ip_map[other_key], other_elements_other.get(other_key, [])):
                    return False

        return status
Beispiel #4
0
    def equals(self, other):
        status = isinstance(other, SSH2EnumAlgos) \
                 and Script.equals(self, other) \
                 and compare_lists(self.__kex_algorithms, other.get_kex_algorithms()) \
                 and compare_lists(self.__server_host_key_algorithms, other.get_server_host_key_algorithms()) \
                 and compare_lists(self.__encryption_algorithms, other.get_encryption_algorithms()) \
                 and compare_lists(self.__mac_algorithms, other.get_mac_algorithms()) \
                 and compare_lists(self.__compression_algorithms, other.get_compression_algorithms()) \
                 and len(self.__other) == len(other.get_other())

        if status:
            other_elements_other = other.get_other()
            for other_key in self.__other:
                if not compare_lists(self.__other[other_key],
                                     other_elements_other.get(other_key, [])):
                    return False

        return status
Beispiel #5
0
 def equals(self, other):
     return isinstance(other, SSHHostkey) \
            and Script.equals(self, other) \
            and compare_lists_equal(self.__keys, other.get_keys())
Beispiel #6
0
 def __init__(self, xml, validate_xml=True):
     self.__xml = xml
     Script.__init__(self, xml, validate_xml)
     self.__keys = []
     self.__parse_xml()
Beispiel #7
0
 def __init__(self, xml, validate_xml=True):
     self.__xml = xml
     Script.__init__(self, xml, validate_xml)
     self.__port_ip_map = {}
     self.__parse_xml()
Beispiel #8
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('nmaprun')

        if None != d.get('scanner', None):
            xml.attrib['scanner'] = d.get('scanner', None)
        if None != d.get('version', None):
            xml.attrib['version'] = d.get('version', None)
        if None != d.get('xmloutputversion', None):
            xml.attrib['xmloutputversion'] = d.get('xmloutputversion', None)
        if None != d.get('profile_name', None):
            xml.attrib['profile_name'] = d.get('profile_name', None)
        if None != d.get('args', None):
            xml.attrib['args'] = d.get('args', None)
        if None != d.get('start', None):
            xml.attrib['start'] = str(d.get('start', None))
        if None != d.get('startstr', None):
            xml.attrib['startstr'] = d.get('startstr', None)

        if None != d.get('scaninfo', None):
            for status_dict in d['scaninfo']:
                xml.append(ScanInfo.dict_to_xml(status_dict, validate_xml))

        if None != d.get('verbose', None):
            verbose_xml = etree.Element('verbose')
            verbose_xml.attrib['level'] = str(d['verbose'])
            xml.append(verbose_xml)

        if None != d.get('debugging', None):
            debugging_xml = etree.Element('debugging')
            debugging_xml.attrib['level'] = str(d['debugging'])
            xml.append(debugging_xml)

        if None != d.get('targets', None):
            for e_dict in d['targets']:
                xml.append(Target.dict_to_xml(e_dict, validate_xml))
        if None != d.get('taskbegin', None):
            for e_dict in d['taskbegin']:
                xml.append(TaskBegin.dict_to_xml(e_dict, validate_xml))
        if None != d.get('taskprogress', None):
            for e_dict in d['taskprogress']:
                xml.append(TaskProgress.dict_to_xml(e_dict, validate_xml))
        if None != d.get('taskend', None):
            for e_dict in d['taskend']:
                xml.append(TaskEnd.dict_to_xml(e_dict, validate_xml))

        if None != d.get('hosthints', None):
            for e_dict in d['hosthints']:
                xml.append(HostHint.dict_to_xml(e_dict, validate_xml))

        if None != d.get('prescripts', None):
            for script_dict in d['prescripts']:
                script_xml = etree.Element('prescript')
                script_xml.append(Script.dict_to_xml(script_dict,
                                                     validate_xml))
                xml.append(script_xml)
        if None != d.get('postscripts', None):
            for script_dict in d['postscripts']:
                script_xml = etree.Element('postscript')
                script_xml.append(Script.dict_to_xml(script_dict,
                                                     validate_xml))
                xml.append(script_xml)

        if None != d.get('hosts', None):
            for e_dict in d['hosts']:
                xml.append(Host.dict_to_xml(e_dict, validate_xml))
        if None != d.get('outputs', None):
            for e_dict in d['outputs']:
                xml.append(Output.dict_to_xml(e_dict, validate_xml))

        if None != d.get('runstats', None):
            xml.append(RunStats.dict_to_xml(d['runstats'], validate_xml))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
Beispiel #9
0
    def dict_to_xml(d, validate_xml=True):
        xml = etree.Element('host')
        ports_xml = etree.Element('ports')
        if None != d.get('starttime', None):
            xml.attrib['starttime'] = str(d.get('starttime', None))
        if None != d.get('endtime', None):
            xml.attrib['endtime'] = str(d.get('endtime', None))
        if None != d.get('comment', None):
            xml.attrib['comment'] = d.get('comment', None)

        if None != d.get('status', None):
            xml.append(Status.dict_to_xml(d['status'], validate_xml))

        if None != d.get('addresses', None):
            for c in d['addresses']:
                xml.append(HostAddress.dict_to_xml(c, validate_xml))
        if None != d.get('os', None):
            for c in d['os']:
                xml.append(OS.dict_to_xml(c, validate_xml))
        if None != d.get('uptime', None):
            for c in d['uptime']:
                xml.append(Uptime.dict_to_xml(c, validate_xml))

        if None != d.get('traces', None):
            for c in d['traces']:
                xml.append(Trace.dict_to_xml(c, validate_xml))
        if None != d.get('tcpsequence', None):
            for c in d['tcpsequence']:
                xml.append(TCPSequence.dict_to_xml(c, validate_xml))
        if None != d.get('tcptssequence', None):
            for c in d['tcptssequence']:
                xml.append(TCPTSSequence.dict_to_xml(c, validate_xml))
        if None != d.get('ipidsequence', None):
            for c in d['ipidsequence']:
                xml.append(IPIDSequence.dict_to_xml(c, validate_xml))
        if None != d.get('distances', None):
            for distance_dict in d['distances']:
                distance_xml = etree.Element('distance')
                distance_xml.attrib['value'] = str(distance_dict)
                xml.append(distance_xml)

        if None != d.get('extraports', None):
            for c in d['extraports']:
                ports_xml.append(ExtraPort.dict_to_xml(c, validate_xml))
        if None != d.get('ports', None):
            for c in d['ports']:
                ports_xml.append(Port.dict_to_xml(c, validate_xml))
        xml.append(ports_xml)
        if None != d.get('hostnames', None):
            hostnames_xml = etree.Element('hostnames')
            for hostname_dict in d['hostnames']:
                hostnames_xml.append(
                    HostName.dict_to_xml(hostname_dict, validate_xml))
            xml.append(hostnames_xml)

        if None != d.get('hostscripts', None):
            for script_dict in d['hostscripts']:
                hostscript_xml = etree.Element('hostscript')
                hostscript_xml.append(
                    Script.dict_to_xml(script_dict, validate_xml))
                xml.append(hostscript_xml)

        if None != d.get('smurfs', None):
            for smurf in d['smurfs']:
                smurf_xml = etree.Element('smurf')
                smurf_xml.attrib['responses'] = smurf
                xml.append(smurf_xml)

        if None != d.get('times', None):
            for time_xml in d['times']:
                xml.append(Time.dict_to_xml(time_xml, validate_xml))

        if validate_xml:
            try:
                validate(xml)
            except NmapXMLParserException:
                raise NmapDictParserException()

        return xml
Beispiel #10
0
 def equals(self, other):
     return isinstance(other, UnknownScript) \
            and Script.equals(self, other)