简体   繁体   English

使用 sniff() 函数进行 Scapy 过滤

[英]Scapy filtering with sniff() function

I'm using scapy function sniff() for packet capturing.我正在使用 scapy 函数 sniff() 进行数据包捕获。 I want to capture only EAP packets.我只想捕获 EAP 数据包。 I can filter EAP packets with tcpdump with following filter:我可以使用以下过滤器使用 tcpdump 过滤 EAP 数据包:

# tcpdump -i mon0 -p ether proto 0x888e
tcpdump: WARNING: mon0: no IPv4 address assigned
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on mon0, link-type IEEE802_11_RADIO (802.11 plus radiotap header), capture size 65535 bytes
13:04:41.949446 80847234901us tsft 48.0 Mb/s 2437 MHz 11g -16dB signal antenna 1 [bit 14] EAP packet (0) v1, len 5
13:04:46.545776 80851831746us tsft 54.0 Mb/s 2437 MHz 11g -13dB signal antenna 1 [bit 14] EAP packet (0) v1, len 5

At the same time I have sniff() function running with the same filter, but function doesn't capture any EAP packets:同时,我有使用相同过滤器运行的 sniff() 函数,但函数不会捕获任何 EAP 数据包:

sniff(filter="ether proto 0x888e",iface="mon0", count = 1)

Why sniff() function doesn't capture any EAP packets?为什么 sniff() 函数不捕获任何 EAP 数据包?

EDIT:编辑:

Sorry for my late reaction, I tried what you proposed:抱歉我反应迟了,我尝试了你的建议:

> conf.iface = 'mon0'
> pkts = sniff(filter="wlan proto 0x888e", count = 1)
tcpdump: WARNING: mon0: no IPv4 address assigned
> pkts
Sniffed: TCP:0 UDP:0 ICMP:0 Other:1
> EAP in pkts[0]
False 

But this does not still capture EAP packet :(但这仍然不能捕获 EAP 数据包:(

I know this is over a year later, but for the benefit of anyone else looking at this question the answer is that he captured EAPOL packets, not EAP packets.我知道这是一年多之后,但为了其他看这个问题的人的利益,答案是他捕获了 EAPOL 数据包,而不是 EAP 数据包。 By using the command通过使用命令

sniff(filter="ether proto 0x888e", count=4)

0x888e refers to EAPOL in ethernet protocol, which requires the use of the ether proto, not the wlan proto. 0x888e 指的是以太网协议中的 EAPOL,它需要使用 ether proto,而不是 wlan proto。 I'm not sure if 0888e can be referred to anything in wlan proto, but after doing almost the identical thing as the op (except replacing 'wlan' with 'ether') I got我不确定 0888e 是否可以在 wlan proto 中引用任何内容,但是在做了与 op 几乎相同的事情之后(除了将 'wlan' 替换为 'ether'),我得到了

>>> EAP in b[0]
False

However when I enter但是当我进入

>>> EAPOL in b[0]
True

I believe OP captured what his code was looking for (2 EAPOL packets), but he didn't capture what he thought he was looking for - 2 EAP packets.我相信 OP 捕获了他的代码正在寻找的东西(2 个 EAPOL 数据包),但他没有捕获到他认为要寻找的东西 - 2 个 EAP 数据包。

Edit - Even when I replace ether with wlan I still come up with EAP as false and EAPOL as true.编辑 - 即使我用 wlan 替换以太,我仍然认为 EAP 为假,EAPOL 为真。

I think these are all partial answers, together it worked for me.我认为这些都是部分答案,一起对我有用。 I did:我做了:

conf.iface='wlan0.mon'
a=sniff(filter='ether proto 0x888e', prn=lambda x: x.summary(),
  count=100, store=1)

Then I generated an EAPOL exchange by manually disconnecting a device from the WPA network.然后我通过手动断开设备与 WPA 网络的连接来生成 EAPOL 交换。 When it tried to re-associated, I captured the 4-way EAPOL exchange.当它尝试重新关联时,我捕获了 4 路 EAPOL 交换。 Do a count>4 because there will likely be frame retransmissions.计数> 4,因为可能会有帧重传。 AFAIK, scapy does not decode the KEY data, so it is dumped as a hex string. AFAIK,scapy 不解码 KEY 数据,因此它被转储为十六进制字符串。

Are you are running tcpdump at same time as scapy sniff?您是否在 scapy sniff 的同时运行 tcpdump?

Scapy can emulate TCPDUMP just fine. Scapy 可以很好地模拟 TCPDUMP。 Just run them one at a time.一次只运行一个。

You could have several issues here, so let me address the one that I just came across today.这里可能有几个问题,所以让我来解决我今天刚刚遇到的一个问题。

First, as seen in the following bug report: http://trac.secdev.org/scapy/ticket/537 -- Scapy doesn't honor the iface parameter in the sniff function.首先,如以下错误报告所示: http ://trac.secdev.org/scapy/ticket/537 -- Scapy 不支持嗅探函数中的 iface 参数。 So to set the iface correctly, you'll have to use:因此,要正确设置 iface,您必须使用:

conf.iface = 'mon0'

Hopefully this will allow you to add the filter and actually get packets across the wire.希望这将允许您添加过滤器并实际通过网络获取数据包。

If you're sniffing on mon0, and it's a wireless interface, you might want to try wlan proto instead of ether proto, but I don't have a network to test EAP packets on to help further.如果您正在嗅探 mon0,并且它是一个无线接口,您可能想尝试使用 wlan proto 而不是 ether proto,但我没有网络来测试 EAP 数据包以提供进一步帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM