[英]Malformed DNS response packet (python + scapy)
我正在使用Python和scapy創建代理服務器。 TCP數據包似乎工作正常,但我遇到了UDP的一些問題,特別是DNS請求。 基本上當DNS請求進來時我會在我的腳本中捕獲它,執行DNS查找,並嘗試將其返回給請求DNS查詢的人。 該腳本成功執行查找並返回DNS響應,但是當查看wireshark時,它告訴我它是“格式錯誤的數據包”。 有人可以告訴我我需要做什么才能正確返回DNS響應嗎?
#!/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
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(DNS):
print "Returning back has UDP"
print pkt.summary()
ipPacket = pkt[0][IP]
dnsPacket = pkt[0][DNS]
if outbound_udp[(ipPacket.src, dnsPacket.id)] > 0:
outbound_udp[(ipPacket.src, dnsPacket.id)] -= 1
print "Found in outbound_udp"
# Modify the destination address back to the address of the TUN on the host.
ipPacket.dst = "10.0.0.1"
try:
del ipPacket[TCP].chksum
del ipPacket[IP].chksum
del ipPacket[UDP].chksum
except IndexError:
print ""
ipPacket.show2() # Force recompute the checksum
if connection:
connection.write_message(str(ipPacket).encode('base64'))
sniffingThread = PacketSniffer()
sniffingThread.daemon = True
sniffingThread.start()
最近在Scapy中圍繞DNS(和其他復雜的協議,但DNS是最常見的)修復了一些錯誤:
嘗試使用Mercurial存儲庫中最新的Scapy開發版本( hg clone http://bb.secdev.org/scapy
)應該解決這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.