Skip to content

Commit

Permalink
When not in app mode, tcp_reassemble sub-packets
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Sep 6, 2024
1 parent 83e065a commit 4415376
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions scapy/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,20 @@ def process(self,
metadata.clear()
# Check for padding
padding = self._strip_padding(packet)
if padding:
while padding:
# There is remaining data for the next payload.
full_length = data.content_len - len(padding)
metadata["relative_seq"] = relative_seq + full_length
data.shiftleft(full_length)
# There might be a sub-payload hidden in the padding
sub_packet = tcp_reassemble(
bytes(data),
metadata,
tcp_session
)
if sub_packet:
packet /= sub_packet
padding = self._strip_padding(sub_packet)
else:
# No padding (data) left. Clear
data.clear()
Expand All @@ -397,10 +406,15 @@ def recv(self, sock: 'SuperSocket') -> Iterator[Packet]:
"""
pkt = sock.recv(stop_dissection_after=self.stop_dissection_after)
# Now handle TCP reassembly
while pkt is not None:
if self.app:
while pkt is not None:
pkt = self.process(pkt)
if pkt:
yield pkt
# keep calling process as there might be more
pkt = b"" # type: ignore
else:
pkt = self.process(pkt)
if pkt:
yield pkt
# keep calling process as there might be more
pkt = b"" # type: ignore
return None

0 comments on commit 4415376

Please sign in to comment.