コード例 #1
0
ファイル: dnssec.py プロジェクト: rurbin3/yawast
def get_dnskey(domain):
    records = []

    try:
        answers = resolver.query(domain, "DNSKEY")

        for data in answers:
            flags = format(data.flags, "016b")
            proto = data.protocol
            alg = dnssec.algorithm_to_text(data.algorithm)
            key = data.key

            records.append([flags, proto, alg, key])
    except (resolver.NoAnswer, resolver.NXDOMAIN, exception.Timeout):
        pass
    except (resolver.NoNameservers, resolver.NotAbsolute, resolver.NoRootSOA):
        output.debug_exception()

    return records
コード例 #2
0
ファイル: subBrute.py プロジェクト: rwboy/sub
    def dns_sec_check(self):
        """
        Check if a zone is configured for DNSSEC and if so if NSEC or NSEC3 is used.
        """
        try:
            answer = self.res._res.query(self.domain, 'DNSKEY')
            self.print_info("DNSSEC is configured for {0}".format(self.domain))
            nsectype = self.get_nsec_type()
            self.print_info("DNSKEYs:")
            for rdata in answer:
                if rdata.flags == 256:
                    key_type = "ZSK"

                if rdata.flags == 257:
                    key_type = "KSk"

                self.print_info("\t{0} {1} {2} {3}".format(
                    nsectype, key_type, algorithm_to_text(rdata.algorithm),
                    dns.rdata._hexify(rdata.key)))

        except dns.resolver.NXDOMAIN:
            self.print_error("Could not resolve domain: {0}".format(
                self.domain))
        # sys.exit(1)

        except dns.exception.Timeout:
            self.print_error(
                "A timeout error occurred please make sure you can reach the target DNS Servers"
            )
            self.print_error(
                "directly and requests are not being filtered. Increase the timeout from {0} second"
                .format(self.res._res.timeout))
            self.print_error(
                "to a higher number with --lifetime <time> option.")
            #sys.exit(1)
        except dns.resolver.NoAnswer:
            self.print_error("DNSSEC is not configured for {0}".format(
                self.domain))
