@@ -4,6 +4,10 @@ module Msf
44class Post
55module Windows
66
7+ #
8+ # @see
9+ # http://msdn.microsoft.com/en-us/library/windows/desktop/aa366961(v=vs.85).aspx
10+ # MSDN: Lightweight Directory Access Protocol
711module LDAP
812
913 include Msf ::Post ::Windows ::Error
@@ -91,7 +95,7 @@ def initialize(info = {})
9195
9296 # Converts a Distinguished Name to DNS name
9397 #
94- # @param [String] Distinguished Name
98+ # @param dn [String] Distinguished Name
9599 # @return [String] DNS name
96100 def dn_to_domain ( dn )
97101 if dn . include? "DC="
@@ -103,10 +107,10 @@ def dn_to_domain(dn)
103107
104108 # Performs an ldap query
105109 #
106- # @param [String] LDAP search filter
107- # @param [Integer ] Maximum results
108- # @param [Array] String array containing attributes to retrieve
109- # @param [String] Optional domain or distinguished name
110+ # @param filter [String] LDAP search filter
111+ # @param max_results [Fixnum ] Maximum results
112+ # @param fields [Array<String>] Attributes to retrieve
113+ # @param domain [String] Optional domain or distinguished name
110114 # @return [Hash] Entries found
111115 # @raise [RuntimeError] Raised when the default naming context isn't
112116 # specified as distinguished name.
@@ -136,6 +140,8 @@ def query(filter, max_results, fields, domain=nil)
136140
137141 # Performs a query to retrieve the default naming context
138142 #
143+ # @param domain [String] Optional domain or distinguished name
144+ # @return [String]
139145 def get_default_naming_context ( domain = nil )
140146 bind_default_ldap_server ( 1 , domain ) do |session_handle |
141147 print_status ( "Querying default naming context" )
@@ -151,14 +157,15 @@ def get_default_naming_context(domain=nil)
151157
152158 # Performs a query on the LDAP session
153159 #
154- # @param [Handle] LDAP Session Handle
155- # @param [Integer] Pointer to string that contains distinguished name of entry to start the search
156- # @param [Integer] Search Scope
157- # @param [String] Search Filter
158- # @param [Array] Attributes to retrieve
160+ # @param session_handle [Handle] LDAP Session Handle
161+ # @param base [Fixnum] Pointer to string that contains distinguished
162+ # name of entry to start the search
163+ # @param scope [Fixnum] Search Scope
164+ # @param filter [String] Search Filter
165+ # @param fields [Array<String>] Attributes to retrieve
159166 # @return [Hash] Entries found
160167 def query_ldap ( session_handle , base , scope , filter , fields )
161- vprint_status ( "Searching LDAP directory" )
168+ vprint_status ( "Searching LDAP directory" )
162169 search = wldap32 . ldap_search_sA ( session_handle , base , scope , filter , nil , 0 , 4 )
163170 vprint_status ( "search: #{ search } " )
164171
@@ -172,7 +179,7 @@ def query_ldap(session_handle, base, scope, filter, fields)
172179
173180 search_count = wldap32 . ldap_count_entries ( session_handle , search [ 'res' ] ) [ 'return' ]
174181
175- if ( search_count == 0 )
182+ if search_count == 0
176183 print_error ( "No entries retrieved" )
177184 wldap32 . ldap_msgfree ( search [ 'res' ] )
178185 return
@@ -217,7 +224,6 @@ def query_ldap(session_handle, base, scope, filter, fields)
217224 field_results = [ ]
218225 fields . each do |field |
219226 vprint_status ( "Field: #{ field } " )
220- value_results = ""
221227
222228 values = get_values_from_ber ( ber , field )
223229
@@ -239,15 +245,15 @@ def query_ldap(session_handle, base, scope, filter, fields)
239245
240246 # Gets the LDAP Entry
241247 #
242- # @param [Integer ] Pointer to the Entry
248+ # @param pEntry [Fixnum ] Pointer to the Entry
243249 # @return [Array] Entry data structure
244250 def get_entry ( pEntry )
245251 return client . railgun . memread ( pEntry , 41 ) . unpack ( 'LLLLLLLLLSCCC' )
246252 end
247253
248254 # Get BER Element data structure from LDAPMessage
249255 #
250- # @param [String] The LDAP Message from the server
256+ # @param msg [String] The LDAP Message from the server
251257 # @return [String] The BER data structure
252258 def get_ber ( msg )
253259 ber = client . railgun . memread ( msg [ 2 ] , 60 ) . unpack ( 'L*' )
@@ -267,9 +273,9 @@ def get_ber(msg)
267273 # instead it finds the first occurance of our field name
268274 # tries to check the length of that value.
269275 #
270- # @param [String] BER data structure
271- # @param [String] Attribute name
272- # @return [Array] Returns array of values for the field
276+ # @param ber_data [String] BER data structure
277+ # @param field [String] Attribute name
278+ # @return [Array] Values for the given + field+
273279 def get_values_from_ber ( ber_data , field )
274280 field_offset = ber_data . index ( field )
275281
@@ -322,10 +328,11 @@ def wldap32
322328 end
323329
324330 # Binds to the default LDAP Server
325- # @param [int] the maximum number of results to return in a query
326- # @return [LDAP Session Handle]
331+ # @param size_limit [Fixnum] Maximum number of results to return in a query
332+ # @param domain [String] Optional domain or distinguished name
333+ # @return LDAP session handle
327334 def bind_default_ldap_server ( size_limit , domain = nil )
328- vprint_status ( "Initializing LDAP connection." )
335+ vprint_status ( "Initializing LDAP connection." )
329336
330337 # If domain is still null the API may be able to handle it...
331338 init_result = wldap32 . ldap_sslinitA ( domain , 389 , 0 )
@@ -336,10 +343,10 @@ def bind_default_ldap_server(size_limit, domain=nil)
336343
337344 vprint_status ( "LDAP Handle: #{ session_handle } " )
338345
339- vprint_status ( "Setting Sizelimit Option" )
340- sl_result = wldap32 . ldap_set_option ( session_handle , LDAP_OPT_SIZELIMIT , size_limit )
346+ vprint_status ( "Setting Sizelimit Option" )
347+ wldap32 . ldap_set_option ( session_handle , LDAP_OPT_SIZELIMIT , size_limit )
341348
342- vprint_status ( "Binding to LDAP server" )
349+ vprint_status ( "Binding to LDAP server" )
343350 bind_result = wldap32 . ldap_bind_sA ( session_handle , nil , nil , LDAP_AUTH_NEGOTIATE )
344351
345352 bind = bind_result [ 'return' ]
0 commit comments