IPv6 逐跳 Scapy:ValueError:缺少“dst”属性

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

我正在尝试

IPv6
Scapy 并尝试设置
Router Alert
Hop By Hop 选项。这是代码示例:

hdr = IPv6ExtHdrHopByHop(options=[("Router Alert", b'\x01\x00')])
ip6 = IPv6(src="xxxx::xxxx", dst="yyyy::yyyy")
send(ip6 / hdr)

执行此代码会产生以下错误:

Traceback (most recent call last):                                                                                                                                                                                 
  File "/home/sn/scapy/scapy/supersocket.py", line 391, in send                                                                                                                                               
    sx = raw(x)                                                                                                                                                                                                    
         ^^^^^^                                                                                                                                                                                                    
  File "/home/sn/scapy/scapy/compat.py", line 123, in raw
    return bytes(x)
           ^^^^^^^^
  File "/home/sn/scapy/scapy/packet.py", line 609, in __bytes__
    return self.build()
           ^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/packet.py", line 768, in build
    p = self.do_build()
        ^^^^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/packet.py", line 751, in do_build
    pay = self.do_build_payload()
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/packet.py", line 737, in do_build_payload
    return self.payload.do_build()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/packet.py", line 748, in do_build
    pkt = self.self_build()
          ^^^^^^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/packet.py", line 727, in self_build
    raise ex
  File "/home/sn/scapy/scapy/packet.py", line 718, in self_build
    p = f.addfield(self, p, val)
        ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/fields.py", line 240, in addfield
    return s + self.struct.pack(self.i2m(pkt, val))
                                ^^^^^^^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/fields.py", line 2201, in i2m
    f = fld.i2len(pkt, fval)
        ^^^^^^^^^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/layers/inet6.py", line 890, in i2len
    return len(self.i2m(pkt, i))
               ^^^^^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/layers/inet6.py", line 905, in i2m
    d = p.alignment_delta(curpos)
        ^^^^^^^^^^^^^^^^^
AttributeError: While dissecting field 'len': 'tuple' object has no attribute 'alignment_delta'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/sn/scapy/scapy/sendrecv.py", line 486, in send
    return _send(
           ^^^^^^
  File "/home/sn/scapy/scapy/sendrecv.py", line 447, in _send
    results = __gen_send(socket, x, inter=inter, loop=loop,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sn/scapy/scapy/sendrecv.py", line 409, in __gen_send
    s.send(p)
  File "/home/sn/scapy/scapy/supersocket.py", line 399, in send
    raise ValueError(
ValueError: Missing 'dst' attribute in the first layer to be sent using a native L3 socket ! (make sure you passed the IP layer)

如果我删除

options=[("Router Alert", b'\x01\x00')]
并将基本上空的
HopByHop
扩展标头发送为

send (ip6 / IPv6ExtHdrHopByHop())

它工作正常,但没有多大意义。实际指定选项有什么问题?

python ipv6 scapy
1个回答
0
投票

RouterAlert
选项添加到
HopByHop
扩展标头的正确方法是使用 RouterAlert
 提供的 
scapy
 类:

ip6 = IPv6(src="xxxx::xxxx", dst="yyyy::yyyy")
hbh = IPv6ExtHdrHopByHop(options = [RouterAlert()])
packet = ip6 / hbh
send(packet)

tcpdump
报告如下:

14:31:53.650727 IP6 (hlim 64, next-header Options (0) payload length: 8)
    xxxx::xxxx > yyyy::yyyy: HBH (rtalert: 0x0000) (padn) no next header
© www.soinside.com 2019 - 2024. All rights reserved.