Issue with scary.layers

Hi Zaid,

Love your Ethical Hacking courses. I’m running to this issue:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/scapy/packet.py", line 372, in __getattr__
    fld, v = self.getfield_and_val(attr)
TypeError: cannot unpack non-iterable NoneType object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/scapy/packet.py", line 372, in __getattr__
    fld, v = self.getfield_and_val(attr)
TypeError: cannot unpack non-iterable NoneType object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/software-security/packet_sniffer.py", line 12, in <module>
    sniff('eth0')
  File "/root/software-security/packet_sniffer.py", line 6, in sniff
    scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)
  File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 1036, in sniff
    sniffer._run(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 989, in _run
    session.on_packet_received(p)
  File "/usr/lib/python3/dist-packages/scapy/sessions.py", line 82, in on_packet_received
    result = self.prn(pkt)
  File "/root/software-security/packet_sniffer.py", line 9, in process_sniffed_packet
    if packet.hasLayer(http.HTTPRequest):
  File "/usr/lib/python3/dist-packages/scapy/packet.py", line 374, in __getattr__
    return self.payload.__getattr__(attr)
  File "/usr/lib/python3/dist-packages/scapy/packet.py", line 374, in __getattr__
    return self.payload.__getattr__(attr)
  File "/usr/lib/python3/dist-packages/scapy/packet.py", line 372, in __getattr__
    fld, v = self.getfield_and_val(attr)
  File "/usr/lib/python3/dist-packages/scapy/packet.py", line 1600, in getfield_and_val
    raise AttributeError(attr)
AttributeError: hasLayer

when running:

#!/usr/bin/env python
import scapy.all as scapy
from scapy.layers import http

def sniff(interface):
    scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)

def process_sniffed_packet(packet):
    if packet.hasLayer(http.HTTPRequest):
        print(packet.show())

sniff('eth0')

I tried to figure out what’s wrong but couldn’t, do you think it’s an issue with python version?

Regards,

Iliya

Not sure what the error is about. Try this in the prn instead of ``the other function:
prn=lambda x: x.summary()) and see if you get any error or not

No errors because the issue is caused by hasLayer()

Check the type of the packet that is received inside process_sniffed_packet function. Use type(packet) and print it out. Also just print packet to see what it outputs. I know that packet has the hasLayer function so unless packet is not None, it should be good. If packet is None then your sniff function didn’t return anything.