invernizzi / scapy-http

Support for HTTP in Scapy
Other
301 stars 77 forks source link

haslayer() fails in for loop #29

Open Lcreager opened 6 years ago

Lcreager commented 6 years ago

When running haslayer('HTTP') over all packets in a for loop, I get the below:

for p in pkts:
    p.haslayer('HTTP')

Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "C:\Python27\lib\site-packages\scapy\packet.py", line 890, in haslayer
    return self.payload.haslayer(cls)
  File "C:\Python27\lib\site-packages\scapy\packet.py", line 890, in haslayer
    return self.payload.haslayer(cls)
  File "C:\Python27\lib\site-packages\scapy\packet.py", line 890, in haslayer
    return self.payload.haslayer(cls)
  File "C:\Python27\lib\site-packages\scapy\layers\ntp.py", line 217, in haslayer
    elif issubclass(cls, NTP):
TypeError: issubclass() arg 1 must be a class

Doing a similar command with a different layer is successful:

for p in pkts:
    p.haslayer(TCP)

I narrowed down the exact packets causing problems here:

i = 0
for p in pkts:
    i += 1
    try:
        p.haslayer('HTTP')
    except Exception as e:
        print(e)
        print(i)

issubclass() arg 1 must be a class
101
issubclass() arg 1 must be a class
109
issubclass() arg 1 must be a class
113
issubclass() arg 1 must be a class
116
issubclass() arg 1 must be a class
118
issubclass() arg 1 must be a class
119
issubclass() arg 1 must be a class
120
issubclass() arg 1 must be a class
121

It looks like NTP packets cause problems for some reason. I have attached a pcap with one of the packets which causes the error.

ntp.pcap.gz