Skip to content

Commit

Permalink
Fix IPSession with no IP in packet
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Aug 3, 2023
1 parent b211487 commit e28c0a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scapy/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def __init__(self, *args, **kwargs):

def _ip_process_packet(self, packet):
# type: (Packet) -> Optional[Packet]
from scapy.layers.inet import _defrag_ip_pkt
from scapy.layers.inet import IP, _defrag_ip_pkt
if IP not in packet:
return packet
return _defrag_ip_pkt(packet, self.fragments)[1] # type: ignore

def on_packet_received(self, pkt):
Expand Down
6 changes: 6 additions & 0 deletions test/scapy/layers/inet.uts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ sniff(offline=tmp_file, session=IPSession, prn=callback)
assert len(dissected_packets) == 1
assert raw(dissected_packets[0]) == raw(packet)

= IPSession - contains non-IP packets

pkts = fragment(IP(dst="10.0.0.5")/ICMP()/("X"*1500))
pkts.insert(1, ARP())
assert len(sniff(offline=pkts, session=IPSession)) == 2

= StringBuffer

buffer = StringBuffer()
Expand Down

0 comments on commit e28c0a2

Please sign in to comment.