Closed stefan6419846 closed 9 months ago
When I try to connect to the share without the password, I get an NTLM error:
This is expected, the error message is a result of trying to authenticate without any credentials specified. The last fallback attempt of the spnego library is to check for the precence of the NTLM_USER_FILE
env var and the file it might be pointing to. While smbprotocol can theoretically work with guest authentication by providing any username and any password it's not exactly the same as anonymous auth without any password.
For the password-based share, something seems to be wrong about the signing:
This one is interesting, I'll have to try and set up a test environment to dig deeper. Looks like what is happening is the NTLM session negotiated with the Impacket server was not negotiated with signing support. Signing is mandatory with Negotiate auth with NTLM because it needs to use the signing context to generate the mechListMIC
in the final authentication token. Signing, and confidentiality, is also required in SMB after authentication to perform the signing and encryption respectively used by NTLM. What I would try is:
auth="ntlm"
to bypass the mechListMIC
settings to get the authentication workingrequire_signing=False
to disable the signing requirements the client will try to enforce after authenticationencrypt=False
but I don't believe it's requiredUnfortunately I don't think there is much we can do to avoid this, the server seems to only offer basic security support (no signing or encryption) so you need to go out of your way to opt out of that from the client side as it is the insecure path.
Thanks for the explanations. Setting auth_protocol='ntlm'
did not fail immediately any more, but gets stuck in an infinite loop in an attempt which looks like trying to setup the session:
[...]
INFO:smbprotocol.session:Sending SMB2_SESSION_SETUP request message
INFO:smbprotocol.session:Receiving SMB2_SESSION_SETUP response message
DEBUG:smbprotocol.transport:Socket recv() returned 4 bytes (total 4)
DEBUG:smbprotocol.transport:Socket recv(240) (total 240)
DEBUG:smbprotocol.transport:Socket recv() returned 240 bytes (total 240)
DEBUG:smbprotocol.transport:Socket recv(4) (total 4)
INFO:smbprotocol.session:More processing is required for SMB2_SESSION_SETUP
DEBUG:spnego._ntlm:NTLM step input: TlRMTVNTUAACAAAAEAAQADgAAAAHAoriqqqqqqqqqqoAAAAAAAAAAGAAYABIAAAA//////////94AEgATQBUAEQAQgBJAFYAAQAQAEEAVwB2AFAASQBJAEIAdwADABAAQQBXAHYAUABJAEkAQgB3AAIAEAB4AEgATQBUAEQAQgBJAFYABAAQAHgASABNAFQARABCAEkAVgAHAAgAANndrsZR2gEAAAAA
DEBUG:spnego._ntlm:NTLM step output: TlRMTVNTUAABAAAAN4II4gAAAAAoAAAAAAAAACgAAAAACgIAAAAADw==
INFO:smbprotocol.session:Sending SMB2_SESSION_SETUP request message
INFO:smbprotocol.session:Receiving SMB2_SESSION_SETUP response message
DEBUG:smbprotocol.transport:Socket recv() returned 4 bytes (total 4)
DEBUG:smbprotocol.transport:Socket recv(240) (total 240)
DEBUG:smbprotocol.transport:Socket recv() returned 240 bytes (total 240)
DEBUG:smbprotocol.transport:Socket recv(4) (total 4)
INFO:smbprotocol.session:More processing is required for SMB2_SESSION_SETUP
DEBUG:spnego._ntlm:NTLM step input: TlRMTVNTUAACAAAAEAAQADgAAAAHAoriqqqqqqqqqqoAAAAAAAAAAGAAYABIAAAA//////////94AEgATQBUAEQAQgBJAFYAAQAQAEEAVwB2AFAASQBJAEIAdwADABAAQQBXAHYAUABJAEkAQgB3AAIAEAB4AEgATQBUAEQAQgBJAFYABAAQAHgASABNAFQARABCAEkAVgAHAAgAANndrsZR2gEAAAAA
DEBUG:spnego._ntlm:NTLM step output: TlRMTVNTUAABAAAAN4II4gAAAAAoAAAAAAAAACgAAAAACgIAAAAADw==
INFO:smbprotocol.session:Sending SMB2_SESSION_SETUP request message
INFO:smbprotocol.session:Receiving SMB2_SESSION_SETUP response message
DEBUG:smbprotocol.transport:Socket recv() returned 4 bytes (total 4)
DEBUG:smbprotocol.transport:Socket recv(240) (total 240)
DEBUG:smbprotocol.transport:Socket recv() returned 240 bytes (total 240)
DEBUG:smbprotocol.transport:Socket recv(4) (total 4)
INFO:smbprotocol.session:More processing is required for SMB2_SESSION_SETUP
DEBUG:spnego._ntlm:NTLM step input: TlRMTVNTUAACAAAAEAAQADgAAAAHAoriqqqqqqqqqqoAAAAAAAAAAGAAYABIAAAA//////////94AEgATQBUAEQAQgBJAFYAAQAQAEEAVwB2AFAASQBJAEIAdwADABAAQQBXAHYAUABJAEkAQgB3AAIAEAB4AEgATQBUAEQAQgBJAFYABAAQAHgASABNAFQARABCAEkAVgAHAAgAANndrsZR2gEAAAAA
DEBUG:spnego._ntlm:NTLM step output: TlRMTVNTUAABAAAAN4II4gAAAAAoAAAAAAAAACgAAAAACgIAAAAADw==
INFO:smbprotocol.session:Sending SMB2_SESSION_SETUP request message
INFO:smbprotocol.session:Receiving SMB2_SESSION_SETUP response message
DEBUG:smbprotocol.transport:Socket recv() returned 4 bytes (total 4)
DEBUG:smbprotocol.transport:Socket recv(240) (total 240)
DEBUG:smbprotocol.transport:Socket recv() returned 240 bytes (total 240)
DEBUG:smbprotocol.transport:Socket recv(4) (total 4)
INFO:smbprotocol.session:More processing is required for SMB2_SESSION_SETUP
DEBUG:spnego._ntlm:NTLM step input: TlRMTVNTUAACAAAAEAAQADgAAAAHAoriqqqqqqqqqqoAAAAAAAAAAGAAYABIAAAA//////////94AEgATQBUAEQAQgBJAFYAAQAQAEEAVwB2AFAASQBJAEIAdwADABAAQQBXAHYAUABJAEkAQgB3AAIAEAB4AEgATQBUAEQAQgBJAFYABAAQAHgASABNAFQARABCAEkAVgAHAAgAANndrsZR2gEAAAAA
DEBUG:spnego._ntlm:NTLM step output: TlRMTVNTUAABAAAAN4II4gAAAAAoAAAAAAAAACgAAAAACgIAAAAADw==
INFO:smbprotocol.session:Sending SMB2_SESSION_SETUP request message
^CTraceback (most recent call last):
File "/home/stefan/tmp/impacket/connect.py", line 7, in <module>
smbclient.register_session('127.0.0.1', username='abc', password='def', port=43794, auth_protocol='ntlm') # , encrypt=False, require_signing=False)
File "/home/stefan/tmp/impacket/venv/lib/python3.10/site-packages/smbclient/_pool.py", line 422, in register_session
session.connect()
File "/home/stefan/tmp/impacket/venv/lib/python3.10/site-packages/smbprotocol/session.py", line 295, in connect
request = self.connection.send(session_setup, sid=self.session_id, credit_request=64)
File "/home/stefan/tmp/impacket/venv/lib/python3.10/site-packages/smbprotocol/connection.py", line 967, in send
return self._send(
File "/home/stefan/tmp/impacket/venv/lib/python3.10/site-packages/smbprotocol/connection.py", line 1268, in _send
b_header = header.pack() + padding
File "/home/stefan/tmp/impacket/venv/lib/python3.10/site-packages/smbprotocol/structure.py", line 113, in pack
field_data = field.pack()
File "/home/stefan/tmp/impacket/venv/lib/python3.10/site-packages/smbprotocol/structure.py", line 175, in pack
value = self._get_calculated_value(self.value)
File "/home/stefan/tmp/impacket/venv/lib/python3.10/site-packages/smbprotocol/structure.py", line 265, in _get_calculated_value
def _get_calculated_value(self, value):
KeyboardInterrupt
INFO:smbprotocol.connection:Disconnecting transport connection
INFO:smbprotocol.transport:Disconnecting DirectTcp socket
DEBUG:smbprotocol.transport:Socket recv() returned 0 bytes (total 4)
Ok I see what is happening, the SMB server is set to return a response buffer on a successful response as per
This is not expected for NTLM normally where the server doesn't response with a token but because our loop continues to run if there is input it just loops back to the first message exchange
I believe we should be only continuing the loop when the context isn't complete but I'll need to verify that is still the case for other authentication types.
Even when manually patching that there are all sorts of errors when it comes to signature verification. Having it enabled results in a signature mismatch and having it disabled results in another strange error about a missing session which I was not expecting. Ultimately it seems like the impacket SMB 2 server is quite experimental. I can fix the bad looping mechanism in my code but they should look at fixing up the signature problems that don't occur on other SMB servers.
Thanks for the explanations. impacket marks support for SMBv2 and SMBv3 as experimental, but generally considers it usable. It seems like the only short-term conclusion is that it means too much hassle to fix the recent SMB protocol versions within impacket.
I will leave this issue open for you to complete analysis on the infinite loop with "bad" server-side behavior.
Thanks for your understanding, I've merged https://github.com/jborean93/smbprotocol/pull/267 which removes the endless loop issue. While it won't fix the impacket server interoperability it at least won't hang indefinitely.
I am currently trying to use your package to connect to a SMB share. While it works with a real server, it seems like my testing setup breaks something (or I am using something wrong).
My testing setup involves https://github.com/fortra/impacket/blob/master/examples/smbserver.py, a dummy server. For my tests, I use two different commands:
python smbserver.py testshare my_directory/ -debug -port 43793 -smb2support
andpython smbserver.py testshare my_directory/ -debug -port 43794 -smb2support -username abc -password def
, id est a share on port 43793 without credentials and a share with credentials on port 43794.Let's take the following script and try to run it:
I would expect this to run without issues, but it fails for both test shares.
When I try to connect to the share without the password, I get an NTLM error:
For the password-based share, something seems to be wrong about the signing:
Am I doing something wrong here or is this an issue with the server-side implementation of
impacket
? The same approach works correctly when using a "real" server, but I would like to avoid this for testing purposes if possible.