Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request: Non-Root Fallback Backend for Scapy
Overview
This PR introduces a non-root fallback backend for Scapy, allowing basic
sendandsnifffunctionality on systems without root privileges.Currently, Scapy requires raw sockets for full L3 access, which fails on non-root environments. This PR provides:
NonRootL3Socket: a UDP-based emulation of L3 send/receive.sniff_nonroot(): non-root compatible packet capture.sudousage: full functionality works if root privileges are present.This enables Scapy to work in restricted environments, such as:
sudo.Implementation Details
scapy/arch/linux/nonroot_backend.pyscapy/all.pytests/test_nonroot.pyKey Features:
NonRootL3Socket
.send(pkt)and.recv(timeout)methods compatible with Scapy.Non-root Sniffer
sniff_nonroot()provides a drop-in alternative forsniff()in non-root mode.count,timeout, and debug logging.Automatic Hook
enable_nonroot_backend()automatically sets Scapy’sconf.L3sockettoNonRootL3Socketif root is not detected.os.geteuid()when available to detect root privileges.Graceful Fallback
Usage Example
Expected Output (non-root mode):
Testing Instructions
nonroot-backendbranch.127.0.0.1.sudo) to confirm full Scapy functionality.Benefits
Notes for Reviewers
send,recv,sniff) mimic standard Scapy behavior wherever possible.