使用scapy获取DNS数据包的原始有效负载

问题描述 投票:0回答:1

我正在尝试使用packet[TCP].payload.loadpacket[UDP].payload.load从pcap文件中提取所有UDP和TCP有效负载。但是,我注意到DNS数据包的packet[UDP].payload.load失败。

packet[IP].show()的输出如下(一个DNS查询和响应数据包)。我没有看到任何[ Raw ]部分,我猜这是.load失败的地方。如何为此类数据包在UDP层之后提取有效载荷(以字节为单位)?

====================================================
###[ IP ]### 
  version   = 4
  ihl       = 5
  tos       = 0x0
  len       = 64
  id        = 59183
  flags     = 
  frag      = 0
  ttl       = 128
  proto     = udp
  chksum    = 0x0
  src       = 172.22.32.48
  dst       = 203.211.152.66
  \options   \
###[ UDP ]### 
     sport     = 55884
     dport     = domain
     len       = 44
     chksum    = 0x309a
###[ DNS ]### 
        id        = 40212
        qr        = 0
        opcode    = QUERY
        aa        = 0
        tc        = 0
        rd        = 1
        ra        = 0
        z         = 0
        <snipped>

None
====================================================
###[ IP ]### 
  version   = 4
  ihl       = 5
  tos       = 0x0
  len       = 155
  id        = 38148
  flags     = 
  frag      = 0
  ttl       = 58
  proto     = udp
  chksum    = 0xbaf1
  src       = 203.211.152.66
  dst       = 172.22.32.48
  \options   \
###[ UDP ]### 
     sport     = domain
     dport     = 55884
     len       = 135
     chksum    = 0x51d9
###[ DNS ]### 
        id        = 40212
        qr        = 1
        opcode    = QUERY
        aa        = 0
        tc        = 0
        rd        = 1
        ra        = 1
        <snipped>

None
python-2.7 dns scapy payload
1个回答
0
投票

Scapy已将DNS层分解为有意义的部分。如果需要原始字节,可以在层上调用bytes()以将其取回。

例如:

bytes(packet[TCP].payload)
© www.soinside.com 2019 - 2024. All rights reserved.