Exemplo n.º 1
0
def get_origin_recordcount():
        # TODO: Implement in a way, that only one XFR is required
        zone = dns.zone.from_xfr(dns.query.xfr(nameserver, 'berlin.warsaw.practicum.os3.nl'))
        names = zone.nodes.keys()
        names.sort()

        totalrecordsets = 0
        totalrecords = 0
        for rr in names:
                totalrecordsets += len(rr)
                raw = zone[rr].to_text(rr)
                lines = raw.split('\n')
                totalrecords += len(lines)

        totaldelegations = 0
        for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NS):
                if name != dns.name.empty:
                        totaldelegations += len(rdataset)
	totalds = 0
	for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.DS):
                if name != dns.name.empty:
                        totalds += len(rdataset)
	if totalds == totaldelegations:
		ds_present_match = 1		
	else:
		ds_present_match = 2

        return zone.origin, totalrecords, totalrecordsets, totaldelegations, ds_present_match
Exemplo n.º 2
0
 def _list_records_in_zone(self, zone, rdtype=None, name=None, content=None):
     """
     Iterates over all records of the zone and returns a list of records filtered
     by record type, name and content. The list is empty if no records found.
     """
     records = []
     rrsets = zone.iterate_rdatasets() if zone else []
     for rname, rdataset in rrsets:
         rtype = dns.rdatatype.to_text(rdataset.rdtype)
         if ((not rdtype or rdtype == rtype)
                 and (not name or name == rname.to_text())):
             for rdata in rdataset:
                 rdata = rdata.to_text()
                 if not content or self._convert_content(rtype, content) == rdata:
                     raw_rdata = self._clean_TXT_record({'type': rtype,
                                                         'content': rdata})['content']
                     data = {
                         'type': rtype,
                         'name': rname.to_text(True),
                         'ttl': int(rdataset.ttl),
                         'content': raw_rdata,
                         'id': Provider._create_identifier(rtype, rname.to_text(), raw_rdata)
                     }
                     records.append(data)
     return records
Exemplo n.º 3
0
def test_zone_iteration(zone):
    expected = {}
    for (name, rdataset) in zone.iterate_rdatasets():
        expected[(name, rdataset.rdtype, rdataset.covers)] = rdataset
    with zone.writer() as txn:
        actual = {}
        for (name, rdataset) in txn:
            actual[(name, rdataset.rdtype, rdataset.covers)] = rdataset
    assert actual == expected
Exemplo n.º 4
0
def make_xfr(zone):
    q = dns.message.make_query(zone.origin, 'AXFR')
    msg = dns.message.make_response(q)
    if zone.relativize:
        msg.origin = zone.origin
        soa_name = dns.name.empty
    else:
        soa_name = zone.origin
    soa = zone.find_rdataset(soa_name, 'SOA')
    add_rdataset(msg, soa_name, soa)
    for (name, rds) in zone.iterate_rdatasets():
        if rds.rdtype == dns.rdatatype.SOA:
            continue
        add_rdataset(msg, name, rds)
    add_rdataset(msg, soa_name, soa)
    return [msg]
Exemplo n.º 5
0
def by_rdataset(zone: dns.zone.Zone):
    rrs = {}
    for (name, rdataset) in zone.iterate_rdatasets():
        rdname = str(name)
        rdclass = dns.rdataclass.to_text(rdataset.rdclass)
        rdtype = dns.rdatatype.to_text(rdataset.rdtype)
        ttl = rdataset.ttl
        if not rdname in rrs:
            rrs[rdname] = {}
        if not rdclass in rrs[rdname]:
            rrs[rdname][rdclass] = {}
        if not rdtype in rrs[rdname][rdclass]:
            rrs[rdname][rdclass][rdtype] = { 'ttl': ttl, 'rrdatas': [] }
        for rdata in rdataset:
            rrs[rdname][rdclass][rdtype]['rrdatas'].append(str(rdata))
    return rrs
Exemplo n.º 6
0
def get_origin_dsmatch():
        # TODO: Implement in a way, that only one XFR is required
        zone = dns.zone.from_xfr(dns.query.xfr(nameserver, domain))
        names = zone.nodes.keys()
        names.sort()

        totalds = 0
        for (dsname, rdataset) in zone.iterate_rdatasets(dns.rdatatype.DS):
                if dsname != dns.name.empty:
                        totalds += len(rdataset)

        if int(totalds) == int(totaldelegations):
                ds_present_match = 1
        else:
                ds_present_match = 2

        return ds_present_match
