python - 如何从 scapy 中的 hexdump 获取数据?

标签 python scapy

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
******
****************
****************
****************
****************
****************
****************
****************

这基本上就是我的有效负载,我怎样才能得到它?

最佳答案

您可以使用 import_hexcap() 并将十六进制转储粘贴到标准输入中。将 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='********************' |>>
>>> 

关于python - 如何从 scapy 中的 hexdump 获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7121635/

相关文章:

python - Pickle 转储和时间戳与预期不符

python - 使用 Scapy 和 Python 的网桥

python - 谷歌云端点测试中的内容长度错误

php - Python 相当于 PHPs __call() 魔术方法?

python - 重复列表中的 i - n 次

python - Scapy - 持久的 RandIP

python - 使用scapy检测ARP中毒

python - Django ModelForm 和 Model 实例保存方法的区别

python - 如何使用 matplotlib 在 python 中绘制 3D 密度图

python-3.x - 即使在 scapy 中调用 load_layer ('tls' 之后也无法读取 tls 部分)