python - 无法嗅探以太网类型 0x0102 自定义数据包

标签 python networking scapy tcp

第一个问题是 Scapy 无法嗅探以太类型 0x0102 上的自定义数据包。

计算.py ↓

from scapy.all import *

class calc(Packet):
    name = 'calc'
    fields_desc = [ BitEnumField('op',0,8,{1:'ADD',2:'SUM',3:'MUL'}),
                BitField('num1',0,32),
                BitField('num2',0,32)
                ]

发送计算.py ↓

from scapy.all import *
from calc import *

p = Ether(type=0x0102)/IP(dst='192.168.1.0')/ICMP()/calc(op=1,num1=2,num2=3)
sendp(p)

嗅探计算.py ↓

from scapy.all import *
from calc import *

sniff(filter='ether proto 0x0102 and host 192.168.1.0',prn=lambda x:x.show())

第二个问题是 Scapy 可以在将 Ether-type 设置为 0x800 时进行嗅探,但不能在 0x0102 上工作。

此外,结果将自定义 calc() header 转换为 Raw。下面的结果是在 Ether-type 0x0800 上嗅探得到的。

....
###[ ICMP ]### 
    type      = echo-request
    code      = 0
    chksum    = 0xf1ff
    id        = 0x0
    seq       = 0x0
###[ Raw ]### 
       load      = '\x01\x00\x00\x00\x02\x00\x00\x00\x03'

我应该采取什么步骤才能自动解析接收到的 Calc 数据包并在以太类型 0x0102 上运行?谢谢

最佳答案

如果值为 >= 0x0600,则以太网 header 中的该字段仅用作 EtherType 字段。如果该字段的值 <= 0x5DC,则该字段被解释为负载长度字段。

您的值 0x0102 将用作有效负载长度字段,而不是 EtherType。您需要选择合适的 EtherType 值。 IANA 维护 IEEE 802 Numbers具有已注册 EtherType 值的页面,以及 the IEEE maintains a page 所有 分配的以太类型。

如果您想进行实验,您需要使用为此分配的 EtherType:

88b5
IEEE Std 802 - Local Experimental Ethertype 1. This Ethertype value is available for public use for prototype and vendor-specific protocol development, as defined in Amendment 802a to IEEE Std 802.

-或-

88b6
IEEE Std 802 - Local Experimental Ethertype 2. This Ethertype value is available for public use and for prototype and vendor-specific protocol development, as defined in Amendment 802a to IEEE Std 802.

关于python - 无法嗅探以太网类型 0x0102 自定义数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52681921/

相关文章:

networking - ping广播地址的问题

java - 常识问题 : Network Access Time, 缓存访问时间、磁盘访问时间

python - 使用 Scapy 遍历 pcap 文件中的所有 tcp 流

python - scapy 的时间戳精度更高

python - PyCharm 不导入 Scapy 模块

python - bash:字符串插值

python - 在 python 文件中运行 Django 项目时出错

Python:自 1970.01.01 GMT 午夜到任意时间 GMT 的秒数?

Python 使用一个函数循环到其他函数。

postgresql - 无法使用psycopg2连接到Postgres容器?