How to enable Python to craft packets and listen to ports less than 1024 without sudo

To be able to craft packets with Scapy, you have to either use sudo or allow setcap for your python environment. I don’t prefer to use sudo when working with my Anaconda environments, so I did the following:

sudo setcap 'cap_net_raw,cap_net_admin,cap_net_bind_service=eip' /home/ubuntu/anaconda3/envs/py311/bin/python3.11

Note: Using in the above example python instead of python3.11 won’t work, since python in that location is just a symbolic link, you have to specify the executable itself directly.

That’s it, now you can run your program without sudo!

Enjoy!

Unknown's avatar

About Ahmed Tawfik

Cybersecurity Professional, Systems Engineer, OSS & Linux Geek
This entry was posted in Linux and tagged , , . Bookmark the permalink.

Leave a comment