Skip to content

Fix Scapy 2.5+ and Python 3.10+ compatibility#61

Open
threadpoolx wants to merge 4 commits into
vanhoefm:masterfrom
threadpoolx:master
Open

Fix Scapy 2.5+ and Python 3.10+ compatibility#61
threadpoolx wants to merge 4 commits into
vanhoefm:masterfrom
threadpoolx:master

Conversation

@threadpoolx

@threadpoolx threadpoolx commented Jul 5, 2026

Copy link
Copy Markdown

Fixes #59. Addresses driver crash in #60.

Changes

Scapy 2.5+ import fixes (libwifi/wifi.py, fraginternals.py)

  • L2Socket and attach_filter no longer in scapy.all wildcard — explicit import from scapy.arch
  • scapy.contrib.wpa_eapol.WPA_key removed — fall back to scapy.layers.eap.EAPOL_KEY; reconstruct key_info from individual bit fields
  • scapy.arch.get_if_raw_hwaddr removed — SIOCGIFHWADDR ioctl fallback
  • scapy.arch.get_if_index removed — SIOCGIFINDEX ioctl monkey-patched back

Python 3.12+ fixes

  • Raw strings for regex patterns (\d, \w SyntaxWarning)
  • get_ccmp_payload: str(bytes)bytes() (Python 2 leftover)
  • create_msdu_subframe: padding ""b""

Issue #60 mitigation (fraginternals.py)

  • 0.5s sleep after virtual monitor interface creation (prevents mt76 null-ptr dereference)
  • Clear error message + --inject hint if creation fails

requirements.txt / pysetup.sh

  • Drop Python 3.7-only packages, loosen pins to >=, require scapy>=2.5.0
  • Guard BPF sed patch for newer scapy

Tested: test-injection.py passes all checks on ath9k_htc with Scapy 2.7 + Python 3.13.

threadpoolx and others added 4 commits July 5, 2026 20:43
Scapy 2.5.0 removed L2Socket, attach_filter, and get_if_raw_hwaddr from
its wildcard export and moved scapy.arch.common.get_if_raw_hwaddr; add
explicit imports so the tool works on current Kali/Debian installs.

- libwifi/wifi.py: import L2Socket and attach_filter from scapy.arch;
  wrap _rt_txflags mutation in try/except for forward compatibility;
  fix get_ccmp_payload str->bytes (Python 3 correctness); fix
  create_msdu_subframe padding initialised as str instead of bytes;
  use raw strings for regex patterns (SyntaxWarning in Python 3.12+)
- fraginternals.py: fallback import for get_if_raw_hwaddr; add 0.5s
  sleep + clear error message after virtual monitor interface creation
  to mitigate mt76 null-pointer dereference (issue vanhoefm#60); raw string
  for regex
- requirements.txt: replace 2020-era exact pins with >= minimums,
  drop Python 3.7-only packages (importlib-metadata, zipp, py),
  require scapy>=2.5.0
- pysetup.sh: guard BPF sed patch so it doesn't fail when file absent
- fragattack.py: suppress DeprecationWarnings from scapy.layers.ipsec

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…w_hwaddr)

Three more Scapy APIs removed in 2.5–2.7 that cause ImportError or
AttributeError at startup on current Kali installs:

- scapy.contrib.wpa_eapol.WPA_key removed: fall back to
  scapy.layers.eap.EAPOL_KEY and reconstruct the key_info integer from
  its individual bit fields via _eapol_key_info()
- scapy.arch.get_if_index removed: monkey-patch it back onto scapy.arch
  using SIOCGIFINDEX ioctl so configure_interfaces() can check whether
  the virtual monitor interface already exists
- scapy.arch.get_if_raw_hwaddr removed: fall back to SIOCGIFHWADDR ioctl
  in both fraginternals.py and libwifi/wifi.py

Tested: test-injection.py passes all checks on ath9k_htc with Scapy 2.7
and Python 3.13; fragattack.py --help and startup run cleanly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
OSSL_PROVIDER_try_load() is used under #if OPENSSL_VERSION_NUMBER >= 0x30000000L
but <openssl/provider.h> was never included, causing an implicit-function-declaration
error on OpenSSL 3.0+ (tested on 3.6.3). Add the include under the same guard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
EapolAmsduTest.__init__ enforces exactly 1 inject action but fragattack.py
was passing 2 by default, causing an immediate quit(1) on every invocation
of eapol-amsdu and eapol-amsdu-bad without custom --actions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vanhoefm

vanhoefm commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Thanks for taking the time to work towards updated Python compatibility! I've found that in the past, the behaviour of Scapy can subtly change between versions, so the code doesn't crash but might no longer send the same frames. For this reason, I'm hesitant to move to a different Scapy version, and also a new Python version, without quite detailed testing to ensure everything still works the same.

To solve some of the Python dependencies, in the short term, switching to uv is best (instead of the virtualenv currently). That should allow the use of the older Python and Scapy versions that were extensively tested. Long term, a new branch can be created to move to a new Python version, but I doubt I will have the time to maintain that.

Code issues and updates different from updating the Scapy and Python versions are something I can more easily adopt in the main branch, e.g., the 0.5s delay to prevent one of the crashes.

@threadpoolx

Copy link
Copy Markdown
Author

Okay, that makes complete sense. Let's begin with just fixing the 0.5s delay. I would gladly contribute to a new branch for the Python and Scapy fixes if you decide to set one up. As a long-time user of your tool, I've had to rely on the live OS method rather than a generic clone, so I'd love to help get those updates sorted out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModuleNotFoundError: No module named scapy.modules.six.moves

2 participants