lib/msf/core/post/windows/ldap.rb
# Binds to the default LDAP Server
# @param [int] the maximum number of results to return in a query
# @return [LDAP Session Handle]
Binds to the default LDAP Server
Binds to the default LDAP Server
def bind_default_ldap_server(size_limit)
    vprint_status ("Initializing LDAP connection.")
    init_result = wldap32.ldap_sslinitA("\x00\x00\x00\x00", 389, 0)
    session_handle = init_result['return']
    if session_handle == 0
      raise RuntimeError.new("Unable to initialize ldap server: #{init_result["ErrorMessage"]}")
    end
    vprint_status("LDAP Handle: #{session_handle}")
    vprint_status ("Setting Sizelimit Option")
    sl_result = wldap32.ldap_set_option(session_handle, LDAP_OPT_SIZELIMIT, size_limit)
    vprint_status ("Binding to LDAP server")
    bind_result = wldap32.ldap_bind_sA(session_handle, nil, nil, LDAP_AUTH_NEGOTIATE)
    bind = bind_result['return']
    unless bind == 0
      vprint_status("Unbinding from LDAP service")
      wldap32.ldap_unbind(session_handle)
      raise RuntimeError.new("Unable to bind to ldap server: #{ERROR_CODE_TO_CONSTANT[bind]}")
    end
    if (block_given?)
      begin
        yield session_handle
      ensure
        vprint_status("Unbinding from LDAP service")
        wldap32.ldap_unbind(session_handle)
      end
    else
      return session_handle
    end
    return session_handle
  end
def bind_default_ldap_server ( size_limit ) vprint_status ( "Initializing LDAP connection." ) init_result = wldap32 . ldap_sslinitA ( "\x00\x00\x00\x00" , 389 , 0 ) session_handle = init_result [ 'return' ] if session_handle == 0 raise RuntimeError . new ( "Unable to initialize ldap server: #{init_result["ErrorMessage"]}" ) end vprint_status ( "LDAP Handle: #{session_handle}" ) vprint_status ( "Setting Sizelimit Option" ) sl_result = wldap32 . ldap_set_option ( session_handle , LDAP_OPT_SIZELIMIT , size_limit ) vprint_status ( "Binding to LDAP server" ) bind_result = wldap32 . ldap_bind_sA ( session_handle , nil , nil , LDAP_AUTH_NEGOTIATE ) bind = bind_result [ 'return' ] unless bind == 0 vprint_status ( "Unbinding from LDAP service" ) wldap32 . ldap_unbind ( session_handle ) raise RuntimeError . new ( "Unable to bind to ldap server: #{ERROR_CODE_TO_CONSTANT[bind]}" ) end if ( block_given? ) begin yield session_handle ensure vprint_status ( "Unbinding from LDAP service" ) wldap32 . ldap_unbind ( session_handle ) end else return session_handle end return session_handle end
Binds to the default LDAP Server
Binds to the default LDAP Server
None
LDAP Session Handle
size_limit
the maximum number of results to return in a query
the maximum number of results to return in a query