fortra / impacket

Impacket is a collection of Python classes for working with network protocols.
https://www.coresecurity.com
Other
13.58k stars 3.59k forks source link

Python3.13 error: impacket.nmb.NetBIOSTimeout: The NETBIOS connection with the remote host timed out. #1824

Open eamanu opened 1 month ago

eamanu commented 1 month ago

Configuration

impacket version: HEAD Python version:
Target OS: Debian sid

During the test execution we have this kind of errors:

 SimpleSMBServerFuncTests.test_smbserver_connect_disconnect_tree ________________________________________________________________________________________________________

self = <impacket.nmb.NetBIOSTCPSession object at 0x7f9149e7b0e0>, read_length = 4, timeout = 60

    def non_polling_read(self, read_length, timeout):
        data = b''
        if timeout is None:
            timeout = 3600

        start_time = time.time()
        bytes_left = read_length

        while bytes_left > 0:
            self._sock.settimeout(timeout)
            try:
>               received = self._sock.recv(bytes_left)
E               TimeoutError: timed out

impacket/nmb.py:986: TimeoutError

During handling of the above exception, another exception occurred:

self = <tests.SMB_RPC.test_smbserver.SimpleSMBServerFuncTests testMethod=test_smbserver_connect_disconnect_tree>

    def test_smbserver_connect_disconnect_tree(self):
        """Test connecting/disconnecting to a share tree.
        """
        server = self.get_smbserver()
        self.start_smbserver(server)

>       client = self.get_smbclient()

tests/SMB_RPC/test_smbserver.py:327: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/SMB_RPC/test_smbserver.py:227: in get_smbclient
    smbclient = SMBConnection(self.address, self.address, sess_port=int(self.port),
impacket/smbconnection.py:82: in __init__
    self.negotiateSession(preferredDialect)
impacket/smbconnection.py:122: in negotiateSession
    packet = self.negotiateSessionWildcard(self._myName, self._remoteName, self._remoteHost, self._sess_port,
impacket/smbconnection.py:182: in negotiateSessionWildcard
    resp = self._nmbSession.recv_packet(timeout)
impacket/nmb.py:917: in recv_packet
    data = self.__read(timeout)
impacket/nmb.py:1004: in __read
    data = self.read_function(4, timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <impacket.nmb.NetBIOSTCPSession object at 0x7f9149e7b0e0>, read_length = 4, timeout = 60

    def non_polling_read(self, read_length, timeout):
        data = b''
        if timeout is None:
            timeout = 3600

        start_time = time.time()
        bytes_left = read_length

        while bytes_left > 0:
            self._sock.settimeout(timeout)
            try:
                received = self._sock.recv(bytes_left)
            except socket.timeout:
>               raise NetBIOSTimeout
E               impacket.nmb.NetBIOSTimeout: The NETBIOS connection with the remote host timed out.

impacket/nmb.py:988: NetBIOSTimeout
----------------------------------------------------------------------------------------------------------------------------- Captured stderr call -----------------------------------------------------------------------------------------------------------------------------
Process Process-1:
Traceback (most recent call last):
  File "/usr/lib/python3.13/multiprocessing/process.py", line 313, in _bootstrap
    self.run()
    ~~~~~~~~^^
  File "/usr/lib/python3.13/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eamanu/Debian/impacket/upstream/impacket/impacket/smbserver.py", line 4909, in start
    self.__srvsServer.start()
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/threading.py", line 973, in start
    _start_joinable_thread(self._bootstrap, handle=self._handle,
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                           daemon=self.daemon)
                           ^^^^^^^^^^^^^^^^^^^
RuntimeError: thread already started
=========================================================================================================================== short test summary info ============================================================================================================================
FAILED tests/SMB_RPC/test_smbserver.py::SimpleSMBServerFuncTests::test_smbserver_connect_disconnect_tree - impacket.nmb.NetBIOSTimeout: The NETBIOS connection with the remote host timed out.

To reproduce it I run:

tox -e py3.13 -- tests/SMB_RPC/test_smbserver.py

I tried to figure out the issue but I couldn't.

Original reported here [0]

[0] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1082142

anadrianmanrique commented 1 month ago

Hello, thanks for reporting! We are not supporting offically 3.13 at the moment. Anyway, we plan to do it in the short term, so this report it's useful. We will keep you updated as soon as we can get more details about the issue. Thanks!

eamanu commented 1 week ago

Hi @anadrianmanrique,

Thanks for the response. I will patch out these tests to avoid break the Py3.13 transition.

I will keep my eyes here to avoid ignore this issue.

cheers!