我使用的Pyshark
使用tshark
来解码pcap文件,并且使用'decode_as'选项时遇到问题。
我正在尝试将特定的UDP端口解码为SOMEIP协议。这是我添加的解剖器,取自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.
按照建议,我使用调试模式(packets.set_debug()
),运行它后,我得到:
tshark: Protocol "someip" isn't valid for layer type "udp.port"
tshark: Valid protocols for layer type "udp.port" are:
....
然后是一长串协议,其中“ someip”不在...中(而是我添加的另一个解剖器,它是dll)
有什么想法吗? 解剖器是否会引起问题,或者我做错了什么?
同样,在Wireshark中手动完成时,“解码为”效果很好。
谢谢!
编辑
因此,我了解了Dissector表,似乎应该没有问题,因为Dissector Lua代码确实将“ someip”添加到了“ udp.port”的Dissector表中:
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)
但是它不起作用:(
任何想法都会感激,谢谢