예제 #1
0
파일: middlewares.py 프로젝트: vognev/dhns
    def handle_dns_packet(self, query: DNSRecord, answer: DNSRecord):
        qname = query.q.qname
        qtype = query.q.qtype
        found = False

        for rec in self.records:
            if qname == rec[0]:
                found = True
                if qtype == QTYPE.ANY:
                    answer.add_answer(RR(rname=rec[0], rtype=rec[1], ttl=60, rdata=RDMAP.get(QTYPE.get(rec[1]))(rec[2])))
                elif qtype == rec[1]:
                    answer.add_answer(RR(rname=rec[0], rtype=rec[1], ttl=60, rdata=RDMAP.get(QTYPE.get(rec[1]))(rec[2])))
                    break
        return found
예제 #2
0
파일: __init__.py 프로젝트: vognev/dhns
    def handle_dns_packet(self, query: DNSRecord, answer: DNSRecord):
        import random

        qname = query.q.qname
        qtype = query.q.qtype
        found = False

        records = []

        for rec in self.records:
            if qname.matchGlob(rec[0]):
                found = True
                if qtype == QTYPE.A and rec[1] == QTYPE.CNAME:
                    # self-resolve it as A additionally
                    local_q = DNSRecord.question(rec[2], "A")
                    local_a = DNSRecord.parse(
                        local_q.send('localhost',
                                     port=int(getenv("DNSPORT", 5353)),
                                     timeout=1.0))

                    for rr in local_a.rr:
                        records.append((qname, rr.rtype, str(rr.rdata)))

                    # records.append((qname, rec[1], rec[2]))
                if qtype == QTYPE.ANY:
                    records.append(rec)
                elif qtype == rec[1]:
                    records.append(rec)

        random.shuffle(records)

        for rec in records:
            answer.add_answer(
                RR(rname=rec[0],
                   rtype=rec[1],
                   ttl=60,
                   rdata=RDMAP.get(QTYPE.get(rec[1]))(rec[2])))

        return found
