Scapy: eth_boundary option returns IndexError: Layer [14] not found

非 Y 不嫁゛ 提交于 2019-12-11 05:09:45

问题


I'm missing something while setting eth_boundary option.

>>> eth_boundary=14
>>> pkt=e/i
>>> len(e)
14
>>> len(i)
20
>>>
>>> pkt.show()
###[ Raw ]###
  load= '\x00\xa0\xa1\x12\xc2\xc1\x001H\xcd\xe8\x5c\x08\x00E\x00\x00\x11\x00\x01\x00\x00@\x00P\xe2\x11\x01\x01\x02\x14\x01\x01\x01'

>>> pkt[eth_boundary:]
Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/home/regress/scapy/scapy/packet.py", line 1171, in __getitem__
    raise IndexError("Layer [%s] not found" % lname)
IndexError: Layer [14] not found
>>>

Please help me out on how to fix the above error.


回答1:


Problem

The problem here is that you are accessing pkt like an array of bytes when it's actually an array of layers:

>>> pkt=Ether()/IP()
>>> pkt[0]
<Ether  type=0x800 |<IP  |>>
>>> pkt[1]
<IP  |>
>>> pkt[2]
IndexError: Layer [2] not found

The error describes the problem it sees exactly: Layer [14] not found

Solution

Use raw(pkt) instead:

>>> eth_boundary = 14
>>> pkt=Ether()/IP()
>>> raw(pkt)
b'\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x08\x00E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01'
>>> raw(pkt)[14:]
b'E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01'


来源:https://stackoverflow.com/questions/58213710/scapy-eth-boundary-option-returns-indexerror-layer-14-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!