Python Scapy HEX解码

时间:2015-07-21 16:31:39

标签: python hex scapy

我试图通过scapy嗅探功能解码无线管理帧中的信号值(SSI)。我搜索并尝试了一些回答但没有成功。这是我到目前为止所拥有的。试图解码十六进制字符串。

代码:

from scapy.all import *

def packet_handler(pkt):
    if pkt.haslayer(Dot11) and pkt.type == 0:
        sig = pkt[RadioTap].notdecoded.decode("hex")
        print sig


sniff(iface="wlan0mon", prn=packet_handler)

数据包示例:

###[ RadioTap dummy ]###
  version   = 0
  pad       = 0
  len       = 36
  present   = TSFT+Flags+Rate+Channel+dBm_AntSignal+b14+b29+Ext
  notdecoded= ' \x08\x00\x00\x00\x00\x00\x00\xf4\x82\xc2\xc6\x01\x00\x00\x00\x10\x02\x99\t\xa0\x00\xb1\x00\x00\x00\xb1\x00'

我抓住了未被解码的'字段的值并试图通过直接python解码它。

错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/scapy/sendrecv.py", line 600, in sniff
    r = prn(p)
  File "<stdin>", line 4, in packet_handler
  File "/usr/lib/python2.7/encodings/hex_codec.py", line 42, in hex_decode
    output = binascii.a2b_hex(input)
TypeError: Non-hexadecimal digit found

1 个答案:

答案 0 :(得分:1)

更新到scapy的最新版本;这些都在更新中正确解码(我使用的是2.4.0 dev263)。

更新scapy:

git clone https://github.com/secdev/scapy
cd scapy
./run_scapy

或者

git clone https://github.com/secdev/scapy
cd scapy
python setup.py install