-
Notifications
You must be signed in to change notification settings - Fork 14k
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
Use ldap_connect in place of ldap_new to trigger the bind early #18145
Conversation
@@ -86,7 +86,7 @@ def run_host(ip) | |||
entries_returned = 0 | |||
|
|||
print_status("#{peer} Connecting...") | |||
ldap_new do |ldap| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this now skips the monkey patching logic that was explicitly put in to catch some bind errors:
metasploit-framework/lib/msf/core/exploit/remote/ldap.rb
Lines 223 to 255 in dfbd14e
def ldap_new(opts = {}) | |
ldap = Net::LDAP.new(get_connect_opts.merge(opts)) | |
# NASTY, but required | |
# monkey patch ldap object in order to ignore bind errors | |
# Some servers (e.g. OpenLDAP) return result even after a bind | |
# has failed, e.g. with LDAP_INAPPROPRIATE_AUTH - anonymous bind disallowed. | |
# See: https://www.openldap.org/doc/admin23/security.html#Authentication%20Methods | |
# "Note that disabling the anonymous bind mechanism does not prevent anonymous | |
# access to the directory." | |
# Bug created for Net:LDAP at https://github.com/ruby-ldap/ruby-net-ldap/issues/375 | |
# | |
# @yieldparam conn [Net::LDAP] The LDAP connection handle to use for connecting to | |
# the target LDAP server. | |
# @param args [Hash] A hash containing options for the ldap connection | |
def ldap.use_connection(args) | |
if @open_connection | |
yield @open_connection | |
else | |
begin | |
conn = new_connection | |
conn.bind(args[:auth] || @auth) | |
# Commented out vs. original | |
# result = conn.bind(args[:auth] || @auth) | |
# return result unless result.result_code == Net::LDAP::ResultCodeSuccess | |
yield conn | |
ensure | |
conn.close if conn | |
end | |
end | |
end | |
yield ldap | |
end |
Is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I didn't spot that, not intentional no, I'll take another pass at this, would even just reverting this change and removing the if ldap.get_operation_result.code == 0
section be viable?
Happy to review this when ready but seems like this may need some revision. Going to await Dean's updates, then feel free to ping me when you'd like a review. |
Closing this for now, this doesn't seem like the right solution |
The auxiliary/gather/ldap_hashdump added in #13906 was using
ldap_new
instead ofldap_connect
this lead to the logic checking for a valid connection to always claim a connection was established sinceldap.get_operation_result.code
will always be 0 (indicating no errors) before connectingSimple fix to just replace
ldap_new
withldap_connect
Before
After
Verification Steps