Exemplo n.º 7
0
def get_origin_dsmatch():
        # TODO: Implement in a way, that only one XFR is required
        zone = dns.zone.from_xfr(dns.query.xfr(nameserver, domain))
        names = zone.nodes.keys()
        names.sort()

        totalds = 0
        for (dsname, rdataset) in zone.iterate_rdatasets(dns.rdatatype.DS):
                if dsname != dns.name.empty:
                        totalds += len(rdataset)

        if int(totalds) == int(totaldelegations):
                ds_present_match = 1
        else:
                ds_present_match = 2

        return ds_present_match
Exemplo n.º 8
0
def get_origin_recordcount():
	# TODO: Implement in a way, that only one XFR is required
	zone = dns.zone.from_xfr(dns.query.xfr(nameserver, domain))
    	names = zone.nodes.keys()
    	names.sort()

    	totalrecordsets = 0
    	totalrecords = 0
	for rr in names:
        	totalrecordsets += len(rr)
        	raw = zone[rr].to_text(rr)
		lines = raw.split('\n')
        	totalrecords += len(lines)
	
	totaldelegations = 0
    	for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NS):
        	if name != dns.name.empty:
                	totaldelegations += len(rdataset)
	
	return zone.origin, totalrecords, totalrecordsets, totaldelegations
Exemplo n.º 9
0
def get_origin_recordcount():
        # TODO: Implement in a way, that only one XFR is required
        zone = dns.zone.from_xfr(dns.query.xfr(nameserver, domain))
        names = zone.nodes.keys()
        names.sort()

        totalrecordsets = 0
        totalrecords = 0
        for rr in names:
                totalrecordsets += len(rr)
                raw = zone[rr].to_text(rr)
                lines = raw.split('\n')
                totalrecords += len(lines)

	global totaldelegations
        totaldelegations = 0
        for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NS):
                if name != dns.name.empty:
                        totaldelegations += len(rdataset)
	return zone.origin, totalrecords, totalrecordsets, totaldelegations
Exemplo n.º 10
0
    'TSIG',
    'IXFR',
    'AXFR',
    'MAILB',
    'MAILA',
    'ANY',
    'URI',
    'CAA',
    'TA',
    'DLV',
]

with open(r'\able.txt', 'r') as myfile:
    data = myfile.read()
# print (data)

zone = dns.zone.from_text(data, origin='able.', check_origin=False)
# print (zone)

for each in ids:
    try:
        print("#####################" + str(each) + "########################")
        for (name, rdataset) in zone.iterate_rdatasets(each):
            for rdata in rdataset:
                print(name)
                print(rdata.address)
                # print(rdata) #what else is in here?
        print("#####################" + str(each) + "########################")
    except:
        pass
