Python scapy&x27;s导出的linux熟食模式捕获不';不要在wireshark中打开
以下是一个简单的exmaple:Python scapy&x27;s导出的linux熟食模式捕获不';不要在wireshark中打开,python,wireshark,pcap,scapy,Python,Wireshark,Pcap,Scapy,以下是一个简单的exmaple: from scapy.all import * pkts = rdpcap('/tmp/sample.pcap') wireshark(pkts) 然后wireshark给出了以下错误: The capture file appears to be damaged or corrupt. (libpcap: IrDA capture has a packet with an invalid sll_protocol field) 我正在使用wireshark
from scapy.all import *
pkts = rdpcap('/tmp/sample.pcap')
wireshark(pkts)
然后wireshark给出了以下错误:
The capture file appears to be damaged or corrupt.
(libpcap: IrDA capture has a packet with an invalid sll_protocol field)
我正在使用wireshark 1.8、python 2.7.3和scapy 2.2.0
注意:我可以直接使用wireshark打开smaple.pcap文件
如何使scapy生成的pcap文件在wireshark中打开
编辑:
我尝试了其他pcap文件(来自wireshark捕获示例),它成功了。问题似乎出在我的包里。这是第一个数据包(也不起作用):
注意:更改了IP地址,因此校验和可能不正确。我不知道问题出在哪里,但可以通过以下方式解决:
wireshark(pkt for pkt in pkts) # don't supply a list but rather a generator
if self.linktype == None:
if type(pkt) is list or type(pkt) is tuple or isinstance(pkt,BasePacketList):
pkt = pkt[0]
try:
self.linktype = conf.l2types[pkt.__class__]
except KeyError:
warning("PcapWriter: unknown LL type for %s. Using type 1 (Ethernet)" % pkt.__class__.__name__)
self.linktype = 1
这也会输出以下消息:
警告:PcapWriter:发电机的LL类型未知。使用类型1(以太网)
显然,wireshark
函数不能很好地处理问题。这种奇怪的情况可能与以下摘录有关:
请记住Wireshark处理第2层数据包(通常称为“帧”)。因此,我们必须在ICMP数据包中添加一个Ether()。只将IP数据包(第3层)传递给Wireshark会产生奇怪的结果
如果我们真的不关心第2层帧,我们还可以通过创建虚拟以太网层来规避此问题:
pkts = [Ether(src=pkt[0].src)/pkt[1:] for pkt in pkts]
编辑-在进一步研究和分析scapy的源代码后,我发现了为什么传递生成器对象似乎可以解决这个问题
wireshark
函数创建一个包含数据包的临时文件,并使用该文件启动wireshark。要在该文件的标头中指定的链接类型将按以下方式提取:
wireshark(pkt for pkt in pkts) # don't supply a list but rather a generator
if self.linktype == None:
if type(pkt) is list or type(pkt) is tuple or isinstance(pkt,BasePacketList):
pkt = pkt[0]
try:
self.linktype = conf.l2types[pkt.__class__]
except KeyError:
warning("PcapWriter: unknown LL type for %s. Using type 1 (Ethernet)" % pkt.__class__.__name__)
self.linktype = 1
当传递生成器对象时,第一个if
语句的计算结果为False
(这显然是一个错误),并且在尝试访问conf.l2types[pkt.\uuuuu class\uuuuu]
时引发异常,因为pkt.\uuuu class\uuuuuuuuuu
是
。因此,执行try except
代码块的except子句,并将链接类型指定为1
但是,当传递真实列表时,第一个if
语句的计算结果为True
,并提取列表的第一个数据包,用于访问conf.l2types
,即:
In [2]: conf.l2types
Out[2]:
0x1 <- Dot3 (802.3)
0x1 <-> Ether (Ethernet)
0xc -> IP (IP)
0x17 -> Ether (Ethernet)
0x1f <-> IPv6 (IPv6)
0x65 <-> IP (IP)
0x69 <-> Dot11 (802.11)
0x71 -> CookedLinux (cooked linux)
0x77 <-> PrismHeader (Prism header)
0x7f <-> RadioTap (RadioTap dummy)
0x90 <-> CookedLinux (cooked linux)
0xc0 <-> PPI (Per-Packet Information header (partial))
0x304 -> Ether (Ethernet)
0x321 -> Dot11 (802.11)
0x322 -> PrismHeader (Prism header)
0x323 -> RadioTap (RadioTap dummy)
编辑-我现在注意到链接类型映射问题已经由secdev解决。然而,它还没有到达python scapy。我还在PcapWriter
中创建了对生成器对象的无效处理
(libpcap:IrDA捕获有一个包含无效sll_协议字段的数据包)
Linux IrDA使用类似于Linux烹调模式标头的内容,但不同之处在于:
- ,链路层头类型为113李>
- ,链接层标头类型为144
我不知道是什么原因导致你的程序选择144而不是113;您的输入文件是Linux IrDA文件而不是Linux熟食捕获文件吗?wireshark([pkts[0]])
有效吗?如果是,请尝试查找有问题的数据包。如果没有,请使用pkts[0]
的值编辑您的问题。