Permissions and working with raw sockets using pycharm
The problem is that raw_sockets require root privileges to initiate. This is not good and creates a lot of fuzz when you do runs on pycharm, you need to go terminal execute the code using sudo and stopping it creates a lot of additional fuzz if you are using threads or processes libraries. And this solution is only for developers that uses linux environments
To overcome this problem;
You can setcap the interpreter but you must be carefull because this is dangerous. After this point all the code you run with this feture will be commited with root privileges so if you are doing packet generation or some crazy stuff you might create network problems. Watch it !!!
sudo setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/bin/python3.10
Or run with sudo in pycharm, use the script below as your interpreter.
There is a catch, you should also require to be a nopassword user in your sudoers config.
-
Get your user name in to sudoers
sudo echo "your_user_name ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/your_user_name
-
Change your pycharm config to use the python-sudo
Copy this and don't forget to change the "home/rammses/PycharmProjects/mikrohelper" section before creating the python-sudo.sh file
#!/bin/bash sudo /home/rammses/PycharmProjects/mikrohelper/venv/bin/python "$@"
- put it into venv/bin folder
- name it python-sudo.sh
- set it executable chmod +x ./python-sudo.sh
- set your project interpreter as shown below
No Comments