Wireshark 认为 scapy 数据包的原始数据是 DNS格式错误的数据包

问题描述

我正在尝试使用原始数据向网络中的所有设备发送带有 scapy 的 udp 数据包:(hello everyone)

数据包看起来像这样:

packet = Ether(dst="ff:ff:ff:ff:ff:ff") / IP(dst="255.255.255.0") / UDP(sport=8118) / "hello everyone"
packet.show()

###[ Ethernet ]###
  dst       = ff:ff:ff:ff:ff:ff
  src       = (my mac address)
  type      = IPv4
###[ IP ]###
     version   = 4
     ihl       = None
     tos       = 0x0
     len       = None
     id        = 1
     flags     =
     frag      = 0
     ttl       = 64
     proto     = udp
     chksum    = None
     src       = 192.168.0.105
     dst       = 255.255.255.0
     \options   \
###[ UDP ]###
        sport     = 8118
        dport     = domain
        len       = None
        chksum    = None
###[ Raw ]###
           load      = 'hello everyone'

当我发送数据包 (sendp(packet)) 时,wireshark 说这是一个格式错误的 DNS 数据包:

enter image description here

enter image description here

enter image description here

有什么问题?

解决方法

我相信您对 Wireshark 感到困惑,因为您没有指定目标端口。如果您没有为 dport 指定 UDP,则默认为 53:

class UDP(Packet):
    name = "UDP"
    fields_desc = [ShortEnumField("sport",53,UDP_SERVICES),ShortEnumField("dport",ShortField("len",None),XShortField("chksum",]

两个端口实际上都可以。 53 用于 DNS,因此 Wireshark 试图根据端口号将您的有效负载解释为 DNS。

同时指定 sportdport 以确保您的数据包不会被误解为 DNS 数据包。