You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling sniff() using an offline pcap file and also specifying a BPF filter can lead to an exception during validation of the filter as it appears the associated linktype may be guessed incorrectly under some conditions.
For example, providing a pcap with raw WiFi packets and using a filter of "subtype probe-req" to select only probe request frames should work, but the additional validation performed in compile_filter() before calling tcpdump with the filter raises an exception.
Environment
Scapy version: 2.4.4
Python version: 3.8.5
Operating System: Ubuntu 20.04
How to reproduce
capture a WiFi pcap using (for example) tshark, eg tshark -i wlan0 -w capture.pcap
using offline mode with a filter, scapy.sniff(offline="path/to/capture.pcap", filter="subtype probe-req", ...)
Internally it looks like compile_filter() makes some educated guesses about the linktype for the filter but if it gets the linktype wrong then the exception is raised. If sniff() is modified take a linktype that is then passed to tcpdump() that is then passed to compile_filter this exception could be avoided.
Thanks for the response! That PR to magically figure out the linktype from the pcap file looks much better than my suggestion which needs the user to supply the linktype.
Brief description
Calling
sniff()
using an offline pcap file and also specifying a BPF filter can lead to an exception during validation of the filter as it appears the associated linktype may be guessed incorrectly under some conditions.For example, providing a pcap with raw WiFi packets and using a filter of "subtype probe-req" to select only probe request frames should work, but the additional validation performed in
compile_filter()
before calling tcpdump with the filter raises an exception.Environment
How to reproduce
tshark -i wlan0 -w capture.pcap
scapy.sniff(offline="path/to/capture.pcap", filter="subtype probe-req", ...)
Actual result
Expected result
no exception
note: This exception isn't always raised, under some conditions it works, possibly the linktype is guessed correctly under some code paths.
Related resources
The
tcpdump
implementation in scapy/utils.py tries to validate the BPF filter before executing tcpdump by callingcompile_filter()
(see https://github.com/secdev/scapy/blob/master/scapy/utils.py#L2079)Internally it looks like
compile_filter()
makes some educated guesses about the linktype for the filter but if it gets the linktype wrong then the exception is raised. Ifsniff()
is modified take a linktype that is then passed totcpdump()
that is then passed tocompile_filter
this exception could be avoided.For example in sendrecv.py (AsyncSniff._run()):
and in utils.py (tcpdump):
sniff could be invoked with a known linktype, DLT_IEEE802_11 in this case:
The text was updated successfully, but these errors were encountered: