Skip to content

Commit ec7d47c

Browse files
Merge pull request #20461 from adfoster-r7/improve-login-summary-for-ldap-scanner
Improve login summary for ldap schannel scanner
2 parents 9dee394 + a1630c0 commit ec7d47c

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

lib/msf/core/auxiliary/report_summary.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,23 @@ def login_credentials(credential_data)
7171
def create_credential_login(credential_data)
7272
return super unless framework.features.enabled?(Msf::FeatureManager::SHOW_SUCCESSFUL_LOGINS) && datastore['ShowSuccessfulLogins'] && @report
7373

74-
@report[rhost] = { successful_logins: [] }
74+
@report[rhost] ||= {}
75+
@report[rhost][:successful_logins] ||= []
7576
@report[rhost][:successful_logins] << login_credentials(credential_data)
7677
super
7778
end
7879

80+
def report_successful_login(public:, private:)
81+
return super unless framework.features.enabled?(Msf::FeatureManager::SHOW_SUCCESSFUL_LOGINS) && datastore['ShowSuccessfulLogins'] && @report
82+
83+
@report[rhost] ||= {}
84+
@report[rhost][:successful_logins] ||= []
85+
@report[rhost][:successful_logins] << {
86+
public: public,
87+
private_data: private
88+
}
89+
end
90+
7991
# Creates a credential and adds to to the DB if one is present, then calls create_credential_login to
8092
# attempt a login
8193
#
@@ -90,7 +102,8 @@ def create_credential_login(credential_data)
90102
def create_credential_and_login(credential_data)
91103
return super unless framework.features.enabled?(Msf::FeatureManager::SHOW_SUCCESSFUL_LOGINS) && datastore['ShowSuccessfulLogins'] && @report
92104

93-
@report[rhost] = { successful_logins: [] }
105+
@report[rhost] ||= {}
106+
@report[rhost][:successful_logins] ||= []
94107
@report[rhost][:successful_logins] << login_credentials(credential_data)
95108
super
96109
end
@@ -107,14 +120,9 @@ def create_credential_and_login(credential_data)
107120
def start_session(obj, info, ds_merge, crlf = false, sock = nil, sess = nil)
108121
return super unless framework.features.enabled?(Msf::FeatureManager::SHOW_SUCCESSFUL_LOGINS) && datastore['ShowSuccessfulLogins']
109122

110-
unless @report && @report[rhost]
111-
elog("No RHOST found in report, skipping reporting for #{rhost}")
112-
print_brute level: :error, ip: rhost, msg: "No RHOST found in report, skipping reporting for #{rhost}"
113-
return super
114-
end
115-
116123
result = super
117-
@report[rhost].merge!({ successful_sessions: [] })
124+
@report[rhost] ||= {}
125+
@report[rhost][:successful_sessions] ||= []
118126
@report[rhost][:successful_sessions] << result
119127
result
120128
end
@@ -127,6 +135,7 @@ def start_session(obj, info, ds_merge, crlf = false, sock = nil, sess = nil)
127135
#
128136
# @return [Hash] Rhost keys mapped to successful logins and sessions for each host
129137
def print_report_summary
138+
return unless @report
130139
report = @report
131140

132141
logins = report.flat_map { |_k, v| v[:successful_logins] }.compact

modules/auxiliary/scanner/ldap/ldap_login.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def create_session?
7171

7272
def run
7373
validate_connect_options!
74-
results = super
74+
results = super || {}
7575
logins = results.flat_map { |_k, v| v[:successful_logins] }
7676
sessions = results.flat_map { |_k, v| v[:successful_sessions] }
7777
print_status("Bruteforce completed, #{logins.size} #{logins.size == 1 ? 'credential was' : 'credentials were'} successful.")
@@ -169,6 +169,10 @@ def run_host(ip)
169169
if opts[:ldap_auth] == Msf::Exploit::Remote::AuthOption::SCHANNEL
170170
# Schannel auth has no meaningful credential information to store in the DB
171171
msg = opts[:ldap_pkcs12].nil? ? 'Using stored certificate' : "Cert File #{opts[:ldap_pkcs12][:path]} (#{opts[:ldap_pkcs12][:value].certificate.subject})"
172+
report_successful_login(
173+
public: opts[:ldap_pkcs12][:value].certificate.subject.to_s,
174+
private: opts[:ldap_pkcs12][:path]
175+
)
172176
print_brute level: :good, ip: ip, msg: "Success: '#{msg}'"
173177
else
174178
create_credential_and_login(credential_data) if result.credential.private

0 commit comments

Comments
 (0)