定义可以在这里看到。
候选答案可能是tcp and dst port 80,但可以tcp and dst port 80保证它的HTTP流量并包括所有 HTTP 流量?
似乎不是,因为可以通过这种方式指定 80 以外的其他端口来访问某些站点:
http://domain.name:8080
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:确切的BPF是HTTP什么?
更新
是否有一种实现来验证数据包是否c已经是 HTTP 数据包?
tcp and dst port 80tcp and (dst port 80 or dst port 8080 or dst port 443)tcp and tcp[20:4] = 0x47455420tcp and tcp[(tcp[12] >> 4) * 4 : 4] = 0x47455420tcp and (dst port 80 or dst port 8080 or dst port 443) and tcp[(tcp[12] >> 4) * 4 : 4] = 0x47455420BPF 不是有状态的数据包过滤器,因此 BPF 无法检测到非标准 HTTP 端口上的任何流量。BPF 在传输层而不是应用层进行过滤,因此它只关心 TCP/IP,而不关心 TCP/IP 数据包中封装的应用数据。最好的选择是过滤常见的 HTTP 端口 80、8000 和 8080。如果您还想考虑 HTTPS,也可以过滤 443。