Skip to content

Commit d532afd

Browse files
authored
Merge pull request #2028 from gpotter2/monitorlinux
Monitor mode docs
2 parents c0c334a + af44ec1 commit d532afd

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

doc/scapy/troubleshooting.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ Troubleshooting
55
FAQ
66
===
77

8+
I can't sniff/inject packets in monitor mode.
9+
---------------------------------------------
10+
11+
The use monitor mode varies greatly depending on the platform.
12+
13+
- **Windows/OSX - ``conf.use_pcap = True``**
14+
The pcap providers must be called differently by Scapy in order for them to create the sockets in monitor mode. You will need to pass the ``monitor=True`` to any calls that open a socket on their own (``send``, ``sniff``...) or to a Scapy socket that you create yourself (``conf.L2Socket``...)
15+
- **Linux native (with pcap disabled):**
16+
You should set the interface in monitor mode on your own. Scapy provides utilitary functions: ``set_iface_monitor`` and ``get_iface_mode`` (linux only), that may be used (they do system calls to ``iwconfig`` and will restart the adapter).
17+
18+
Note that many adapters do not support monitor mode, especially on Windows, or may incorrectly report the headers. See `the Wireshark doc about this <https://wiki.wireshark.org/CaptureSetup/WLAN>`_
19+
20+
We make our best to make this work, if your adapter works with Wireshark for instance, but not with Scapy, feel free to report an issue.
21+
822
My TCP connections are reset by Scapy or by my kernel.
923
------------------------------------------------------
1024
The kernel is not aware of what Scapy is doing behind his back. If Scapy sends a SYN, the target replies with a SYN-ACK and your kernel sees it, it will reply with a RST. To prevent this, use local firewall rules (e.g. NetFilter for Linux). Scapy does not mind about local firewalls.

doc/scapy/usage.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,14 +1120,17 @@ Wireless frame injection
11201120
.. index::
11211121
single: FakeAP, Dot11, wireless, WLAN
11221122

1123+
.. note::
1124+
See the TroubleShooting section for more information on the usage of Monitor mode among Scapy.
1125+
11231126
Provided that your wireless card and driver are correctly configured for frame injection
11241127

11251128
::
11261129

11271130
$ iw dev wlan0 interface add mon0 type monitor
11281131
$ ifconfig mon0 up
11291132

1130-
On Windows, if using Npcap, the equivalent would be to call
1133+
On Windows, if using Npcap, the equivalent would be to call::
11311134

11321135
>>> # Of course, conf.iface can be replaced by any interfaces accessed through IFACES
11331136
... conf.iface.setmonitor(True)

scapy/arch/linux.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,13 @@ def _check_call(commands):
422422
warning("%s failed !" % " ".join(commands))
423423
return False
424424
return True
425-
try:
426-
assert _check_call(["ifconfig", iface, "down"])
427-
assert _check_call(["iwconfig", iface, "mode", s_mode])
428-
assert _check_call(["ifconfig", iface, "up"])
429-
return True
430-
except AssertionError:
425+
if not _check_call(["ifconfig", iface, "down"]):
426+
return False
427+
if not _check_call(["iwconfig", iface, "mode", s_mode]):
431428
return False
429+
if not _check_call(["ifconfig", iface, "up"]):
430+
return False
431+
return True
432432

433433

434434
class L2Socket(SuperSocket):
@@ -440,8 +440,10 @@ def __init__(self, iface=None, type=ETH_P_ALL, promisc=None, filter=None,
440440
self.type = type
441441
self.promisc = conf.sniff_promisc if promisc is None else promisc
442442
if monitor is not None:
443-
if not set_iface_monitor(iface, monitor):
444-
warning("Could not change interface mode !")
443+
warning(
444+
"The monitor argument is ineffective on native linux sockets."
445+
" Use set_iface_monitor instead."
446+
)
445447
self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type)) # noqa: E501
446448
self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)
447449
if not nofilter:

0 commit comments

Comments
 (0)