@@ -12,7 +12,6 @@ module Exploit::Remote::LDAP
12
12
include Msf ::Exploit ::Remote ::Kerberos ::Ticket ::Storage
13
13
include Msf ::Exploit ::Remote ::Kerberos ::ServiceAuthenticator ::Options
14
14
include Metasploit ::Framework ::LDAP ::Client
15
- include Msf ::OptionalSession ::LDAP
16
15
17
16
# Initialize the LDAP client and set up the LDAP specific datastore
18
17
# options to allow the client to perform authentication and timeout
@@ -28,6 +27,8 @@ def initialize(info = {})
28
27
super
29
28
30
29
register_options ( [
30
+ Opt ::RHOST ,
31
+ Opt ::RPORT ( 389 ) ,
31
32
OptBool . new ( 'SSL' , [ false , 'Enable SSL on the LDAP connection' , false ] ) ,
32
33
Msf ::OptString . new ( 'DOMAIN' , [ false , 'The domain to authenticate to' ] ) ,
33
34
Msf ::OptString . new ( 'USERNAME' , [ false , 'The username to authenticate with' ] , aliases : [ 'BIND_DN' ] ) ,
@@ -95,7 +96,6 @@ def get_connect_opts
95
96
# @return [Object] The result of whatever the block that was
96
97
# passed in via the "block" parameter yielded.
97
98
def ldap_connect ( opts = { } , &block )
98
- return yield session . client if session
99
99
ldap_open ( get_connect_opts . merge ( opts ) , &block )
100
100
end
101
101
@@ -111,7 +111,6 @@ def ldap_connect(opts = {}, &block)
111
111
# @return [Object] The result of whatever the block that was
112
112
# passed in via the "block" parameter yielded.
113
113
def ldap_open ( connect_opts , &block )
114
- return yield session . client if session
115
114
opts = resolve_connect_opts ( connect_opts )
116
115
Rex ::Proto ::LDAP ::Client . open ( opts , &block )
117
116
end
@@ -136,8 +135,6 @@ def resolve_connect_opts(connect_opts)
136
135
# @yieldparam ldap [Rex::Proto::LDAP::Client] The LDAP connection handle to use for connecting to
137
136
# the target LDAP server.
138
137
def ldap_new ( opts = { } )
139
- return yield session . client if session
140
-
141
138
ldap = Rex ::Proto ::LDAP ::Client . new ( resolve_connect_opts ( get_connect_opts . merge ( opts ) ) )
142
139
143
140
# NASTY, but required
@@ -182,6 +179,11 @@ def ldap.use_connection(args)
182
179
# bind request failed.
183
180
# @return [Nil] This function does not return any data.
184
181
def validate_bind_success! ( ldap )
182
+ if defined? ( :session ) && session
183
+ vprint_good ( 'Successfully bound to the LDAP server via existing SESSION!' )
184
+ return
185
+ end
186
+
185
187
bind_result = ldap . get_operation_result . table
186
188
187
189
# Codes taken from https://ldap.com/ldap-result-code-reference-core-ldapv3-result-codes
0 commit comments