コード例 #3
0
ファイル: dnshelper.py プロジェクト: nangai/dnsrecon
    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 = []
        ns_records = []
        print_status('Checking for Zone Transfer for {0} name servers'.format(
            self._domain))

        # Find SOA for Domain
        print_status("Resolving SOA Record")
        try:
            soa_srvs = self.get_soa()
            for s in soa_srvs:
                print_good("\t {0}".format(" ".join(s)))
                ns_records.append(s[2])
        except:
            print_error("Could not obtain the domains SOA Record.")
            return

        # Find NS for Domain
        print_status("Resolving NS Records")
        ns_srvs = []
        try:
            ns_srvs = self.get_ns()
            print_status("NS Servers found:")
            for ns in ns_srvs:
                print_status("\t{0}".format(" ".join(ns)))
                ns_ip = ''.join(ns[2])
                ns_records.append(ns_ip)
        except Exception as s:
            print_error("Could not Resolve NS Records")

        # Remove duplicates
        print_status("Removing any duplicate NS server IP Addresses...")
        ns_records = list(set(ns_records))
        # Test each NS Server
        for ns_srv in ns_records:
            print_status('Trying NS server {0}'.format(ns_srv))
            if self.check_tcp_dns(ns_srv):

                print_good('{0} Has port 53 TCP Open'.format(ns_srv))
                try:
                    zone = self.from_wire(dns.query.xfr(ns_srv, self._domain))
                    print_good('Zone Transfer was successful!!')
                    zone_records.append({
                        'type': 'info',
                        'zone_transfer': 'success',
                        'ns_server': ns_srv
                    })
                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.SOA):
                        for rdata in rdataset:
                            for mn_ip in self.get_ip(rdata.mname.to_text()):
                                if re.search(r'^A', mn_ip[0]):
                                    print_status('\t SOA {0} {1}'.format(
                                        rdata.mname.to_text()[:-1], mn_ip[2]))
                                    zone_records.append({'zone_server': ns_srv, 'type': 'SOA', \
                                                'mname': rdata.mname.to_text()[:-1], 'address': mn_ip[2]
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.NS):
                        for rdata in rdataset:
                            for n_ip in self.get_ip(rdata.target.to_text()):
                                if re.search(r'^A', n_ip[0]):
                                    print_status('\t NS {0} {1}'.format(
                                        rdata.target.to_text()[:-1], n_ip[2]))
                                    zone_records.append({'zone_server': ns_srv, 'type': 'NS', \
                                                'target': rdata.target.to_text()[:-1], 'address': n_ip[2]
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.TXT):
                        for rdata in rdataset:
                            print_status('\t TXT {0}'.format(''.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_status('\t SPF {0}'.format(''.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.PTR):
                        for rdata in rdataset:
                            for n_ip in self.get_ip(rdata.target.to_text() +
                                                    "." + self._domain):
                                if re.search(r'^A', n_ip[0]):
                                    print_status('\t PTR {0} {1}'.format(
                                        rdata.target.to_text() + "." +
                                        self._domain, n_ip[2]))
                                    zone_records.append({'zone_server': ns_srv, 'type': 'PTR', \
                                                'name': rdata.target.to_text() + "." + self._domain, 'address': n_ip[2]
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.MX):
                        for rdata in rdataset:
                            for e_ip in self.get_ip(rdata.exchange.to_text()):
                                if re.search(r'^A', e_ip[0]):
                                    print_status('\t MX {0} {1} {2}'.format(str(name) + '.' + self._domain, \
                                rdata.exchange.to_text()[:-1], e_ip[2]))
                                zone_records.append({'zone_server': ns_srv, 'type': 'MX', \
                                                'name': str(name) + '.' + self._domain,\
                                                'exchange': rdata.exchange.to_text()[:-1],\
                                                'address': e_ip[2]
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.AAAA):
                        for rdata in rdataset:
                            print_status('\t AAAA {0} {1}'.format(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_status('\t A {0} {1}'.format(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:
                            for t_ip in self.get_ip(rdata.target.to_text()):
                                if re.search(r'^A', t_ip[0]):
                                    print_status('\t CNAME {0} {1} {2}'.format(str(name) + '.'\
                                    + self._domain, rdata.target.to_text(), t_ip[2]))
                                    zone_records.append({'zone_server': ns_srv, 'type': 'CNAME', \
                                                'name': str(name) + '.' + self._domain, \
                                                'target': str(rdata.target.to_text())[:-1],
                                                'address': t_ip[2]
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.SRV):
                        for rdata in rdataset:
                            ip_list = self.get_ip(rdata.target.to_text())
                            if ip_list:
                                for t_ip in self.get_ip(
                                        rdata.target.to_text()):
                                    if re.search(r'^A', t_ip[0]):
                                        print_status('\t SRV {0} {1} {2} {3} {4}'.format(str(name) + '.' + self._domain, rdata.target, \
                                        str(rdata.port), str(rdata.weight), t_ip[2]))
                                        zone_records.append({'zone_server': ns_srv, 'type': 'SRV', \
                                                    'name': str(name) + '.' + self._domain, \
                                                    'target': rdata.target.to_text()[:-1], \
                                                    'address': t_ip[2], \
                                                    'port': str(rdata.port), \
                                                    'weight': str(rdata.weight)
                                                    })
                            else:
                                print_status('\t SRV {0} {1} {2} {3} {4}'.format(str(name) + '.' + self._domain, rdata.target, \
                                        str(rdata.port), str(rdata.weight), 'no_ip'))
                                zone_records.append({'zone_server': ns_srv, 'type': 'SRV', \
                                        'name': str(name) + '.' + self._domain, \
                                        'target': rdata.target.to_text()[:-1], \
                                        'address': "no_ip", \
                                        'port': str(rdata.port), \
                                        'weight': str(rdata.weight)
                                       })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.HINFO):
                        for rdata in rdataset:
                            print_status('\t HINFO {0} {1}'.format(
                                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_status('\t WKS {0} {1} {2}'.format(
                                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_status('\t RP {0} {1}'.format(
                                rdata.mbox, rdata.txt))
                            zone_records.append({'zone_server': ns_srv, 'type': 'RP', \
                                                'mbox': rdata.mbox.to_text(), 'txt': rdata.txt.to_text()
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.AFSDB):
                        for rdata in rdataset:
                            print_status('\t AFSDB {0} {1}'.format(
                                str(rdata.subtype), rdata.hostname))
                            zone_records.append({'zone_server': ns_srv, 'type': 'AFSDB', \
                                                'subtype': str(rdata.subtype), 'hostname': rdata.hostname.to_text()
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.LOC):
                        for rdata in rdataset:
                            print_status('\t LOC {0}'.format(rdata.to_text()))
                            zone_records.append({'zone_server': ns_srv, 'type': 'LOC', \
                                                'coordinates': rdata.to_text()
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.X25):
                        for rdata in rdataset:
                            print_status('\tX25 {0}'.format(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_status('\t ISDN {0}'.format(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_status('\t RT {0} {1}'.format(
                                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_status('\t NSAP {0}'.format(rdata.address))
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSAP', \
                                                'address': rdata.address
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.NAPTR):
                        for rdata in rdataset:
                            print_status('\t NAPTR {0} {1} {2} {3} {4} {5}'.format(rdata.flags,\
                                                               rdata.order,\
                                                               rdata.preference,\
                                                               rdata.regexp,\
                                                               rdata.replacement,\
                                                               rdata.service))
                            zone_records.append({'zone_server': ns_srv, 'type': 'NAPTR', \
                                                'order': str(rdata.order),\
                                                'preference': str(rdata.preference),\
                                                'regex': rdata.regexp,\
                                                'replacement': rdata.replacement.to_text(),\
                                                'service': rdata.service
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.CERT):
                        for rdata in rdataset:
                            print_status('\t CERT {0}'.format(rdata.to_text()))
                            zone_records.append({'zone_server': ns_srv, 'type': 'CERT', \
                                                'algorithm': rdata.algorithm,\
                                                'certificate': rdata.certificate,\
                                                'certificate_type': rdata.certificate_type,\
                                                'key_tag': rdata.key_tag
                                                })

                    for (name, rdataset) in \
                        zone.iterate_rdatasets(dns.rdatatype.SIG):
                        for rdata in rdataset:
                            print_status('\t SIG {0} {1} {2} {3} {4} {5} {6} {7} {8}'.format(\
                            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_status('\t RRSIG {0} {1} {2} {3} {4} {5} {6} {7} {8}'.format(\
                            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_status('\t DNSKEY {0} {1} {2} {3}'.format(\
                            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_status('\t DS {0} {1} {2} {3}'.format(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_status('\t NSEC {0} {1} {2} {3}'.format(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_status('\t NSEC3 {0} {1} {2} {3}'.format(algorithm_to_text(rdata.algorithm), rdata.flags, \
                            rdata.iterations, rdata.salt))
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSEC3', \
                                                '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_status('\t NSEC3PARAM {0} {1} {2} {3}'.format(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_status('\t PSECKEY {0} {1} {2} {3} {4}'.format(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 Exception as e:
                    print_error('Zone Transfer Failed!')
                    print_error(e)
                    zone_records.append({
                        'type': 'info',
                        'zone_transfer': 'failed',
                        'ns_server': ns_srv
                    })
            else:
                print_error('Zone Transfer Failed for {0}!'.format(ns_srv))
                print_error('Port 53 TCP is being filtered')
                zone_records.append({
                    'type': 'info',
                    'zone_transfer': 'failed',
                    'ns_server': ns_srv
                })
        return zone_records
コード例 #4
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 = []
        ns_records = []
        print_status(
            f'Checking for Zone Transfer for {self._domain} name servers')

        # Find SOA for Domain
        print_status("Resolving SOA Record")
        try:
            soa_srvs = self.get_soa()
            for type_, name_, addr_ in soa_srvs:
                print_good(f"\t {type_} {name_} {addr_}")
                ns_records.append(addr_)
        except Exception:
            print_error("Could not obtain the domains SOA Record.")
            return

        # Find NS for Domain
        print_status("Resolving NS Records")
        try:
            ns_srvs = []
            ns_srvs = self.get_ns()
            print_status("NS Servers found:")
            for type_, name_, addr_ in ns_srvs:
                print_good(f"\t {type_} {name_} {addr_}")
                ns_records.append(addr_)
        except Exception as e:
            print_error(f"Could not Resolve NS Records: {e}")

        # Remove duplicates
        print_status("Removing any duplicate NS server IP Addresses...")
        ns_records = list(set(ns_records))

        # Test each NS Server
        for ns_srv in ns_records:
            print_status(" ")
            print_status(f'Trying NS server {ns_srv}')

            if not self.check_tcp_dns(ns_srv):
                print_error(f"Zone Transfer Failed for {ns_srv}!")
                print_error('Port 53 TCP is being filtered')
                zone_records.append({
                    'type': 'info',
                    'zone_transfer': 'failed',
                    'ns_server': ns_srv
                })
                continue

            print_good(f"{ns_srv} Has port 53 TCP Open")
            try:
                zone = self.from_wire(dns.query.xfr(ns_srv, self._domain))
                print_good('Zone Transfer was successful!!')
                zone_records.append({
                    'type': 'info',
                    'zone_transfer': 'success',
                    'ns_server': ns_srv
                })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.SOA):
                    for rdata in rdataset:
                        mname = strip_last_dot(rdata.mname.to_text())

                        for type_, name_, addr_ in self.get_ip(mname):
                            if type_ in ['A', 'AAAA']:
                                print_status(f"\t SOA {mname} {addr_}")
                                zone_records.append({
                                    'zone_server': ns_srv,
                                    'type': 'SOA',
                                    'mname': mname,
                                    'address': addr_
                                })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.NS):
                    for rdata in rdataset:
                        # Check if target is only the host name or a full FQDN.
                        # If only a hostname we will append the domain name of the
                        # Zone being transfered.
                        target = rdata.target.to_text()
                        if target.count('.') == 0:
                            target = target + '.' + self._domain
                        else:
                            target = strip_last_dot(target)

                        for type_, name_, addr_ in self.get_ip(target):
                            if type_ in ['A', 'AAAA']:
                                print_status(f"\t NS {target} {addr_}")
                                zone_records.append({
                                    'zone_server': ns_srv,
                                    'type': 'NS',
                                    'target': target,
                                    'address': addr_
                                })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.TXT):
                    for rdata in rdataset:
                        s = "; ".join(
                            [string.decode() for string in rdata.strings])
                        print_status(f"\t TXT {s}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'TXT',
                            'strings': s
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.SPF):
                    for rdata in rdataset:
                        s = "; ".join(
                            [string.decode() for string in rdata.strings])
                        print_status(f"\t SPF {s}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'SPF',
                            'strings': s
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.PTR):
                    for rdata in rdataset:
                        target = rdata.target.to_text() + "." + self._domain
                        for type_, name_, addr_ in self.get_ip(target):
                            if type_ in ['A', 'AAAA']:
                                print_status(f"\t PTR {target} {addr_}")
                                zone_records.append({
                                    'zone_server': ns_srv,
                                    'type': 'PTR',
                                    'name': target,
                                    'address': addr_
                                })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.MX):
                    for rdata in rdataset:
                        exchange = strip_last_dot(rdata.exchange.to_text())

                        for type_, name_, addr_ in self.get_ip(exchange):
                            fqdn_ = str(name) + '.' + self._domain
                            if type_ in ['A', 'AAAA']:
                                print_status(
                                    f"\t MX {fqdn_} {exchange} {addr_}")
                                zone_records.append({
                                    'zone_server': ns_srv,
                                    'type': 'MX',
                                    'name': fqdn_,
                                    'exchange': exchange,
                                    'address': addr_
                                })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.AAAA):
                    fqdn_ = str(name) + '.' + self._domain
                    for rdata in rdataset:
                        print_status(f"\t AAAA {fqdn_} {rdata.address}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'AAAA',
                            'name': fqdn_,
                            'address': rdata.address
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.A):
                    fqdn_ = str(name) + '.' + self._domain
                    for rdata in rdataset:
                        print_status(f"\t A {fqdn_} {rdata.address}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'A',
                            'name': fqdn_,
                            'address': rdata.address
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.CNAME):
                    fqdn_ = str(name) + '.' + self._domain
                    for rdata in rdataset:
                        target = strip_last_dot(rdata.target.to_text())

                        for type_, name_, addr in self.get_ip(target):
                            if type_ in ['A', 'AAAA']:
                                print_status(
                                    f"\t CNAME {fqdn_} {target} {addr_}")
                                zone_records.append({
                                    'zone_server': ns_srv,
                                    'type': 'CNAME',
                                    'name': fqdn_,
                                    'target': target,
                                    'address': addr_
                                })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.SRV):
                    fqdn_ = str(name) + '.' + self._domain

                    for rdata in rdataset:
                        target = strip_last_dot(rdata.target.to_text())
                        weight_ = str(rdata.weight)
                        port_ = str(rdata.port)

                        ip_list = self.get_ip(rdata.target.to_text())
                        if not ip_list:
                            print_status(
                                f"\t SRV {fqdn_} {target} {port_} {weight_} no_ip"
                            )
                            zone_records.append({
                                'zone_server': ns_srv,
                                'type': 'SRV',
                                'name': fqdn_,
                                'target': target,
                                'address': "no_ip",
                                'port': port_,
                                'weight': weight_
                            })
                            continue

                        for type_, name, addr_ in ip_list:
                            if type_ in ['A', 'AAAA']:
                                print_status(
                                    f"\t SRV {fqdn_} {target} {port_} {weight_} {addr_}"
                                )
                                zone_records.append({
                                    'zone_server': ns_srv,
                                    'type': 'SRV',
                                    'name': fqdn_,
                                    'target': target,
                                    'address': addr_,
                                    'port': port_,
                                    'weight': weight_
                                })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.HINFO):
                    for rdata in rdataset:
                        cpu_ = rdata.cpu.decode()
                        os_ = rdata.os.decode()
                        print_status(f"\t HINFO {cpu_} {os_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'HINFO',
                            'cpu': cpu_,
                            'os': os_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.WKS):
                    for rdata in rdataset:
                        addr_ = rdata.address
                        bitmap_ = rdata.bitmap
                        proto_ = rdata.protocol
                        print_status(f"\t WKS {addr_} {bitmap_} {proto_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'WKS',
                            'address': addr_,
                            'bitmap': bitmap_,
                            'protocol': proto_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.RP):
                    for rdata in rdataset:
                        mbox_ = rdata.mbox.to_text()
                        txt_ = rdata.txt.to_text()
                        print_status(f"\t RP {mbox_} {txt_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'RP',
                            'mbox': mbox_,
                            'txt': txt_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.AFSDB):
                    for rdata in rdataset:
                        subtype_ = str(rdata.subtype)
                        hostname_ = rdata.hostname.to_text()
                        print_status(f"\t AFSDB {subtype_} {hostname_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'AFSDB',
                            'subtype': subtype_,
                            'hostname': hostname_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.LOC):
                    for rdata in rdataset:
                        coordinates_ = rdata.to_text()
                        print_status(f"\t LOC {coordinates_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'LOC',
                            'coordinates': coordinates_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.X25):
                    for rdata in rdataset:
                        addr_ = rdata.address
                        print_status(f"\t X25 {addr_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'X25',
                            'address': addr_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.ISDN):
                    for rdata in rdataset:
                        addr_ = rdata.address
                        print_status(f"\t ISDN {addr_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'ISDN',
                            'address': addr_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.RT):
                    for rdata in rdataset:
                        addr_ = rdata.address
                        exchange = strip_last_dot(rdata.exchange.to_text())
                        pref_ = str(rdata.preference)

                        print_status(f"\t RT {exchange} {pref_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'X25',
                            'address': addr_,
                            'preference': pref_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSAP):
                    for rdata in rdataset:
                        addr_ = rdata.address
                        print_status(f"\t NSAP {addr_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'NSAP',
                            'address': addr_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.NAPTR):
                    for rdata in rdataset:
                        flags_ = rdata.flags.decode()
                        order_ = str(rdata.order)
                        pref_ = str(rdata.preference)
                        regexp_ = rdata.regexp.decode()
                        replacement_ = rdata.replacement.to_text()
                        service_ = rdata.service.decode()

                        print_status(
                            f"\t NAPTR {flags_} {order_} {pref_} {regexp_} {replacement_} {service_}"
                        )
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'NAPTR',
                            'order': order_,
                            'preference': pref_,
                            'regex': regexp_,
                            'replacement': replacement_,
                            'service': service_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.CERT):
                    for rdata in rdataset:
                        algo_ = algorithm_to_text(rdata.algorithm)
                        cert_ = rdata.certificate
                        cert_type_ = rdata.certificate_type
                        key_tag_ = rdata.key_tag

                        print_status("\t CERT {0}".format(rdata.to_text()))
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'CERT',
                            'algorithm': algo_,
                            'certificate': cert_,
                            'certificate_type': cert_type_,
                            'key_tag': key_tag_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.SIG):
                    for rdata in rdataset:
                        algo_ = 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

                        print_status(
                            f"\t SIG {algo_} {expiration_} {inception_} {key_tag_} {labels_} {original_ttl_} {signature_} {signer_} {type_covered_}"
                        )
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'SIG',
                            'algorithm': algo_,
                            'expiration': expiration_,
                            'inception': inception_,
                            'key_tag': key_tag_,
                            'labels': labels_,
                            'original_ttl': original_ttl_,
                            'signature': signature_,
                            'signer': signer_,
                            'type_covered': type_covered_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.RRSIG):
                    for rdata in rdataset:
                        algo_ = 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

                        print_status(
                            f"\t RRSIG {algo_} {expiration_} {inception_} {key_tag_} {labels_} {original_ttl_} {signature_} {signer_} {type_covered_}"
                        )
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'RRSIG',
                            'algorithm': algo_,
                            'expiration': expiration_,
                            'inception': inception_,
                            'key_tag': key_tag_,
                            'labels': labels_,
                            'original_ttl': original_ttl_,
                            'signature': signature_,
                            'signer': signer_,
                            'type_covered': type_covered_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.DNSKEY):
                    for rdata in rdataset:
                        algo_ = algorithm_to_text(rdata.algorithm)
                        flags_ = rdata.flags
                        key_ = dns.rdata._hexify(rdata.key)
                        proto_ = rdata.protocol

                        print_status(
                            f"\t DNSKEY {algo_} {flags_} {key_} {proto_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'DNSKEY',
                            'algorithm': algo_,
                            'flags': flags_,
                            'key': key_,
                            'protocol': proto_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.DS):
                    for rdata in rdataset:
                        algo_ = algorithm_to_text(rdata.algorithm)
                        digest_ = dns.rdata._hexify(rdata.digest)
                        digest_type_ = rdata.digest_type
                        key_tag_ = rdata.key_tag

                        print_status(
                            f"\t DS {algo_} {digest_} {digest_type_} {key_tag_}"
                        )
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'DS',
                            'algorithm': algo_,
                            'digest': digest_,
                            'digest_type': digest_type_,
                            'key_tag': key_tag_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC):
                    for rdata in rdataset:
                        next_ = rdata.next.to_text()
                        print_status(f"\t NSEC {next_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'NSEC',
                            'next': next_
                        })

                for (name,
                     rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC3):
                    for rdata in rdataset:
                        algo_ = algorithm_to_text(rdata.algorithm)
                        flags_ = rdata.flags
                        iterations_ = rdata.iterations
                        salt_ = dns.rdata._hexify(rdata.salt)

                        print_status(
                            f"\t NSEC3 {algo_} {flags_} {iterations_} {salt_}")
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'NSEC3',
                            'algorithm': algo_,
                            'flags': flags_,
                            'iterations': iterations_,
                            'salt': salt_
                        })

                for (name, rdataset) in zone.iterate_rdatasets(
                        dns.rdatatype.NSEC3PARAM):
                    for rdata in rdataset:
                        algo_ = algorithm_to_text(rdata.algorithm)
                        flags_ = rdata.flags
                        iterations_ = rdata.iterations
                        salt_ = dns.rdata._hexify(rdata.salt)

                        print_status(
                            f"\t NSEC3PARAM {algo_} {flags_} {iterations_} {salt_}"
                        )
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'NSEC3PARAM',
                            'algorithm': algo_,
                            'flags': flags_,
                            'iterations': iterations_,
                            'salt': salt_
                        })

                for (name, rdataset) in zone.iterate_rdatasets(
                        dns.rdatatype.IPSECKEY):
                    for rdata in rdataset:
                        algo_ = algorithm_to_text(rdata.algorithm)
                        key_ = dns.rdata._hexify(rdata.key)
                        gw_ = rdata.gateway
                        gw_type_ = rdata.gateway_type
                        prec_ = rdata.precedence

                        print_status(
                            f"\t IPSECKEY {algo_} {gw_} {gw_type_} {key_} {prec_}"
                        )
                        zone_records.append({
                            'zone_server': ns_srv,
                            'type': 'IPSECKEY',
                            'algorithm': algo_,
                            'gateway': gw_,
                            'gateway_type': gw_type_,
                            'key': key_,
                            'precedence': prec_
                        })
            except Exception as e:
                print_error(f"Zone Transfer Failed ({e})")
                zone_records.append({
                    'type': 'info',
                    'zone_transfer': 'failed',
                    'ns_server': ns_srv
                })

        return zone_records
コード例 #5
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 = []
        ns_records = []
        print_status('Checking for Zone Transfer for {0} name servers'.format(self._domain))

        # Find SOA for Domain
        print_status("Resolving SOA Record")
        try:
            soa_srvs = self.get_soa()
            for s in soa_srvs:
                print_good("\t {0}".format(" ".join(s)))
                ns_records.append(s[2])
        except:
            print_error("Could not obtain the domains SOA Record.")
            return

        # Find NS for Domain
        print_status("Resolving NS Records")
        ns_srvs = []
        try:
            ns_srvs = self.get_ns()
            print_status("NS Servers found:")
            for ns in ns_srvs:
                print_status("\t{0}".format(" ".join(ns)))
                ns_ip = ''.join(ns[2])
                ns_records.append(ns_ip)
        except Exception as s:
            print_error("Could not Resolve NS Records")

        # Remove duplicates
        print_status("Removing any duplicate NS server IP Addresses...")
        ns_records = list(set(ns_records))
        # Test each NS Server
        for ns_srv in ns_records:
            print_status(" ")
            print_status('Trying NS server {0}'.format(ns_srv))
            if self.check_tcp_dns(ns_srv):

                print_good('{0} Has port 53 TCP Open'.format(ns_srv))
                try:
                    zone = self.from_wire(dns.query.xfr(ns_srv, self._domain))
                    print_good('Zone Transfer was successful!!')
                    zone_records.append({'type': 'info', 'zone_transfer': 'success', 'ns_server': ns_srv})
                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SOA):
                        for rdata in rdataset:
                            for mn_ip in self.get_ip(rdata.mname.to_text()):
                                if re.search(r'^A', mn_ip[0]):
                                    print_status('\t SOA {0} {1}'.format(rdata.mname.to_text()[:-1], mn_ip[2]))
                                    zone_records.append({'zone_server': ns_srv, 'type': 'SOA',
                                                         'mname': rdata.mname.to_text()[:-1], 'address': mn_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NS):
                        for rdata in rdataset:

                            # Check if target is only the host name or a full FQDN.
                            # If only a hostname we will append the domain name of the
                            # Zone being transfered.
                            target = rdata.target.to_text()
                            target_split = target.split('.')
                            appended = False
                            if len(target_split) == 1:
                                target = target + '.' + self._domain
                                appended = True

                            for n_ip in self.get_ip(target):
                                if re.search(r'^A', n_ip[0]):

                                    if appended:
                                        print_status('\t NS {0} {1}'.format(target, n_ip[2]))
                                        zone_records.append({'zone_server': ns_srv, 'type': 'NS',
                                                        'target': target, 'address': n_ip[2]})
                                    else:
                                        if rdata.target.to_text().endswith('.'):
                                            target = rdata.target.to_text()[:-1]
                                        else:
                                            target = rdata.target.to_text()

                                        print_status('\t NS {0} {1}'.format(target, n_ip[2]))
                                        zone_records.append({'zone_server': ns_srv, 'type': 'NS',
                                                        'target': target, 'address': n_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.TXT):
                        for rdata in rdataset:
                            print_status('\t TXT {0}'.format(''.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_status('\t SPF {0}'.format(''.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.PTR):
                        for rdata in rdataset:
                            for n_ip in self.get_ip(rdata.target.to_text() + "." + self._domain):
                                if re.search(r'^A', n_ip[0]):
                                    print_status('\t PTR {0} {1}'.format(rdata.target.to_text() + "." + self._domain, n_ip[2]))
                                    zone_records.append({'zone_server': ns_srv, 'type': 'PTR',
                                                         'name': rdata.target.to_text() + "." + self._domain, 'address': n_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.MX):
                        for rdata in rdataset:
                            for e_ip in self.get_ip(rdata.exchange.to_text()):
                                if re.search(r'^A', e_ip[0]):
                                    if rdata.exchange.to_text().endswith('.'):
                                        exchange = rdata.exchange.to_text()[:-1]
                                    else:
                                        exchange = rdata.exchange.to_text()
                                    print_status('\t MX {0} {1} {2}'.format(str(name) + '.' + self._domain,
                                                 exchange, e_ip[2]))
                                zone_records.append({'zone_server': ns_srv, 'type': 'MX',
                                                     'name': str(name) + '.' + self._domain,
                                                     'exchange': exchange,
                                                     'address': e_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.AAAA):
                        for rdata in rdataset:
                            print_status('\t AAAA {0} {1}'.format(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_status('\t A {0} {1}'.format(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:
                            for t_ip in self.get_ip(rdata.target.to_text()):
                                if re.search(r'^A', t_ip[0]):
                                    if rdata.target.to_text().endswith('.'):
                                        ctarget = rdata.target.to_text()[:-1]
                                    else:
                                        ctarget = rdata.target.to_text()
                                    print_status('\t CNAME {0} {1} {2}'.format(str(name) + '.'
                                                 + self._domain, rdata.target.to_text(), t_ip[2]))
                                    zone_records.append({'zone_server': ns_srv, 'type': 'CNAME',
                                                         'name': str(name) + '.' + self._domain,
                                                         'target': str(ctarget),
                                                         'address': t_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SRV):
                        for rdata in rdataset:
                            ip_list = self.get_ip(rdata.target.to_text())
                            if ip_list:
                                for t_ip in self.get_ip(rdata.target.to_text()):
                                    if re.search(r'^A', t_ip[0]):
                                        print_status('\t SRV {0} {1} {2} {3} {4}'.format(str(name) + '.' + self._domain, rdata.target,
                                                     str(rdata.port), str(rdata.weight), t_ip[2]))
                                        zone_records.append({'zone_server': ns_srv, 'type': 'SRV',
                                                            'name': str(name) + '.' + self._domain,
                                                            'target': rdata.target.to_text()[:-1],
                                                            'address': t_ip[2],
                                                            'port': str(rdata.port),
                                                            'weight': str(rdata.weight)})
                            else:
                                print_status('\t SRV {0} {1} {2} {3} {4}'.format(str(name) + '.' + self._domain, rdata.target,
                                             str(rdata.port), str(rdata.weight), 'no_ip'))
                                zone_records.append({'zone_server': ns_srv, 'type': 'SRV',
                                                    'name': str(name) + '.' + self._domain,
                                                    'target': rdata.target.to_text()[:-1],
                                                    'address': "no_ip",
                                                    'port': str(rdata.port),
                                                    'weight': str(rdata.weight)})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.HINFO):
                        for rdata in rdataset:
                            print_status('\t HINFO {0} {1}'.format(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_status('\t WKS {0} {1} {2}'.format(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_status('\t RP {0} {1}'.format(rdata.mbox, rdata.txt))
                            zone_records.append({'zone_server': ns_srv, 'type': 'RP',
                                                'mbox': rdata.mbox.to_text(), 'txt': rdata.txt.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.AFSDB):
                        for rdata in rdataset:
                            print_status('\t AFSDB {0} {1}'.format(str(rdata.subtype), rdata.hostname))
                            zone_records.append({'zone_server': ns_srv, 'type': 'AFSDB',
                                                'subtype': str(rdata.subtype), 'hostname': rdata.hostname.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.LOC):
                        for rdata in rdataset:
                            print_status('\t LOC {0}'.format(rdata.to_text()))
                            zone_records.append({'zone_server': ns_srv, 'type': 'LOC',
                                                'coordinates': rdata.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.X25):
                        for rdata in rdataset:
                            print_status('\tX25 {0}'.format(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_status('\t ISDN {0}'.format(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_status('\t RT {0} {1}'.format(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_status('\t NSAP {0}'.format(rdata.address))
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSAP',
                                                 'address': rdata.address})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NAPTR):
                        for rdata in rdataset:
                            print_status('\t NAPTR {0} {1} {2} {3} {4} {5}'.format(rdata.flags,
                                                                                   rdata.order,
                                                                                   rdata.preference,
                                                                                   rdata.regexp,
                                                                                   rdata.replacement,
                                                                                   rdata.service))
                            zone_records.append({'zone_server': ns_srv, 'type': 'NAPTR',
                                                 'order': str(rdata.order),
                                                 'preference': str(rdata.preference),
                                                 'regex': rdata.regexp,
                                                 'replacement': rdata.replacement.to_text(),
                                                 'service': rdata.service})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.CERT):
                        for rdata in rdataset:
                            print_status('\t CERT {0}'.format(rdata.to_text()))
                            zone_records.append({'zone_server': ns_srv, 'type': 'CERT',
                                                 'algorithm': rdata.algorithm,
                                                 'certificate': rdata.certificate,
                                                 'certificate_type': rdata.certificate_type,
                                                 'key_tag': rdata.key_tag})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SIG):
                        for rdata in rdataset:
                            print_status('\t SIG {0} {1} {2} {3} {4} {5} {6} {7} {8}'.format(
                                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_status('\t RRSIG {0} {1} {2} {3} {4} {5} {6} {7} {8}'.format(
                                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_status('\t DNSKEY {0} {1} {2} {3}'.format(
                                algorithm_to_text(rdata.algorithm), rdata.flags, dns.rdata._hexify(rdata.key),
                                rdata.protocol))
                            zone_records.append({'zone_server': ns_srv, 'type': 'DNSKEY',
                                                 'algorithm': algorithm_to_text(rdata.algorithm),
                                                 'flags': rdata.flags,
                                                 'key': dns.rdata._hexify(rdata.key),
                                                 'protocol': rdata.protocol})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.DS):
                        for rdata in rdataset:
                            print_status('\t DS {0} {1} {2} {3}'.format(algorithm_to_text(rdata.algorithm), dns.rdata._hexify(rdata.digest),
                                         rdata.digest_type, rdata.key_tag))
                            zone_records.append({'zone_server': ns_srv, 'type': 'DS',
                                                'algorithm': algorithm_to_text(rdata.algorithm),
                                                'digest': dns.rdata._hexify(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_status('\t NSEC {0}'.format(rdata.next))
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSEC',
                                                 'next': rdata.next.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC3):
                        for rdata in rdataset:
                            print_status('\t NSEC3 {0} {1} {2} {3}'.format(algorithm_to_text(rdata.algorithm), rdata.flags,
                                         rdata.iterations, rdata.salt))
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSEC3',
                                                 'algorithm': algorithm_to_text(rdata.algorithm),
                                                 'flags': rdata.flags,
                                                 'iterations': rdata.iterations,
                                                 'salt': dns.rdata._hexify(rdata.salt)})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC3PARAM):
                        for rdata in rdataset:
                            print_status('\t NSEC3PARAM {0} {1} {2} {3}'.format(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': dns.rdata._hexify(rdata.salt)})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.IPSECKEY):
                        for rdata in rdataset:
                            print_status('\t PSECKEY {0} {1} {2} {3} {4}'.format(algorithm_to_text(rdata.algorithm), rdata.gateway,
                                         rdata.gateway_type, dns.rdata._hexify(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': dns.rdata._hexify(rdata.key),
                                                 'precedence': rdata.precedence})
                except Exception as e:
                    print_error('Zone Transfer Failed!')
                    print_error(e)
                    zone_records.append({'type': 'info', 'zone_transfer': 'failed', 'ns_server': ns_srv})
            else:
                print_error('Zone Transfer Failed for {0}!'.format(ns_srv))
                print_error('Port 53 TCP is being filtered')
                zone_records.append({'type': 'info', 'zone_transfer': 'failed', 'ns_server': ns_srv})
        return zone_records
コード例 #6
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 = []
        ns_records = []
        print_status(f'Checking for Zone Transfer for {self._domain} name servers')

        # Find SOA for Domain
        print_status("Resolving SOA Record")
        try:
            soa_srvs = self.get_soa()
            for s in soa_srvs:
                print(s)
                print_good("\t {0}".format(" ".join(s)))
                ns_records.append(s[2])
        except Exception:
            print_error("Could not obtain the domains SOA Record.")
            return

        # Find NS for Domain
        print_status("Resolving NS Records")
        try:
            ns_srvs = []
            ns_srvs = self.get_ns()
            for ns in ns_srvs:
                ns_ip = ''.join(ns[2])
                ns_records.append(ns_ip)
        except Exception as e:
            print_error(f"Could not Resolve NS Records: {e}")

        # Remove duplicates
        print_status("Removing any duplicate NS server IP Addresses...")
        ns_records = list(set(ns_records))
        # Test each NS Server
        for ns_srv in ns_records:
            print_status(" ")
            print_status(f'Trying NS server {ns_srv}')
            if self.check_tcp_dns(ns_srv):
                print_good(f'{ns_srvs} Has port 53 TCP Open')
                try:
                    zone = self.from_wire(dns.query.xfr(ns_srv, self._domain))
                    print_good('Zone Transfer was successful!!')
                    zone_records.append({'type': 'info', 'zone_transfer': 'success', 'ns_server': ns_srv})
                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SOA):
                        for rdata in rdataset:
                            for mn_ip in self.get_ip(rdata.mname.to_text()):
                                if re.search(r'^A', mn_ip[0]):
                                    zone_records.append({'zone_server': ns_srv, 'type': 'SOA',
                                                         'mname': rdata.mname.to_text()[:-1], 'address': mn_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NS):
                        for rdata in rdataset:

                            # Check if target is only the host name or a full FQDN.
                            # If only a hostname we will append the domain name of the
                            # Zone being transfered.
                            target = rdata.target.to_text()
                            target_split = target.split('.')
                            appended = False
                            if len(target_split) == 1:
                                target = target + '.' + self._domain
                                appended = True

                            for n_ip in self.get_ip(target):
                                if re.search(r'^A', n_ip[0]):

                                    if appended:
                                        zone_records.append({'zone_server': ns_srv, 'type': 'NS',
                                                             'target': target, 'address': n_ip[2]})
                                    else:
                                        if rdata.target.to_text().endswith('.'):
                                            target = rdata.target.to_text()[:-1]
                                        else:
                                            target = rdata.target.to_text()

                                        zone_records.append({'zone_server': ns_srv, 'type': 'NS',
                                                             'target': target, 'address': n_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.TXT):
                        for rdata in rdataset:
                            rdata = [string.decode() for string in rdata.strings]
                            zone_records.append({'zone_server': ns_srv, 'type': 'TXT',
                                                'strings': ''.join(rdata)})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SPF):
                        for rdata in rdataset:
                            #print_status('\t SPF {0}'.format(''.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.PTR):
                        for rdata in rdataset:
                            for n_ip in self.get_ip(rdata.target.to_text() + "." + self._domain):
                                if re.search(r'^A', n_ip[0]):
                                    zone_records.append({'zone_server': ns_srv, 'type': 'PTR',
                                                         'name': rdata.target.to_text() + "." + self._domain, 'address': n_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.MX):
                        for rdata in rdataset:
                            for e_ip in self.get_ip(rdata.exchange.to_text()):
                                if re.search(r'^A', e_ip[0]):
                                    if rdata.exchange.to_text().endswith('.'):
                                        exchange = rdata.exchange.to_text()[:-1]
                                    else:
                                        exchange = rdata.exchange.to_text()
                                    print_status('\t MX {0} {1} {2}'.format(str(name) + '.' + self._domain,
                                                 exchange, e_ip[2]))
                                zone_records.append({'zone_server': ns_srv, 'type': 'MX',
                                                     'name': str(name) + '.' + self._domain,
                                                     'exchange': exchange,
                                                     'address': e_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.AAAA):
                        for rdata in rdataset:
                            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:
                            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:
                            for t_ip in self.get_ip(rdata.target.to_text()):
                                if re.search(r'^A', t_ip[0]):
                                    if rdata.target.to_text().endswith('.'):
                                        ctarget = rdata.target.to_text()[:-1]
                                    else:
                                        ctarget = rdata.target.to_text()
                                    zone_records.append({'zone_server': ns_srv, 'type': 'CNAME',
                                                         'name': str(name) + '.' + self._domain,
                                                         'target': str(ctarget),
                                                         'address': t_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SRV):
                        for rdata in rdataset:
                            ip_list = self.get_ip(rdata.target.to_text())
                            if ip_list:
                                for t_ip in self.get_ip(rdata.target.to_text()):
                                    if re.search(r'^A', t_ip[0]):
                                        zone_records.append({'zone_server': ns_srv, 'type': 'SRV',
                                                            'name': str(name) + '.' + self._domain,
                                                             'target': rdata.target.to_text()[:-1],
                                                             'address': t_ip[2],
                                                             'port': str(rdata.port),
                                                             'weight': str(rdata.weight)})
                            else:
                                zone_records.append({'zone_server': ns_srv, 'type': 'SRV',
                                                    'name': str(name) + '.' + self._domain,
                                                     'target': rdata.target.to_text()[:-1],
                                                     'address': "no_ip",
                                                     'port': str(rdata.port),
                                                     'weight': str(rdata.weight)})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.HINFO):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'HINFO',
                                                'cpu': rdata.cpu.decode(), 'os': rdata.os.decode()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.WKS):
                        for rdata in rdataset:
                            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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'RP',
                                                'mbox': rdata.mbox.to_text(), 'txt': rdata.txt.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.AFSDB):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'AFSDB',
                                                'subtype': str(rdata.subtype), 'hostname': rdata.hostname.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.LOC):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'LOC',
                                                'coordinates': rdata.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.X25):
                        for rdata in rdataset:
                            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:
                            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:
                            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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSAP',
                                                 'address': rdata.address})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NAPTR):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'NAPTR',
                                                 'order': str(rdata.order),
                                                 'preference': str(rdata.preference),
                                                 'regex': rdata.regexp.decode(),
                                                 'replacement': rdata.replacement.to_text(),
                                                 'service': rdata.service.decode()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.CERT):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'CERT',
                                                 'algorithm': rdata.algorithm,
                                                 'certificate': rdata.certificate,
                                                 'certificate_type': rdata.certificate_type,
                                                 'key_tag': rdata.key_tag})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SIG):
                        for rdata in rdataset:
                            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:
                            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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'DNSKEY',
                                                 'algorithm': algorithm_to_text(rdata.algorithm),
                                                 'flags': rdata.flags,
                                                 'key': dns.rdata._hexify(rdata.key),
                                                 'protocol': rdata.protocol})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.DS):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'DS',
                                                'algorithm': algorithm_to_text(rdata.algorithm),
                                                 'digest': dns.rdata._hexify(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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSEC',
                                                 'next': rdata.next.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC3):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSEC3',
                                                 'algorithm': algorithm_to_text(rdata.algorithm),
                                                 'flags': rdata.flags,
                                                 'iterations': rdata.iterations,
                                                 'salt': dns.rdata._hexify(rdata.salt)})

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

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.IPSECKEY):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'IPSECKEY',
                                                 'algorithm': algorithm_to_text(rdata.algorithm),
                                                 'gateway': rdata.gateway,
                                                 'gateway_type': rdata.gateway_type,
                                                 'key': dns.rdata._hexify(rdata.key),
                                                 'precedence': rdata.precedence})
                except Exception as e:
                    print_error('Zone Transfer Failed!')
                    print_error(e)
                    import traceback as t
                    t.print_exc()
                    zone_records.append({'type': 'info', 'zone_transfer': 'failed', 'ns_server': ns_srv})
            else:
                print_error('Zone Transfer Failed for {0}!'.format(ns_srv))
                print_error('Port 53 TCP is being filtered')
                zone_records.append({'type': 'info', 'zone_transfer': 'failed', 'ns_server': ns_srv})
        return zone_records
コード例 #7
0
ファイル: dnshelper.py プロジェクト: cryptedwolf/3102
    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 = []
        ns_records = []

        # Find SOA for Domain
        try:
            soa_srvs = self.get_soa()
            for s in soa_srvs:
                ns_records.append(s[2])
        except:
            return

        # Find NS for Domain
        ns_srvs = []
        try:
            ns_srvs = self.get_ns()
            for ns in ns_srvs:
                ns_ip = ''.join(ns[2])
                ns_records.append(ns_ip)
        except Exception as s:
            pass

        # Remove duplicates
        ns_records = list(set(ns_records))
        # Test each NS Server
        for ns_srv in ns_records:
            if self.check_tcp_dns(ns_srv):

                try:
                    zone = self.from_wire(dns.query.xfr(ns_srv, self._domain))
                    zone_records.append({'type': 'info', 'zone_transfer': 'success', 'ns_server': ns_srv})
                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SOA):
                        for rdata in rdataset:
                            for mn_ip in self.get_ip(rdata.mname.to_text()):
                                if re.search(r'^A', mn_ip[0]):
                                    zone_records.append({'zone_server': ns_srv, 'type': 'SOA',
                                                         'mname': rdata.mname.to_text()[:-1], 'address': mn_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NS):
                        for rdata in rdataset:

                            # Check if target is only the host name or a full FQDN.
                            # If only a hostname we will appaned the domain name of the
                            # Zone being transfered.
                            target = rdata.target.to_text()
                            target_split = target.split('.')
                            appended = False
                            if len(target_split) == 1:
                                target = target + '.' + self._domain
                                appended = True

                            for n_ip in self.get_ip(target):
                                if re.search(r'^A', n_ip[0]):

                                    if appended:
                                        zone_records.append({'zone_server': ns_srv, 'type': 'NS',
                                                        'target': target, 'address': n_ip[2]})
                                    else:
                                        zone_records.append({'zone_server': ns_srv, 'type': 'NS',
                                                        'target': rdata.target.to_text()[:-1], 'address': n_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.TXT):
                        for rdata in rdataset:
                            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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'SPF',
                                                 'strings': ''.join(rdata.strings)})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.PTR):
                        for rdata in rdataset:
                            for n_ip in self.get_ip(rdata.target.to_text() + "." + self._domain):
                                if re.search(r'^A', n_ip[0]):
                                    zone_records.append({'zone_server': ns_srv, 'type': 'PTR',
                                                         'name': rdata.target.to_text() + "." + self._domain, 'address': n_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.MX):
                        for rdata in rdataset:
                            for e_ip in self.get_ip(rdata.exchange.to_text()):
                                zone_records.append({'zone_server': ns_srv, 'type': 'MX',
                                                     'name': str(name) + '.' + self._domain,
                                                     'exchange': rdata.exchange.to_text()[:-1],
                                                     'address': e_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.AAAA):
                        for rdata in rdataset:
                            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:
                            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:
                            for t_ip in self.get_ip(rdata.target.to_text()):
                                if re.search(r'^A', t_ip[0]):
                                    zone_records.append({'zone_server': ns_srv, 'type': 'CNAME',
                                                         'name': str(name) + '.' + self._domain,
                                                         'target': str(rdata.target.to_text())[:-1],
                                                         'address': t_ip[2]})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SRV):
                        for rdata in rdataset:
                            ip_list = self.get_ip(rdata.target.to_text())
                            if ip_list:
                                for t_ip in self.get_ip(rdata.target.to_text()):
                                    if re.search(r'^A', t_ip[0]):
                                        zone_records.append({'zone_server': ns_srv, 'type': 'SRV',
                                                            'name': str(name) + '.' + self._domain,
                                                            'target': rdata.target.to_text()[:-1],
                                                            'address': t_ip[2],
                                                            'port': str(rdata.port),
                                                            'weight': str(rdata.weight)})
                            else:
                                zone_records.append({'zone_server': ns_srv, 'type': 'SRV',
                                                    'name': str(name) + '.' + self._domain,
                                                    'target': rdata.target.to_text()[:-1],
                                                    'address': "no_ip",
                                                    'port': str(rdata.port),
                                                    'weight': str(rdata.weight)})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.HINFO):
                        for rdata in rdataset:
                            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:
                            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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'RP',
                                                'mbox': rdata.mbox.to_text(), 'txt': rdata.txt.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.AFSDB):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'AFSDB',
                                                'subtype': str(rdata.subtype), 'hostname': rdata.hostname.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.LOC):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'LOC',
                                                'coordinates': rdata.to_text()})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.X25):
                        for rdata in rdataset:
                            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:
                            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:
                            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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSAP',
                                                 'address': rdata.address})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NAPTR):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'NAPTR',
                                                 'order': str(rdata.order),
                                                 'preference': str(rdata.preference),
                                                 'regex': rdata.regexp,
                                                 'replacement': rdata.replacement.to_text(),
                                                 'service': rdata.service})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.CERT):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'CERT',
                                                 'algorithm': rdata.algorithm,
                                                 'certificate': rdata.certificate,
                                                 'certificate_type': rdata.certificate_type,
                                                 'key_tag': rdata.key_tag})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.SIG):
                        for rdata in rdataset:
                            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:
                            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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'DNSKEY',
                                                 'algorithm': algorithm_to_text(rdata.algorithm),
                                                 'flags': rdata.flags,
                                                 'key': dns.rdata._hexify(rdata.key),
                                                 'protocol': rdata.protocol})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.DS):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'DS',
                                                'algorithm': algorithm_to_text(rdata.algorithm),
                                                'digest': dns.rdata._hexify(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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSEC',
                                                 'next': rdata.next})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC3):
                        for rdata in rdataset:
                            zone_records.append({'zone_server': ns_srv, 'type': 'NSEC3',
                                                 'algorithm': algorithm_to_text(rdata.algorithm),
                                                 'flags': rdata.flags,
                                                 'iterations': rdata.iterations,
                                                 'salt': dns.rdata._hexify(rdata.salt)})

                    for (name, rdataset) in zone.iterate_rdatasets(dns.rdatatype.NSEC3PARAM):
                        for rdata in rdataset:
                            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:
                            zone_records.append({'zone_server': ns_srv, 'type': 'IPSECKEY',
                                                 'algorithm': algorithm_to_text(rdata.algorithm),
                                                 'gateway': rdata.gateway,
                                                 'gateway_type': rdata.gateway_type,
                                                 'key': dns.rdata._hexify(rdata.key),
                                                 'precedence': rdata.precedence})
                except Exception as e:
                    zone_records.append({'type': 'info', 'zone_transfer': 'failed', 'ns_server': ns_srv})
            else:
                zone_records.append({'type': 'info', 'zone_transfer': 'failed', 'ns_server': ns_srv})
        return zone_records
コード例 #8
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 = []
        ns_records = []

        # Find SOA for Domain
        try:
            soa_srvs = self.get_soa()
            for s in soa_srvs:
                ns_records.append(s[2])
        except:
            return

        # Find NS for Domain
        ns_srvs = []
        try:
            ns_srvs = self.get_ns()
            for ns in ns_srvs:
                ns_ip = ''.join(ns[2])
                ns_records.append(ns_ip)
        except Exception as s:
            pass

        # Remove duplicates
        ns_records = list(set(ns_records))
        # Test each NS Server
        for ns_srv in ns_records:
            if self.check_tcp_dns(ns_srv):

                try:
                    zone = self.from_wire(dns.query.xfr(ns_srv, self._domain))
                    zone_records.append({
                        'type': 'info',
                        'zone_transfer': 'success',
                        'ns_server': ns_srv
                    })
                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.SOA):
                        for rdata in rdataset:
                            for mn_ip in self.get_ip(rdata.mname.to_text()):
                                if re.search(r'^A', mn_ip[0]):
                                    zone_records.append({
                                        'zone_server':
                                        ns_srv,
                                        'type':
                                        'SOA',
                                        'mname':
                                        rdata.mname.to_text()[:-1],
                                        'address':
                                        mn_ip[2]
                                    })

                    for (name,
                         rdataset) in zone.iterate_rdatasets(dns.rdatatype.NS):
                        for rdata in rdataset:

                            # Check if target is only the host name or a full FQDN.
                            # If only a hostname we will appaned the domain name of the
                            # Zone being transfered.
                            target = rdata.target.to_text()
                            target_split = target.split('.')
                            appended = False
                            if len(target_split) == 1:
                                target = target + '.' + self._domain
                                appended = True

                            for n_ip in self.get_ip(target):
                                if re.search(r'^A', n_ip[0]):

                                    if appended:
                                        zone_records.append({
                                            'zone_server': ns_srv,
                                            'type': 'NS',
                                            'target': target,
                                            'address': n_ip[2]
                                        })
                                    else:
                                        zone_records.append({
                                            'zone_server':
                                            ns_srv,
                                            'type':
                                            'NS',
                                            'target':
                                            rdata.target.to_text()[:-1],
                                            'address':
                                            n_ip[2]
                                        })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.TXT):
                        for rdata in rdataset:
                            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:
                            zone_records.append({
                                'zone_server':
                                ns_srv,
                                'type':
                                'SPF',
                                'strings':
                                ''.join(rdata.strings)
                            })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.PTR):
                        for rdata in rdataset:
                            for n_ip in self.get_ip(rdata.target.to_text() +
                                                    "." + self._domain):
                                if re.search(r'^A', n_ip[0]):
                                    zone_records.append({
                                        'zone_server':
                                        ns_srv,
                                        'type':
                                        'PTR',
                                        'name':
                                        rdata.target.to_text() + "." +
                                        self._domain,
                                        'address':
                                        n_ip[2]
                                    })

                    for (name,
                         rdataset) in zone.iterate_rdatasets(dns.rdatatype.MX):
                        for rdata in rdataset:
                            for e_ip in self.get_ip(rdata.exchange.to_text()):
                                zone_records.append({
                                    'zone_server':
                                    ns_srv,
                                    'type':
                                    'MX',
                                    'name':
                                    str(name) + '.' + self._domain,
                                    'exchange':
                                    rdata.exchange.to_text()[:-1],
                                    'address':
                                    e_ip[2]
                                })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.AAAA):
                        for rdata in rdataset:
                            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:
                            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:
                            for t_ip in self.get_ip(rdata.target.to_text()):
                                if re.search(r'^A', t_ip[0]):
                                    zone_records.append({
                                        'zone_server':
                                        ns_srv,
                                        'type':
                                        'CNAME',
                                        'name':
                                        str(name) + '.' + self._domain,
                                        'target':
                                        str(rdata.target.to_text())[:-1],
                                        'address':
                                        t_ip[2]
                                    })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.SRV):
                        for rdata in rdataset:
                            ip_list = self.get_ip(rdata.target.to_text())
                            if ip_list:
                                for t_ip in self.get_ip(
                                        rdata.target.to_text()):
                                    if re.search(r'^A', t_ip[0]):
                                        zone_records.append({
                                            'zone_server':
                                            ns_srv,
                                            'type':
                                            'SRV',
                                            'name':
                                            str(name) + '.' + self._domain,
                                            'target':
                                            rdata.target.to_text()[:-1],
                                            'address':
                                            t_ip[2],
                                            'port':
                                            str(rdata.port),
                                            'weight':
                                            str(rdata.weight)
                                        })
                            else:
                                zone_records.append({
                                    'zone_server':
                                    ns_srv,
                                    'type':
                                    'SRV',
                                    'name':
                                    str(name) + '.' + self._domain,
                                    'target':
                                    rdata.target.to_text()[:-1],
                                    'address':
                                    "no_ip",
                                    'port':
                                    str(rdata.port),
                                    'weight':
                                    str(rdata.weight)
                                })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.HINFO):
                        for rdata in rdataset:
                            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:
                            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:
                            zone_records.append({
                                'zone_server': ns_srv,
                                'type': 'RP',
                                'mbox': rdata.mbox.to_text(),
                                'txt': rdata.txt.to_text()
                            })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.AFSDB):
                        for rdata in rdataset:
                            zone_records.append({
                                'zone_server':
                                ns_srv,
                                'type':
                                'AFSDB',
                                'subtype':
                                str(rdata.subtype),
                                'hostname':
                                rdata.hostname.to_text()
                            })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.LOC):
                        for rdata in rdataset:
                            zone_records.append({
                                'zone_server': ns_srv,
                                'type': 'LOC',
                                'coordinates': rdata.to_text()
                            })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.X25):
                        for rdata in rdataset:
                            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:
                            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:
                            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:
                            zone_records.append({
                                'zone_server': ns_srv,
                                'type': 'NSAP',
                                'address': rdata.address
                            })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.NAPTR):
                        for rdata in rdataset:
                            zone_records.append({
                                'zone_server':
                                ns_srv,
                                'type':
                                'NAPTR',
                                'order':
                                str(rdata.order),
                                'preference':
                                str(rdata.preference),
                                'regex':
                                rdata.regexp,
                                'replacement':
                                rdata.replacement.to_text(),
                                'service':
                                rdata.service
                            })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.CERT):
                        for rdata in rdataset:
                            zone_records.append({
                                'zone_server': ns_srv,
                                'type': 'CERT',
                                'algorithm': rdata.algorithm,
                                'certificate': rdata.certificate,
                                'certificate_type': rdata.certificate_type,
                                'key_tag': rdata.key_tag
                            })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.SIG):
                        for rdata in rdataset:
                            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:
                            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:
                            zone_records.append({
                                'zone_server':
                                ns_srv,
                                'type':
                                'DNSKEY',
                                'algorithm':
                                algorithm_to_text(rdata.algorithm),
                                'flags':
                                rdata.flags,
                                'key':
                                dns.rdata._hexify(rdata.key),
                                'protocol':
                                rdata.protocol
                            })

                    for (name,
                         rdataset) in zone.iterate_rdatasets(dns.rdatatype.DS):
                        for rdata in rdataset:
                            zone_records.append({
                                'zone_server':
                                ns_srv,
                                'type':
                                'DS',
                                'algorithm':
                                algorithm_to_text(rdata.algorithm),
                                'digest':
                                dns.rdata._hexify(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:
                            zone_records.append({
                                'zone_server': ns_srv,
                                'type': 'NSEC',
                                'next': rdata.next
                            })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.NSEC3):
                        for rdata in rdataset:
                            zone_records.append({
                                'zone_server':
                                ns_srv,
                                'type':
                                'NSEC3',
                                'algorithm':
                                algorithm_to_text(rdata.algorithm),
                                'flags':
                                rdata.flags,
                                'iterations':
                                rdata.iterations,
                                'salt':
                                dns.rdata._hexify(rdata.salt)
                            })

                    for (name, rdataset) in zone.iterate_rdatasets(
                            dns.rdatatype.NSEC3PARAM):
                        for rdata in rdataset:
                            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:
                            zone_records.append({
                                'zone_server':
                                ns_srv,
                                'type':
                                'IPSECKEY',
                                'algorithm':
                                algorithm_to_text(rdata.algorithm),
                                'gateway':
                                rdata.gateway,
                                'gateway_type':
                                rdata.gateway_type,
                                'key':
                                dns.rdata._hexify(rdata.key),
                                'precedence':
                                rdata.precedence
                            })
                except Exception as e:
                    zone_records.append({
                        'type': 'info',
                        'zone_transfer': 'failed',
                        'ns_server': ns_srv
                    })
            else:
                zone_records.append({
                    'type': 'info',
                    'zone_transfer': 'failed',
                    'ns_server': ns_srv
                })
        return zone_records
コード例 #9
0
ファイル: dnshelper.py プロジェクト: brunotikami/dnsrecon
    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