-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ntlmrelayx: socket ssl wrapping error #581
Comments
One key difference I noticed between request made by ldap3 and by f.e. ldp.exe, is timestamp here and TLS version here: I've tried to investigate where this settings can be tuned, by modifying some aspects of this Class https://github.com/SecureAuthCorp/impacket/blob/master/impacket/examples/ntlmrelayx/clients/ldaprelayclient.py#L141 with no success. |
Good analysis! I can't reproduce it locally (maybe i'd have to play with which ciphers are accepted by the DC) but the TLS logic of LDAP3 is here: |
Can you check what the |
Hi, @dirkjanm! I see Any ideas about that? |
Also having this issue. I'm able to connect via ldp.exe over 636, however get a 104 reset from ntlmrelayx. Looking on the DC event log shows two relevant alerts:
My openssl library is 1.1.1a |
If anyone can look what ciphers the python client supports (in the Client Hello package) and what the server offers (in the Server Hello of the working ldp.exe) I can try to replicate it and maybe figure out if this is purely related to openssl or with how python interacts with it. |
So this is definitely just related to Kali. It works fine on Ubuntu 18 & 16.
|
That sounds like avahi messing up resolving for .local domains. |
@hausec , unfortunately for me with Ubuntu 18.04.2 situation is the same: |
If anyone could share a PCAP of this error and also include how a working connection (using for example |
I solved the problem, Because I forgot to open ladps over SSL. Enable LDAP over SSL (LDAPS) for Microsoft Active Directory servers Finally, I succeeded on Windows 2012 and Windows 7. |
The solution that was posted by @l3m0n also worked for me! It seems that the LDAP over SSL was not enabled/properly configured in the DC. |
Hi @asolino! Sorry for late answer! Unfortunately this does not apply to initial description, here is the case with some prod servers as well that run LDAPS successfully in field (which was confirmed with ldp.exe over SSL in initial post)... Still looks as case of TLS values problem in ntlmrelayx's Hello packet. Hope to find some time to dig further and tune ldap3 TLS time settings. Not sure when though. |
I am experiencing the same thing here I can confirm that it was working on impacket v0.19 , on the same DC |
I did some experimenting with this bug tonight. I get the same results as a lot of people in this thread: Error relaying to LDAPS on a brand new DC. @dirkjanm: In your lab, did you setup your DC to be a CA? If so, that might explain why it works in your lab but not others. I guess what I'm still unsure about is how I can join other servers to the domain without a working LDAPS server... Correct me if I'm wrong, but isn't LDAPS required to add computer accounts to the DC? |
Yes you do need to have a valid certificate to use LDAPS, which gets automatically added when you add the CA role to the DC. Otherwise LDAPS will not work and will immediately reset the connection (both with impacket and with ldp.exe). |
That makes sense. Wouldn't it then be possible to get ntlmrelayx to do the same thing? Using LDAP with integrity for the --add-computer switch? |
It is but the encryption key for this is derived from (I think) the encrypted session key which is encrypted based on the password during authentication, so you don't have this key if you're relaying. I'd have to look up the exact details. With LDAPs the encryption is done separate from the authentication so this isn't a problem when relaying, but it isn't always configured. |
EDIT solution here -> #581 (comment) I did a bit of debugging because I had the same error has everyone :
What I found is that the problem is not related to Let's check: Kali testing, I check if LDAPS is working:
Maybe related to openssl version installed in Kali ? openssl/openssl#9566 (comment) I've tested on my laptop with an older version of openssl =>
And this is where the magic happens =>
With an older version of openssl I can use the LDAPS service of my AD. How did I generate my certificate ? Well I've just use the Active Directory Certificates Services and click Next Next Next all the time without touching anything. Then I simply restart the AD and check if the certificat was on the Personal Certificat (local computer) Then using LDP.exe I was able to connect to the LDAPS service on port 636 But using Kali, I cannot connect to LDAPS with openssl v1.1.1d (sep 2019) but only with openssl 1.11.1 (sep 2018) Hope it helps ! :) EDIT Further debugging on Kali
But with option TLS1_1
Full ntlmrelay stacktrace:
EDIT AGAIN I remove the version 1.1.1d of openssl and install an old one : 1.1.1 (sep 2018) and everything is working fine on my side :) |
Great explanation @mpgn. I had the same issue and resolved it downgrading the version of OpenSSL from 1.1.1c (May 2019) to 1.1.1 (Sep 2018). |
How did you accomplish the downgrade without destroying all dependencies? I have same issue with ntlmrelayx (even after upgrade to version 3 of openssl) Soooo guys I think I know why the connection does not establish. In openssl > 1.1.1 the default setting for TLS was changed to TLSv1.2 in openssl.cnf. This is reproducable! open /etc/ssl/openssl.cnf That did work for me to get it running! |
Nice catch @Sateng ! looks better than downgrading openssl 💯 |
Man - I ran into this same thing on another project and it completely slipped my mind while troubleshooting this one! Thank you @Sateng ! |
Hello @asolino I think you can close this issue :) |
Is there a deleted comment here? I really was enjoying this thread and then the solution seems to be missing |
Hi @n00py! The solution is in the previous comment (modify the config file):
I think there was a username change... |
Hi!
I'm facing the issue when using relay for LDAPs traffic.
Whole exception with
-debug
flug:[-] Exception in HTTP request handler: ('unable to open socket', [(LDAPSocketOpenError('socket ssl wrapping error: [Errno 104] Connection reset by peer',), ('A.B.C.D', 636))]) [+] Traceback (most recent call last): File "build/bdist.linux-x86_64/egg/impacket/examples/ntlmrelayx/servers/httprelayserver.py", line 72, in handle_one_request SimpleHTTPServer.SimpleHTTPRequestHandler.handle_one_request(self) File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request method() File "build/bdist.linux-x86_64/egg/impacket/examples/ntlmrelayx/servers/httprelayserver.py", line 193, in do_GET if not self.do_ntlm_negotiate(token, proxy=proxy): File "build/bdist.linux-x86_64/egg/impacket/examples/ntlmrelayx/servers/httprelayserver.py", line 261, in do_ntlm_negotiate if not self.client.initConnection(): File "build/bdist.linux-x86_64/egg/impacket/examples/ntlmrelayx/clients/ldaprelayclient.py", line 144, in initConnection self.session.open(False) File "/usr/local/lib/python2.7/dist-packages/ldap3/strategy/sync.py", line 56, in open BaseStrategy.open(self, reset_usage, read_server_info) File "/usr/local/lib/python2.7/dist-packages/ldap3/strategy/base.py", line 147, in open raise LDAPSocketOpenError('unable to open socket', exception_history) LDAPSocketOpenError: ('unable to open socket', [(LDAPSocketOpenError('socket ssl wrapping error: [Errno 104] Connection reset by peer',), ('A.B.C.D', 636))])
System:
Same problem was slightly touched in #514, where @dirkjanm mentioned:
I have access to ~12 AD systems (2012 R2 and 2016), targeting any of them results into this error.
Connections using ldp.exe works well (along with many production calls to some of ADs):
LDAP signing not enabled:
Behavior is that LDAPs service RST connection just after TLS hello is received:
So this is not caused by ntlmrelayx not trusting LDAPs sertificate - it's about LDAPs refusing this TLS hello packet.
Any ideas?
The text was updated successfully, but these errors were encountered: