Skip to content

Commit 468f168

Browse files
committed
Call LDAP whoami when the username is not present
1 parent 44f79f5 commit 468f168

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/msf/base/sessions/ldap.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,17 @@ def bootstrap(datastore = {}, handler = nil)
4242
session = self
4343
session.init_ui(user_input, user_output)
4444

45-
@info = "LDAP #{datastore['USERNAME']} @ #{@peer_info}"
45+
username = datastore['USERNAME']
46+
if username.blank?
47+
begin
48+
whoami = client.ldapwhoami
49+
rescue Net::LDAP::Error => e
50+
ilog('ldap session opened with no username and the target does not support the LDAP whoami extension')
51+
else
52+
username = whoami.delete_prefix('u:').split('\\').last
53+
end
54+
end
55+
@info = "LDAP #{username} @ #{@peer_info}"
4656
end
4757

4858
def execute_file(full_path, args)

spec/lib/msf/base/sessions/ldap_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
allow(client).to receive(:peerinfo).and_return(peer_info)
2424
allow(client).to receive(:peerhost).and_return(address)
2525
allow(client).to receive(:peerport).and_return(port)
26+
allow(client).to receive(:ldapwhoami).and_return("u:WORKGROUP\\Administrator")
2627
end
2728

2829
it_behaves_like 'client session'

0 commit comments

Comments
 (0)