Skip to content

Commit

Permalink
Merge pull request #19809 from dwelch-r7/mark-ldap-session-as-interac…
Browse files Browse the repository at this point in the history
…tive

Add LDAP to the set of interactive session types
  • Loading branch information
adfoster-r7 authored Jan 15, 2025
2 parents c494ad4 + 4c478a5 commit de0cde7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/msf/core/rpc/v10/rpc_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ def rpc_compatible_modules(sid)
postgresql
mysql
smb
ldap
].freeze

def _find_module(_mtype, mname)
Expand All @@ -545,7 +546,7 @@ def _valid_interactive_session(sid)
error(500, "Unknown Session ID #{sid}") if session.nil?

unless INTERACTIVE_SESSION_TYPES.include?(session.type)
error(500, "Use `interactive_read` and `interactive_write` for sessions of #{session.type} type")
error(500, "`interactive_read` and `interactive_write` not available for #{session.type} sessions")
end

session
Expand Down
7 changes: 6 additions & 1 deletion lib/rex/post/ldap/ui/console/command_dispatcher/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ def cmd_query_help
end

def cmd_getuid
username = client.ldapwhoami
begin
username = client.ldapwhoami
rescue Net::LDAP::Error => e
print_error(e.message)
return
end
username.delete_prefix!('u:')
print_status("Server username: #{username}")
end
Expand Down
8 changes: 6 additions & 2 deletions lib/rex/proto/ldap/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,16 @@ def discover_base_dn
end

# Monkeypatch upstream library to support the extended Whoami request. Delete
# this after https://github.com/ruby-ldap/ruby-net-ldap/pull/425 is landed.
# this after https://github.com/ruby-ldap/ruby-net-ldap/pull/425 is released.
# This is not the only occurrence of a patch for this functionality.
def ldapwhoami(args = {})
instrument "ldapwhoami.net_ldap", args do |payload|
@result = use_connection(args, &:ldapwhoami)
@result.success? ? @result.extended_response : nil
if @result.success?
@result.extended_response
else
raise Net::LDAP::Error, "#{peerinfo} LDAP Error: #{@result.error_message}"
end
end
end
end
Expand Down

0 comments on commit de0cde7

Please sign in to comment.