I am using scapy to send a packet. which works fine in command line under the code.
send(IP(dst="www.google.com")/ICMP())
But when I try to send it inside shell it throws an error. The code I am using is
from scapy.all import *
packet=send(IP(dst="www.google.com")/ICMP())
It throws an error
Traceback (most recent call last):
File "/home/pi/111.py", line 2, in <module>
packet=send(IP(dst="www.google.com")/ICMP())
File "/usr/local/lib/python2.7/dist-packages/scapy/sendrecv.py", line 268, in send
return __gen_send(conf.L3socket(*args, **kargs), x, inter=inter, loop=loop, count=count,verbose=verbose,
File "/usr/local/lib/python2.7/dist-packages/scapy/arch/linux.py", line 324, in __init__
self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
File "/usr/lib/python2.7/socket.py", line 187, in __init__
_sock = _realsocket(family, type, proto)
error: [Errno 1] Operation not permitted
But when I use sudo python 'file_name.py'
in command line it works fine. Previously this command was not working as well untill I set RAW Scokets in shell using sudo setcap -v cap_net)raw+eip/usr/bin/python2.7
In my opinion this issue is related to RAW sockets which scapy uses to send the packet and it needs sudo privileges. But I don't know how to fix it for shell or script which I can run in shell not in command line. Your feedback in easy explanation is expected as I am newbie to all this.
1 Answer 1
I think need to run it with admin privileges (sudo
).
also...
https://stackoverflow.com/questions/22421290/scapy-operation-not-permitted-when-sending-packets
-
1It would be nice to see a summary of the information contained in the link featured in your answer...2017年06月02日 11:14:00 +00:00Commented Jun 2, 2017 at 11:14
-
That link was the first google result for '_sock = _realsocket(family, type, proto)'. But it's on stack overflow, so I didn't want to flag this as a duplicate.Chris– Chris2017年06月02日 13:40:41 +00:00Commented Jun 2, 2017 at 13:40
-
I can run the script using 'sudo' in command line interface but unable to run it within the python shell. so basically I don't know how to give admin rights to python script while running it inside python shell. Of course I can use "sudo fileName.py" in CLI but can't do it inside shell.Kashif Ahmad– Kashif Ahmad2017年06月20日 12:46:04 +00:00Commented Jun 20, 2017 at 12:46