Forum Discussion
Intro to Python Scripting Building an IDS
I am stuck on task 5 of the lab and het this error:
from scapy.all import sniff
from scapy.layers.inet import IP, TCP
ip_connections = {}
PORT_SCAN_THRESHOLD = 10
def packet_callback(packet):
if packet.haslayer(IP) and packet.haslayer(TCP):
ip_src = packet[IP].src
port_dst = packet[TCP].dport
if ip_src not in ip_connections:
ip_connections[ip_src] = set()
ip_connections[ip_src].add(port_dst)
if len(ip_connections[ip_src]) > PORT_SCAN_THRESHOLD:
print(f"Alert! Possible port scan detected from IP: {ip_src}")
ip_connections[ip_src] = set()
sniff(prn=packet_callback, store=0)
Traceback (most recent call last):
File "/usr/lib/python3.12/idlelib/run.py", line 580, in runcode
exec(code, self.locals)
File "<pyshell#6>", line 1, in <module>
File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 1311, in sniff
sniffer._run(*args, **kwargs)
File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 1171, in _run
sniff_sockets[_RL2(iface)(type=ETH_P_ALL, iface=iface,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/scapy/arch/linux.py", line 484, in __init__
self.ins = socket.socket(
^^^^^^^^^^^^^^
File "/usr/lib/python3.12/socket.py", line 233, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted
2 Replies
- SamDickison
Community Manager
Hey account3448, hopefully one of our Community member can help. If not I'll see if our support team can give a hint.
- netcat
Advocate
Please use the icon with the label "{;}" to insert code, and I might take a look.