Python 格式错误的DNS数据包scapy
我有一个作为代理的小python脚本。除了DNS请求之外,脚本的所有功能似乎都正常工作。当我的脚本收到DNS请求时,我执行请求,然后将响应转发回发出DNS请求的原始用户。但是,当发起DNS请求的一个获得响应时,它被认为是格式不正确的。我知道旧版本的scapy存在DNS问题,所以我更新到scapy 2.3.1,但仍然存在问题Python 格式错误的DNS数据包scapy,python,networking,proxy,dns,scapy,Python,Networking,Proxy,Dns,Scapy,我有一个作为代理的小python脚本。除了DNS请求之外,脚本的所有功能似乎都正常工作。当我的脚本收到DNS请求时,我执行请求,然后将响应转发回发出DNS请求的原始用户。但是,当发起DNS请求的一个获得响应时,它被认为是格式不正确的。我知道旧版本的scapy存在DNS问题,所以我更新到scapy 2.3.1,但仍然存在问题 #!/usr/bin/env python from tornado.websocket import WebSocketHandler from tornado.http
#!/usr/bin/env python
from tornado.websocket import WebSocketHandler
from tornado.httpserver import HTTPServer
from tornado.web import Application
from tornado.ioloop import IOLoop
from collections import defaultdict
from scapy.all import *
import threading
# Warning: Not thread-safe.
# Dictionary mapping (outbound.dst, outbound.dport) -> count of IP packets awaiting reply
outbound_packets = defaultdict(int)
outbound_udp = defaultdict(int)
connection = None
class PacketSniffer(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
global connection
while (True):
pkt = sniff(iface="eth0", count=1)
if pkt[0].haslayer(IP):
pkt = pkt[0][IP]
if outbound_packets[(pkt.src, pkt.sport)] > 0:
outbound_packets[(pkt.src, pkt.sport)] -= 1
if pkt[0].haslayer(UDP):
# Modify the destination address back to the address of the TUN on the host.
pkt.dst = "10.0.0.1"
try:
del pkt[UDP].chksum
del pkt[IP].chksum
pkt.show2() # Force recompute the checksum
except IndexError:
print "error deleting"
if connection:
connection.write_message(str(pkt).encode('base64'))
elif pkt[0].haslayer(TCP):
print "TCP packet"
# Modify the destination address back to the address of the TUN on the host.
pkt.dst = "10.0.0.1"
try:
del pkt[TCP].chksum
del pkt[IP].chksum
pkt.show2() # Force recompute the checksum
except IndexError:
print "error deleting"
if connection:
connection.write_message(str(pkt).encode('base64'))
我不是DNS专家,但据我所知,响应有答案RRs:2
,但查看实际的DNS答案,我只看到1个条目。假设答案RRs值应与实际答案的数量匹配是否安全?如果是这种情况,您知道如何/为什么从DNS条目中删除答案吗
跳过并讨论这个问题,最终我找到了解决问题的方法
当我将这些应用于scapy2.2.0(不是2.3.1)时,行号并不完全匹配,但很明显事情的发展方向。我首先找到并输入了18,但91本身就足以解决问题