File: test_TCP_bug_issue7.py

package info (click to toggle)
impacket 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,264 kB
  • sloc: python: 137,329; makefile: 10; sh: 3
file content (48 lines) | stat: -rwxr-xr-x 1,589 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# Impacket - Collection of Python classes for working with network protocols.
#
# Copyright Fortra, LLC and its affiliated companies 
#
# All rights reserved.
#
# This software is provided under a slightly modified version
# of the Apache Software License. See the accompanying LICENSE file
# for more information.
#
import unittest
from threading import Thread
from impacket.ImpactPacket import TCP, ImpactPacketException


class TestTCP(unittest.TestCase):

    def setUp(self):
        # Dummy TCP header with "Maximum Segment Size" Option and zero length
        self.frame = '\x12\x34\x00\x50\x00\x00\x00\x01\x00\x00\x00\x00\x60\x00\x00\x00\x8d\x5c\x00\x00\x02\x00\x00\x00'
        
    def test_01(self):
        'Test TCP options parsing hangs'
        class it_hangs(Thread):
            def __init__(self):
                Thread.__init__(self)
            def run(self):
                try:
                    frame = '\x12\x34\x00\x50\x00\x00\x00\x01\x00\x00\x00\x00' \
                        '\x60\x00\x00\x00\x8d\x5c\x00\x00\x02\x00\x00\x00'
                    TCP(frame)
                except ImpactPacketException as e:
                    if str(e) != "'TCP Option length is too low'":
                        raise e
                except Exception:
                    pass

        thread_hangs = it_hangs()
        thread_hangs.daemon = True
        thread_hangs.start()

        thread_hangs.join(1.0)  # 1 seconds timeout
        self.assertEqual(thread_hangs.is_alive(), False)


if __name__ == '__main__':
    unittest.main(verbosity=1)