S
S
sudo_root2021-04-30 19:53:10
Python
sudo_root, 2021-04-30 19:53:10

Error while working with Debian Python scapy module?

Good afternoon, I created a simple sniffer on Debian but I can't run it.

from scapy.all import *
 
 
counter = 0
 
 
def analysis(pkt):
    global counter
    print(counter, ":  Ethernet")
    print("Src:", pkt["Ether"].src)
    print("Dst:", pkt["Ether"].dst)
    print(pkt.sprintf("Type: %Ether.type%"))
 
    if pkt["Ether"].type == 2054:     #ARP
        print("###ARP###")
        if pkt["ARP"].op == 1:
            print("echo-request")
        elif pkt["ARP"].op == 2:
            print("echo-reply")
 
    elif pkt["Ether"].type == 2048:   #IPv4
        print("###IPv4###")
        print("Src:", pkt["IP"].src)
        print("Dst:", pkt["IP"].dst)
        print("TTL:", pkt["IP"].ttl)
        print("High level protocol: ", pkt.sprintf("%IP.proto%"))    #udp 17
        print("Data size:", pkt["IP"].len-20)
        if pkt["IP"].proto == 17:
            print("     ###UDP###")
            print("     Src port:", pkt["UDP"].sport)
            print("     Dst port:", pkt["UDP"].dport)
            print("     Data size:", pkt["UDP"].len - 8)
 
    counter += 1
    print("---------------------------------------------------")
 
 
if __name__ == '__main__':
    ifaces = os.listdir('/sys/class/net/')
    sniff(iface=ifaces, prn=analysis)


When running in Pycharm, an error occurs (tried on python3.7 and 3.9:
home/danya/Python-3.9.1/python /home/danya/PycharmProjects/main.py
Traceback (most recent call last):
  File "/home/danya/PycharmProjects/main.py", line 40, in <module>
    sniff(iface=ifaces, prn=analysis)
  File "/home/danya/.local/lib/python3.9/site-packages/scapy/sendrecv.py", line 1263, in sniff
    sniffer._run(*args, **kwargs)
  File "/home/danya/.local/lib/python3.9/site-packages/scapy/sendrecv.py", line 1127, in _run
    sniff_sockets[L2socket(type=ETH_P_ALL, iface=iface,
  File "/home/danya/.local/lib/python3.9/site-packages/scapy/arch/linux.py", line 486, in init
    self.ins = socket.socket(
  File "/home/danya/Python-3.9.1/Lib/socket.py", line 232, in init
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted

Process finished with exit code 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-04-30
@sudo_root

Only root can "sniff".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question