Exemplo n.º 11
0
    def zone_transfer(self):
        """
        Function for testing for zone transfers for a given Domain, it will parse the
        output by record type.
        """
        # if anyone reports a record not parsed I will add it, the list is a long one
        # I tried to include those I thought where the most common.

        zone_records = []
        print '[*] Checking for Zone Transfer for', self._domain, \
            'name servers'
        ns_srvs = self.get_ns()
        
        for ns in ns_srvs:
            ns_srv = ''.join(ns[2])
            if self.check_tcp_dns(ns_srv):
                print '[*]',ns_srv,'Has port 53 TCP Open'
                print '[*] Trying NS server', ns_srv
                try:
                    zone = dns.zone.from_xfr(dns.query.xfr(ns_srv, self._domain))
                    print '[*] Zone Transfer was successful!!'
                    zone_records.append({'zone_transfer':'success', 'ns_server':ns_srv})
                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.SOA):
                        for rdata in rdataset:
                            print '[*]\t', 'SOA', rdata.mname.to_text()
                            zone_records.append({'zone_server':ns_srv, 'type':'SOA', \
                                                'mname':rdata.mname.to_text()
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.NS):
                        for rdata in rdataset:
                            print '[*]\t', 'NS', rdata.target.to_text()
                            zone_records.append({'zone_server':ns_srv, 'type':'NS', \
                                                'mname':rdata.target.to_text()
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.TXT):
                        for rdata in rdataset:
                            print '[*]\t', 'TXT', ''.join(rdata.strings)
                            zone_records.append({'zone_server':ns_srv, 'type':'TXT', \
                                                'strings':''.join(rdata.strings)
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.SPF):
                        for rdata in rdataset:
                            print '[*]\t', 'SPF', ''.join(rdata.strings)
                            zone_records.append({'zone_server':ns_srv, 'type':'SPF', \
                                                'strings':''.join(rdata.strings)
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.MX):
                        for rdata in rdataset:
                            print '[*]\t', 'MX', str(name) + '.' + self._domain, \
                                rdata.exchange.to_text()
                            zone_records.append({'zone_server':ns_srv, 'type':'MX', \
                                                'name':str(name) + '.' + self._domain, \
                                                'exchange':rdata.exchange.to_text()
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.AAAA):
                        for rdata in rdataset:
                            print '[*]\t', 'AAAA', str(name) + '.' + self._domain, \
                                rdata.address
                            zone_records.append({'zone_server':ns_srv, 'type':'AAAA', \
                                                'name':str(name) + '.' + self._domain, \
                                                'address':rdata.address
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.A):
                        for rdata in rdataset:
                            print '[*]\t', 'A', str(name) + '.' + self._domain, \
                                rdata.address
                            zone_records.append({'zone_server':ns_srv, 'type':'A', \
                                                'name':str(name) + '.' + self._domain, \
                                                'address':rdata.address
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.CNAME):
                        for rdata in rdataset:
                            print '[*]\t', 'CNAME', str(name) + '.'\
                                + self._domain, rdata.target.to_text()
                            zone_records.append({'zone_server':ns_srv, 'type':'CNAME', \
                                                'name':str(name) + '.' + self._domain, \
                                                'target':str(rdata.target.to_text())
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.SRV):
                        for rdata in rdataset:
                            print '[*]\t', 'SRV', str(name) + '.' + self._domain, rdata.target, \
                            str(rdata.port), str(rdata.weight)
                            zone_records.append({'zone_server':ns_srv, 'type':'SRV', \
                                                'name':str(name) + '.' + self._domain, \
                                                'target':rdata.target.to_text(), \
                                                'port':str(rdata.port), \
                                                'weight':str(rdata.weight)
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.HINFO):
                        for rdata in rdataset:
                            print '[*]\t', 'HINFO', rdata.cpu, rdata.os
                            zone_records.append({'zone_server':ns_srv, 'type':'HINFO', \
                                                'cpu':rdata.cpu, 'os':rdata.os
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.WKS):
                        for rdata in rdataset:
                            print '[*]\t', 'WKS', rdata.address, rdata.bitmap, rdata.protocol
                            zone_records.append({'zone_server':ns_srv, 'type':'WKS', \
                                                'address':rdata.address, 'bitmap':rdata.bitmap, \
                                                'protocol':rdata.protocol
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.RP):
                        for rdata in rdataset:
                            print '[*]\t', 'RP', rdata.mbox, rdata.txt
                            zone_records.append({'zone_server':ns_srv, 'type':'RP', \
                                                'mbox':rdata.mbox, 'txt':rdata.txt
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.AFSDB):
                        for rdata in rdataset:
                            print '[*]\t', 'AFSDB', rdata.subtype, rdata.hostname
                            zone_records.append({'zone_server':ns_srv, 'type':'AFSDB', \
                                                'subtype':rdata.subtype, 'hostname':rdata.hostname
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.X25):
                        for rdata in rdataset:
                            print '[*]', '\tX25', rdata.address
                            zone_records.append({'zone_server':ns_srv, 'type':'X25', \
                                                'address':rdata.address
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.ISDN):
                        for rdata in rdataset:
                            print '[*]\t', 'ISDN', rdata.address
                            zone_records.append({'zone_server':ns_srv, 'type':'ISDN', \
                                                'address':rdata.address
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.RT):
                        for rdata in rdataset:
                            print '[*]\t', 'RT', str(rdata.exchange), rdata.preference
                            zone_records.append({'zone_server':ns_srv, 'type':'X25', \
                                                'address':rdata.address
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.NSAP):
                        for rdata in rdataset:
                            print '[*]\t', 'NSAP', rdata.address
                            zone_records.append({'zone_server':ns_srv, 'type':'NSAP', \
                                                'address':rdata.address
                                                })


                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.SIG):
                        for rdata in rdataset:
                            print '[*]\t', 'SIG', algorithm_to_text(rdata.algorithm), rdata.expiration, \
                            rdata.inception, rdata.key_tag, rdata.labels, rdata.original_ttl, \
                            rdata.signature, str(rdata.signer), rdata.type_covered
                            zone_records.append({'zone_server':ns_srv, 'type':'SIG', \
                                                'algorithm':algorithm_to_text(rdata.algorithm), \
                                                'expiration':rdata.expiration, \
                                                'inception':rdata.inception, \
                                                'key_tag':rdata.key_tag, \
                                                'labels':rdata.labels, \
                                                'original_ttl':rdata.original_ttl, \
                                                'signature':rdata.signature, \
                                                'signer':str(rdata.signer), \
                                                'type_covered':rdata.type_covered
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.RRSIG):
                        for rdata in rdataset:
                            print '[*]\t', 'RRSIG', algorithm_to_text(rdata.algorithm), rdata.expiration, \
                            rdata.inception, rdata.key_tag, rdata.labels, rdata.original_ttl, \
                            rdata.signature, str(rdata.signer), rdata.type_covered
                            zone_records.append({'zone_server':ns_srv, 'type':'RRSIG', \
                                                'algorithm':algorithm_to_text(rdata.algorithm), \
                                                'expiration':rdata.expiration, \
                                                'inception':rdata.inception, \
                                                'key_tag':rdata.key_tag, \
                                                'labels':rdata.labels, \
                                                'original_ttl':rdata.original_ttl, \
                                                'signature':rdata.signature, \
                                                'signer':str(rdata.signer), \
                                                'type_covered':rdata.type_covered
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.DNSKEY):
                        for rdata in rdataset:
                            print '[*]\t', 'DNSKEY', algorithm_to_text(rdata.algorithm), rdata.flags, rdata.key, \
                            rdata.protocol
                            zone_records.append({'zone_server':ns_srv, 'type':'DNSKEY', \
                                                'algorithm':algorithm_to_text(rdata.algorithm), \
                                                'flags':rdata.flags, \
                                                'key':rdata.key, \
                                                'protocol':rdata.protocol
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.DS):
                        for rdata in rdataset:
                            print '[*]\t', 'DS', algorithm_to_text(rdata.algorithm), rdata.digest, \
                            rdata.digest_type, rdata.key_tag
                            zone_records.append({'zone_server':ns_srv, 'type':'DS', \
                                                'algorithm':algorithm_to_text(rdata.algorithm), \
                                                'digest':rdata.digest, \
                                                'digest_type':rdata.digest_type, \
                                                'key_tag':rdata.key_tag
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.NSEC):
                        for rdata in rdataset:
                            print '[*]\t', 'NSEC', algorithm_to_text(rdata.algorithm), rdata.flags, \
                            rdata.iterations, rdata.salt
                            zone_records.append({'zone_server':ns_srv, 'type':'NSEC', \
                                                'algorithm':algorithm_to_text(rdata.algorithm), \
                                                'flags':rdata.flags, \
                                                'iterations':rdata.iterations, \
                                                'salt':rdata.salt
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.NSEC3):
                        for rdata in rdataset:
                            print '[*]\t', 'NSEC3', algorithm_to_text(rdata.algorithm), rdata.flags, \
                            rdata.iterations, rdata.salt
                            zone_records.append({'zone_server':ns_srv, 'type':'NSEC', \
                                                'algorithm':algorithm_to_text(rdata.algorithm), \
                                                'flags':rdata.flags, \
                                                'iterations':rdata.iterations, \
                                                'salt':rdata.salt
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.NSEC3PARAM):
                        for rdata in rdataset:
                            print '[*]\t', 'NSEC3PARAM', algorithm_to_text(rdata.algorithm), rdata.flags, \
                            rdata.iterations, rdata.salt
                            zone_records.append({'zone_server':ns_srv, 'type':'NSEC3PARAM', \
                                                'algorithm':algorithm_to_text(rdata.algorithm), \
                                                'flags':rdata.flags, \
                                                'iterations':rdata.iterations, \
                                                'salt':rdata.salt
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.IPSECKEY):
                        for rdata in rdataset:
                            print '[*]\t', 'IPSECKEY', algorithm_to_text(rdata.algorithm), rdata.gateway, \
                            rdata.gateway_type, rdata.key, rdata.precedence
                            zone_records.append({'zone_server':ns_srv, 'type':'IPSECKEY', \
                                                'algorithm':algorithm_to_text(rdata.algorithm), \
                                                'gateway':rdata.gateway, \
                                                'gateway_type':rdata.gateway_type, \
                                                'key':rdata.key, \
                                                'precedence':rdata.precedence
                                                })

                except:
                    print '[-] Zone Transfer Failed!'
                zone_records.append({'zone_transfer':'failed', 'ns_server':ns_srv})
        return zone_records