更改编码以将Pyshark原始数据转换为scapy原始数据

时间:2018-04-12 17:49:11

标签: python wireshark scapy tshark pyshark

我对Pyshark做了一些修改,让它包含原始数据。从那里,我可以抓住看起来像这样的frame_raw.value

'000026002f4000a0200800a0200800001b2db7ec0100000010308f09c000cb000000c300cb01c4007c0018742eb7cf16c3cabcb2'

我现在需要使用该数据创建一个scapy数据包,需要看起来像这样:

b'\x00\x00&\x00/@\x00\xa0 \x08\x00\xa0 \x08\x00\x00\x1b-\xb7\xec\x01\x00\x00\x00\x100\x8f\t\xc0\x00\xcb\x00\x00\x00\xc3\x00\xcb\x01\xc4\x00|\x00\x18t.\xb7\xcf\x16\xc3\xca\xbc\xb2'

如何将pyshark数据转换为scapy所需的格式?

以下是我输入和输出的示例:

In [264]: d

Out[264]: '000026002f4000a0200800a0200800001b2db7ec0100000010308f09c000cb000000c300cb01c4007c0018742eb7cf16c3cabcb2'

In [265]: RadioTap(d)

Out[265]: <RadioTap version=48 pad=48 len=12336 present=Flags+FHSS+dBm_AntSignal+dB_TX_Attenuation+dBm_TX_Power+dB_AntSignal+dB_AntNoise+b20+b21+b28+b29 notdecoded='2f4000a0200800a0200800001b2db7ec0100000010308f09c000cb000000c300cb01c4007c0018742eb7cf16c3cabcb2' |>

1 个答案:

答案 0 :(得分:2)

只需将二进制字符串传递给RadioTap()(或Ether(),如果这是您的链接层协议),对我来说很有用:

Scapy 2.4 +

>>> from scapy.all import *
>>> data="000026002f4000a0200800a0200800001b2db7ec0100000010308f09c000cb000000c300cb01c4007c0018742eb7cf16c3cabcb2"
>>> RadioTap(hex_bytes(data))
<RadioTap  version=0 pad=0 len=38 present=TSFT+Flags+Rate+Channel+dBm_AntSignal+b14+b29+Ext notdecoded=' \x08\x00\xa0 \x08\x00\x00\x1b-\xb7\xec\x01\x00\x00\x00\x100\x8f\t\xc0\x00\xcb\x00\x00\x00\xc3\x00\xcb\x01' |<Dot11  subtype=12L type=Control proto=0L FCfield= ID=31744 addr1=18:74:2e:b7:cf:16 addr2=None addr3=None SC=None addr4=None |<Raw  load='\xc3\xca\xbc\xb2' |>>>

Scapy&lt; 2.4

Python 3

>>> from scapy.all import *
>>> import codecs
>>> data="000026002f4000a0200800a0200800001b2db7ec0100000010308f09c000cb000000c300cb01c4007c0018742eb7cf16c3cabcb2"
>>> RadioTap(codecs.decode(data, "hex"))
<RadioTap  version=0 pad=0 len=38 present=TSFT+Flags+Rate+Channel+dBm_AntSignal+b14+b29+Ext notdecoded=' \x08\x00\xa0 \x08\x00\x00\x1b-\xb7\xec\x01\x00\x00\x00\x100\x8f\t\xc0\x00\xcb\x00\x00\x00\xc3\x00\xcb\x01' |<Dot11  subtype=12L type=Control proto=0L FCfield= ID=31744 addr1=18:74:2e:b7:cf:16 addr2=None addr3=None SC=None addr4=None |<Raw  load='\xc3\xca\xbc\xb2' |>>>

Python 2

>>> from scapy.all import *
>>> data="000026002f4000a0200800a0200800001b2db7ec0100000010308f09c000cb000000c300cb01c4007c0018742eb7cf16c3cabcb2"
>>> RadioTap(data.decode("hex"))
<RadioTap  version=0 pad=0 len=38 present=TSFT+Flags+Rate+Channel+dBm_AntSignal+b14+b29+Ext notdecoded=' \x08\x00\xa0 \x08\x00\x00\x1b-\xb7\xec\x01\x00\x00\x00\x100\x8f\t\xc0\x00\xcb\x00\x00\x00\xc3\x00\xcb\x01' |<Dot11  subtype=12L type=Control proto=0L FCfield= ID=31744 addr1=18:74:2e:b7:cf:16 addr2=None addr3=None SC=None addr4=None |<Raw  load='\xc3\xca\xbc\xb2' |>>>