如何在scapy中从hexdump获取数据?
0000 00 01 00 14 45 49 50 43 A8 2A 55 50 6F 72 74 20 [37m.[0m[37m.[0m[37m.[0m[37m.[0mEIPC[37m.[0m*UPort
0010 49 64 20 3D 20 34 33 30 35 30 2A 2A 2A 2A 2A 2A Id = 43050******
0020 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0030 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0040 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0050 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0060 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0070 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0080 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
这是我收到的一个数据包的十六进制转储,我只需要其中的 -
UPort Id = 43050
******
****************
****************
****************
****************
****************
****************
****************
这基本上就是我的有效载荷,我该怎么获取它呢?
2 个回答
0
你是在想要获取端口号吗?
>>> import re
>>> data = '\x00\x01\x00\x14\x45\x49\x50\x43\xA8\x2A\x55\x50\x6F\x72\x74\x20\x49\x64\x20\x3D\x20\x34\x33\x30\x35\x30\x2A\x2A\x2A\x2A\x2A\x2A'
>>> print re.findall('UPort Id = (\d*)', data)[0]
43050
>>>
1
你可以使用 import_hexcap() 函数,然后把你的十六进制转储(hexdump)粘贴到标准输入(stdin)里。把 IP() 替换成你想要解析的任何数据包类就可以了:
>>> pkt_hex = IP(import_hexcap())
0000 00 01 00 14 45 49 50 43 A8 2A 55 50 6F 72 74 20 [37m.[0m[37m.[0m[37m.[0m[37m.[0mEIPC[37m.[0m*UPort
0010 49 64 20 3D 20 34 33 30 35 30 2A 2A 2A 2A 2A 2A Id = 43050******
0020 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0030 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0040 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0050 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0060 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0070 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0080 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
>>> pkt_hex
<IP version=0L ihl=0L tos=0x1 len=20 id=17737 flags=DF frag=4163L ttl=168 proto=42 chksum=0x5550 src=111.114.116.32 dst=73.100.32.61 options=[<IPOption_EOL copy_flag=0L optclass=1L option=end_of_list |>, <IPOption_Router_Alert copy_flag=0L optclass=1L option=router_alert length=51 alert=12341 |>, <IPOption copy_flag=0L optclass=1L option=imi_traffic_descriptor length=42 value='****************************************' |>, <IPOption copy_flag=0L optclass=1L option=experimental_measurement length=42 value='****************************************' |>, <IPOption copy_flag=0L optclass=1L option=experimental_measurement length=42 value='*************' |>] |<Raw load='********************' |>>
>>>