secdev / secdev/scapy

CLI fails when running under static Python build (no ctypes)

Open
#4,951 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
12.6k
Forks
2.2k
Avg merge
1d 4h
Merged PRs (30d)
56

Description

Brief description

When running with static Python build (in my setup it's pkgsStatic.python314 package from nixpkgs), scapy CLI fails. it happens because ctypes are not available, and scapy.all import pulls modules that eagerly load .so libraries.

I think it would be better if CLI can start in this environment, even if in degraded mode (some functionality not available).

Scapy version

2.7.0

Python version

3.14

Operating system

Linux 6.18.16; NixOS unstable

Additional environment information

No response

How to reproduce

Run scapy using static Python build. I only know how to get a static Python build using Nix...


In Nix environment, it's: nix run .#pkgsStatic.python313Packages.scapy

Note: at the moment, the command requires this nixpkgs patch: https://github.com/NixOS/nixpkgs/pull/502064

Actual result
$ ./result/bin/scapy
INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
Traceback (most recent call last):
  File "/nix/store/jwyqphmzah1dxpxvca2l90525bfvbjmx-python3.14-scapy-2.7.0-x86_64-unknown-linux-musl/bin/.scapy-wrapped", line 9, in <module>
    sys.exit(interact())
             ~~~~~~~~^^
  File "/nix/store/jwyqphmzah1dxpxvca2l90525bfvbjmx-python3.14-scapy-2.7.0-x86_64-unknown-linux-musl/lib/python3.14/site-packages/scapy/main.py", line 711, in interact
    SESSION = init_session(mydict=mydict, ret=True)
  File "/nix/store/jwyqphmzah1dxpxvca2l90525bfvbjmx-python3.14-scapy-2.7.0-x86_64-unknown-linux-musl/lib/python3.14/site-packages/scapy/main.py", line 517, in init_session
    scapy_builtins = _scapy_builtins()
  File "/nix/store/jwyqphmzah1dxpxvca2l90525bfvbjmx-python3.14-scapy-2.7.0-x86_64-unknown-linux-musl/lib/python3.14/site-packages/scapy/main.py", line 473, in _scapy_builtins
    for k, v in importlib.import_module(".all", "scapy").__dict__.copy().items()
                ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/nix/store/pz96bx1swwkv32yy2flpxg8sdcj707q1-python3-static-x86_64-unknown-linux-musl-3.14.3/lib/python3.14/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1398, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1371, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1342, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 938, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 759, in exec_module
  File "<frozen importlib._bootstrap>", line 491, in _call_with_frames_removed
  File "/nix/store/jwyqphmzah1dxpxvca2l90525bfvbjmx-python3.14-scapy-2.7.0-x86_64-unknown-linux-musl/lib/python3.14/site-packages/scapy/all.py", line 16, in <module>
    from scapy.arch import *
  File "/nix/store/jwyqphmzah1dxpxvca2l90525bfvbjmx-python3.14-scapy-2.7.0-x86_64-unknown-linux-musl/lib/python3.14/site-packages/scapy/arch/__init__.py", line 28, in <module>
    from scapy.libs.extcap import load_extcap
  File "/nix/store/jwyqphmzah1dxpxvca2l90525bfvbjmx-python3.14-scapy-2.7.0-x86_64-unknown-linux-musl/lib/python3.14/site-packages/scapy/libs/extcap.py", line 28, in <module>
    from scapy.supersocket import SuperSocket
  File "/nix/store/jwyqphmzah1dxpxvca2l90525bfvbjmx-python3.14-scapy-2.7.0-x86_64-unknown-linux-musl/lib/python3.14/site-packages/scapy/supersocket.py", line 11, in <module>
    import ctypes
  File "/nix/store/pz96bx1swwkv32yy2flpxg8sdcj707q1-python3-static-x86_64-unknown-linux-musl-3.14.3/lib/python3.14/ctypes/__init__.py", line 565, in <module>
    pythonapi = PyDLL(None)
  File "/nix/store/pz96bx1swwkv32yy2flpxg8sdcj707q1-python3-static-x86_64-unknown-linux-musl-3.14.3/lib/python3.14/ctypes/__init__.py", line 433, in __init__
    self._handle = self._load_library(name, mode, handle, winmode)
                   ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/pz96bx1swwkv32yy2flpxg8sdcj707q1-python3-static-x86_64-unknown-linux-musl-3.14.3/lib/python3.14/ctypes/__init__.py", line 473, in _load_library
    return _dlopen(name, mode)
OSError: Dynamic loading not supported
Expected result

CLI starts and gives access to some / most scapy functionality that doesn't depend on dynamic library loading.

Related resources

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with nix run .#pkgsStatic.python313Packages.scapy, then trace the import path through scapy/main.py, scapy/all.py, scapy/arch/__init__.py, scapy/libs/extcap.py, and scapy/supersocket.py. The issue is done when the CLI starts under a static Python build and still exposes functionality that does not require dynamic library loading.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.