簡體   English   中英

DNS數據包格式錯誤

[英]Malformed DNS packet scapy

我有一個小的python腳本充當代理。 除DNS請求外,其他腳本似乎一切正常。 當我的腳本收到DNS請求時,我會執行請求,然后將響應轉發回發出DNS請求的原始用戶。 但是,當發起DNS請求的請求獲得響應時,它被認為是格式錯誤的。 我知道scapy的較早版本存在DNS問題,因此我更新到scapy 2.3.1,但仍然有問題。

#!/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專家,但據我所知,響應具有Answer RRs: 2但查看實際的DNS答復,我僅看到1項。 假設Answer RRs值應與實際答案的數量相匹配是否安全? 如果是這種情況,是否知道如何/為什么從DNS條目中刪除答案?

在此處輸入圖片說明

Scapy 問題913問題5105討論了此問題,最終使我提出了解決問題的請求18請求91

當我將這些應用於Scapy 2.2.0(而非2.3.1)時,行號並不完全匹配,但是很明顯,行進去了。 我發現並首先輸入18,但是僅靠91即可解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM