gpt4 book ai didi

python - Pyshark - tshark 无法在 'decode_as' 中使用用户插件

转载 作者:行者123 更新时间:2023-12-05 06:27:12 25 4
gpt4 key购买 nike

我使用 Pyshark,它使用 tshark 来解码 pcap 文件,但我在使用“decode_as”选项时遇到了问题。我正在尝试将特定的 UDP 端口解码为 SOMEIP 协议(protocol)。这是我添加的解剖器,取自 here .

重要的是要说解析器和“decode_as”选项在 Wireshark 中都能完美工作。

这是我使用的代码:

import pyshark

packets=pyshark.FileCapture(pcap_path, display_filter="udp")
packets.next() # Works fine

packets=pyshark.FileCapture(pcap_path, display_filter="udp", decode_as={"udp.port==50000":"someip"})
packets.next() # doesn't return a packet

还有一个被忽略的异常:

Exception ignored in: <function Capture.__del__ at 0x000001D9CE035268>
Traceback (most recent call last):
File "C:\Users\SHIRM\AppData\Local\Continuum\anaconda3\lib\site-packages\pyshark\capture\capture.py", line 412, in __del__
self.close()
File "C:\Users\SHIRM\AppData\Local\Continuum\anaconda3\lib\site-packages\pyshark\capture\capture.py", line 403, in close
self.eventloop.run_until_complete(self._close_async())
File "C:\Users\SHIRM\AppData\Local\Continuum\anaconda3\lib\asyncio\base_events.py", line 573, in run_until_complete
return future.result()
File "C:\Users\SHIRM\AppData\Local\Continuum\anaconda3\lib\site-packages\pyshark\capture\capture.py", line 407, in _close_async
await self._cleanup_subprocess(process)
File "C:\Users\SHIRM\AppData\Local\Continuum\anaconda3\lib\site-packages\pyshark\capture\capture.py", line 400, in _cleanup_subprocess
% process.returncode)
pyshark.capture.capture.TSharkCrashException: TShark seems to have crashed (retcode: 1). Try rerunning in debug mode [ capture_obj.set_debug() ] or try updating tshark.

按照它的建议,我使用 Debug模式 (packets.set_debug()),运行后我得到:

tshark: Protocol "someip" isn't valid for layer type "udp.port"
tshark: Valid protocols for layer type "udp.port" are:
....

然后是一长串协议(protocol),“someip”不在...(但我添加的另一个解剖器是 dll)

知道这里出了什么问题吗?是解剖器导致了问题,还是我做错了什么?

同样,在 Wireshark 中手动完成时,“解码为”工作正常。 enter image description here

谢谢!


编辑

我在 Wireshark 代码中找到了导致此错误的部分: enter image description here

所以我阅读了有关解析器表的内容,似乎应该没有问题,因为解析器 lua 代码确实将“someip”添加到“udp.port”的解析器表中:

    local udp_dissector_table = DissectorTable.get("udp.port")
-- Register dissector to multiple ports
for i,port in ipairs{30490,30491,30501,30502,30503,30504} do
udp_dissector_table:add(port,p_someip)
tcp_dissector_table:add(port,p_someip)
end

我还尝试使用 dissectortable:add_for_decode_as(proto) 函数(在 11.6.2.11 here 中描述):

    udp_dissector_table:add_for_decode_as(p_someip)

但是没有成功:(

任何想法将不胜感激,谢谢

最佳答案

尽管这是一个老问题:

我用我的 pcap 试过它有效。所以 3 个建议:

  1. 有一个错误,现在已修复 - 那么它现在应该也适用于您

  2. udp端口错误。我有一个不同的 (30490),如果这个错了,包裹将是空的。请尝试使用 50001,因为此端口显示在您的屏幕截图中

  3. pcap有一些问题,这种情况下换一个试试。

希望对您有所帮助!

关于python - Pyshark - tshark 无法在 'decode_as' 中使用用户插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55457419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com