예제 #3
0
def _setDNSProxy():

    if conf.dnsproxy:

        conf.nametodns = dict()

        for qtype in RDMAP.keys():

            conf.nametodns[qtype] = dict()

        if conf.ipv6:
            infoMsg = "Enable ipv6 mode."
            logger.info(infoMsg)
            if conf.interface == "127.0.0.1":
                conf.interface = "::1"

            if conf.nameserver == "8.8.8.8":
                conf.nameserver = "2001:4860:4860:8888"

        if conf.nameserver:
            conf.nameserver = conf.nameserver.split(",")

        if conf.fakeipv6 or conf.fakeip or conf.fakemail or conf.fakealias or conf.fakens:

            if conf.fakedomain:

                for domain in conf.fakedomain.split(","):

                    domain = domain.lower()
                    domain = domain.strip()

                    if conf.fakeip:
                        conf.nametodns["A"][domain] = conf.fakeip
                        msg = "Cooking A replies to point to %s matching: %s" % (
                            conf.fakeip, domain)
                        logger.info(msg)

                    if conf.fakeipv6:
                        conf.nametodns["AAAA"][domain] = conf.fakeipv6
                        msg = "Cooking AAAA replies to point to %s matching: %s" % (
                            conf.fakeipv6, domain)
                        logger.info(msg)

                    if conf.fakemail:
                        conf.nametodns["MX"][domain] = conf.fakemail
                        msg = "Cooking MX replies to point to %s matching: %s" % (
                            conf.fakemail, domain)
                        logger.info(msg)

                    if conf.fakens:
                        conf.nametodns["NS"][domain] = conf.fakens
                        msg = "Cooking NS replies to point to %s matching: %s" % (
                            conf.fakens, domain)
                        logger.info(msg)

                    if conf.fakealias:
                        conf.nametodns["CNAME"][domain] = conf.fakealias
                        msg = "Cooking CNAME replies to point to %s matching: %s" % (
                            conf.fakealias, domain)
                        logger.info(msg)

            elif conf.truedomain:

                for domain in conf.truedomain.split(","):

                    doamin = domain.lower()
                    domain = domain.strip()

                    if conf.fakeip:
                        conf.nametodns["A"][doamin] = False
                        conf.nametodns["A"][
                            '*.*.*.*.*.*.*.*.*.*'] = conf.fakeip
                        msg = "Cooking A replies to point to %s not matching: %s" % (
                            conf.fakeip, domain)
                        logger.info(msg)

                    if conf.fakeipv6:
                        conf.nametodns["AAAA"][doamin] = False
                        conf.nametodns["AAAA"][
                            "*.*.*.*.*.*.*.*.*.*"] = conf.fakeipv6
                        msg = "Cooking AAAA replies to point to %s not matching: %s" % (
                            conf.fakeipv6, domain)
                        logger.info(msg)

                    if conf.fakemail:
                        conf.nametodns["MX"][domain] = False
                        conf.nametodns["MX"][
                            "*.*.*.*.*.*.*.*.*.*"] = conf.fakemail
                        msg = "Cooking MX replies to point to %s not matching: %s" % (
                            conf.fakemail, domain)
                        logger.info(msg)

                    if conf.fakens:
                        conf.nametodns["NS"][domain] = False
                        conf.nametodns["NS"][
                            "*.*.*.*.*.*.*.*.*.*"] = conf.fakens
                        msg = "Cooking NS replies to point to %s not matching: %s" % (
                            conf.fakens, domain)
                        logger.info(msg)

                    if conf.fakealias:
                        conf.nametodns["CNAME"][domain] = False
                        conf.nametodns["CNAME"][
                            "*.*.*.*.*.*.*.*.*.*"] = conf.fakealias
                        msg = "Cooking CNAME replies to point to %s not matching: %s" % (
                            conf.fakealias, domain)
                        logger.info(msg)

            else:

                if conf.fakeip:
                    conf.nametodns["A"]['*.*.*.*.*.*.*.*.*.*'] = conf.fakeip
                    msg = "Cooking all A replies to point to %s" % conf.fakeip
                    logger.info(msg)

                if conf.fakeipv6:
                    conf.nametodns["AAAA"][
                        "*.*.*.*.*.*.*.*.*.*"] = conf.fakeipv6
                    msg = "Cooking all AAAA replies to point to %s" % conf.fakeipv6
                    logger.info(msg)

                if conf.fakemail:
                    conf.nametodns["MX"]["*.*.*.*.*.*.*.*.*.*"] = conf.fakemail
                    msg = "Cooking all MX replies to point to %s" % conf.fakemail
                    logger.info(msg)

                if conf.fakens:
                    conf.nametodns["NS"]["*.*.*.*.*.*.*.*.*.*"] = conf.fakens
                    msg = "Cooking all NS replies to point to %s" % conf.fakens
                    logger.info(msg)

                if conf.fakealias:
                    conf.nametodns["CNAME"][
                        "*.*.*.*.*.*.*.*.*.*"] = conf.fakealias
                    msg = "Cooking all CNAME replies to point to %s" % conf.fakealias
                    logger.info(msg)
예제 #4
0
                        action="store_false",
                        dest="verbose",
                        default=True,
                        help="Don't show headers.")
    parser.add_option_group(rungroup)

    (options, args) = parser.parse_args()

    # Print program header
    if options.verbose:
        print header

    # Main storage of domain filters
    # NOTE: RDMAP is a dictionary map of qtype strings to handling classes
    nametodns = dict()
    for qtype in RDMAP.keys():
        nametodns[qtype] = dict()

    # Incorrect or incomplete command line arguments
    if options.fakedomains and options.truedomains:
        print(
            "[!] You can not specify both 'fakedomains' and 'truedomains' parameters."
        )
        exit(0)

    elif not (options.fakeip or options.fakeipv6) and (options.fakedomains
                                                       or options.truedomains):
        print(
            "[!] You have forgotten to specify which IP to use for fake responses"
        )
        exit(0)