From d8f1c6f98932c3c27edb85d17211cc5f724da8f7 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 3 Jun 2009 11:14:54 -0600 Subject: [PATCH] Another TCP Resequencer fix --- __init__.py | 10 ++++++++-- ip.py | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index e821df5..1a7ebdf 100755 --- a/__init__.py +++ b/__init__.py @@ -213,9 +213,15 @@ def pp(value, bits=16): ## ## Codecs ## - import codecs -from __init__ import BitVector +import string + +b64alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' + +def from_b64(s, alphabet, codec='base64'): + tr = string.maketrans(alphabet, b64alpha) + t = s.translate(tr) + return t.decode(codec) class Esab64Codec(codecs.Codec): """Little-endian version of base64.""" diff --git a/ip.py b/ip.py index 3fc53a4..3197dfa 100755 --- a/ip.py +++ b/ip.py @@ -276,7 +276,8 @@ class TCP_Resequence: del pending[key] if frame.flags & (FIN | RST): seq += 1 - self.closed[idx] = True + if frame.flags & (FIN | ACK) == FIN | ACK: + self.closed[xdi] = True if self.closed == [True, True]: self.handle = self.handle_drop if seq != pkt.ack: @@ -288,8 +289,15 @@ class TCP_Resequence: def handle_drop(self, pkt): """Warn about any unhandled packets""" + if pkt.flags & SYN: + # Re-using ports! + self.__init__() + return self.handle(pkt) + if pkt.payload: warnings.warn('Spurious frame after shutdown: %r %d' % (pkt, pkt.flags)) + hexdump(pkt.payload) + merf class Dispatch: