Skip to content

Commit 7e42746

Browse files
Code review and fixes
- Fix Pkcs12 filer to use case insensitive username and realm - Handle nil values in `StoredPkcs12` - Use `fallbacks` options in `ldap_login` - Small fixes
1 parent 3205c73 commit 7e42746

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

lib/msf/core/exploit/remote/pkcs12/storage.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ def filter_pkcs12(options)
4444

4545
filter = {}
4646
filter[:id] = options[:id] if options[:id].present?
47-
filter[:user] = options[:username] if options[:username].present?
48-
filter[:realm] = options[:realm] if options[:realm].present?
4947

5048
creds = framework.db.creds(
5149
workspace: options.fetch(:workspace) { workspace },
@@ -54,6 +52,15 @@ def filter_pkcs12(options)
5452
).select do |cred|
5553
# this is needed since if a filter is provided (e.g. `id:`) framework.db.creds will ignore the type:
5654
next false unless cred.private.type == 'Metasploit::Credential::Pkcs12'
55+
56+
if options[:username].present?
57+
next false if options[:username].casecmp(cred.public.username) != 0
58+
end
59+
60+
if options[:realm].present? && cred.realm
61+
next false if options[:realm].casecmp(cred.realm.value) != 0
62+
end
63+
5764
if options[:status].present?
5865
# If status is not set on the credential, considere it is `active`
5966
status = cred.private.status || 'active'

lib/msf/core/exploit/remote/pkcs12/stored_pkcs12.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ def openssl_pkcs12
1414
end
1515

1616
def adcs_ca
17-
private_cred.adcs_ca
17+
private_cred.adcs_ca || ''
1818
end
1919

2020
def adcs_template
21-
private_cred.adcs_template
21+
private_cred.adcs_template || ''
2222
end
2323

2424
def private_cred
2525
@pkcs12.private
2626
end
2727

2828
def username
29-
@pkcs12.public.username
29+
@pkcs12.public&.username || ''
3030
end
3131

3232
def realm
33-
@pkcs12.realm.value
33+
@pkcs12.realm&.value || ''
3434
end
3535

3636
def status
37-
private_cred.status
37+
private_cred.status || ''
3838
end
3939

4040
# @return [TrueClass, FalseClass] True if the certificate is valid within the not_before/not_after, false otherwise

modules/auxiliary/scanner/ldap/ldap_login.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def initialize(info = {})
3737
'APPEND_DOMAIN', [true, 'Appends `@<DOMAIN> to the username for authentication`', false],
3838
conditions: ['LDAP::Auth', 'in', [Msf::Exploit::Remote::AuthOption::AUTO, Msf::Exploit::Remote::AuthOption::PLAINTEXT]]
3939
),
40-
Msf::OptString.new('LDAPDomain', [false, 'The domain to authenticate to']),
41-
Msf::OptString.new('LDAPUsername', [false, 'The username to authenticate with'], aliases: ['BIND_DN']),
42-
Msf::OptString.new('LDAPPassword', [false, 'The password to authenticate with'], aliases: ['BIND_PW']),
40+
Msf::OptString.new('LDAPDomain', [false, 'The domain to authenticate to'], fallbacks: ['DOMAIN']),
41+
Msf::OptString.new('LDAPUsername', [false, 'The username to authenticate with'], fallbacks: ['USERNAME'], aliases: ['BIND_DN']),
42+
Msf::OptString.new('LDAPPassword', [false, 'The password to authenticate with'], fallbacks: ['PASSWORD'], aliases: ['BIND_PW']),
4343
OptInt.new('SessionKeepalive', [true, 'Time (in seconds) for sending protocol-level keepalive messages', 10 * 60])
4444
]
4545
)
@@ -93,10 +93,13 @@ def validate_connect_options!
9393
end
9494

9595
def run_host(ip)
96-
ignore_public = datastore['LDAP::Auth'] == Msf::Exploit::Remote::AuthOption::SCHANNEL
97-
ignore_private =
98-
datastore['LDAP::Auth'] == Msf::Exploit::Remote::AuthOption::SCHANNEL ||
99-
(Msf::Exploit::Remote::AuthOption::KERBEROS && !datastore['ANONYMOUS_LOGIN'] && !datastore['LDAPPassword'])
96+
ignore_public = ignore_private = false
97+
case datastore['LDAP::Auth']
98+
when Msf::Exploit::Remote::AuthOption::SCHANNEL
99+
ignore_public = ignore_private = true
100+
when Msf::Exploit::Remote::AuthOption::KERBEROS
101+
ignore_private = !datastore['ANONYMOUS_LOGIN'] && !datastore['LDAPPassword']
102+
end
100103

101104
cred_collection = build_credential_collection(
102105
username: datastore['LDAPUsername'],
@@ -109,7 +112,7 @@ def run_host(ip)
109112
)
110113

111114
opts = {
112-
ldap_domain: datastore['LDAPDomain'],
115+
domain: datastore['LDAPDomain'],
113116
append_domain: datastore['APPEND_DOMAIN'],
114117
ssl: datastore['SSL'],
115118
proxies: datastore['PROXIES'],

0 commit comments

Comments
 (0)