Skip to content

Commit becdda1

Browse files
Tanush-Jainsmcintyre-r7
authored andcommitted
added fixed pkinit file
1 parent 854a5bc commit becdda1

File tree

1 file changed

+22
-6
lines changed
  • lib/msf/core/exploit/remote/kerberos/client

1 file changed

+22
-6
lines changed

lib/msf/core/exploit/remote/kerberos/client/pkinit.rb

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def extract_user_and_realm(certificate, username, realm)
6767
certificate.extensions.select { |ext| ext.oid == 'subjectAltName' }.each do |san_extension|
6868
begin
6969
asn_san = OpenSSL::ASN1.decode(san_extension)
70-
asn_san_value = asn_san.value.find {|value| value.is_a? OpenSSL::ASN1::OctetString }
70+
asn_san_value = asn_san.value.find { |value| value.is_a? OpenSSL::ASN1::OctetString }
7171

7272
if asn_san_value.nil?
7373
raise ArgumentError, 'Invalid certificate provided: unable to decode SAN'
@@ -95,7 +95,7 @@ def extract_user_and_realm(certificate, username, realm)
9595
elsif san_entry.tag == 2 # dNSName
9696
parts = san_entry.value.split('.')
9797
if parts.length == 1
98-
user = san_entry
98+
user = san_entry.value # Corrected to extract string value
9999
domain = ''
100100
else
101101
user = parts[0] + '$'
@@ -110,15 +110,26 @@ def extract_user_and_realm(certificate, username, realm)
110110
end
111111

112112
unless realm.nil? # and also username, since it's both or neither
113-
unless results.map { |x| x.map(&:downcase) }.include?([username.downcase, realm.downcase])
114-
# If we've been provided an override but can't find them in a SAN, give a warning
113+
normalized_results = results.map do |pair|
114+
pair.map do |value|
115+
if value.is_a?(String)
116+
value.downcase
117+
elsif value.is_a?(OpenSSL::ASN1::ASN1Data) && value.respond_to?(:value)
118+
val = value.value
119+
val.is_a?(String) ? val.downcase : val.to_s.downcase
120+
else
121+
value.to_s.downcase
122+
end
123+
end
124+
end
125+
126+
unless normalized_results.include?([username.downcase, realm.downcase])
115127
print_warning("Warning: Provided principal and realm (#{username}@#{realm}) do not match entries in certificate:")
116128
results.each do |cert_username, cert_realm|
117129
print_warning(" * #{cert_username}@#{cert_realm}")
118130
end
119131
end
120132

121-
# But hey, they've overridden it, so off we go
122133
return [username, realm]
123134
end
124135

@@ -220,16 +231,21 @@ def build_pa_pk_as_req(pfx, dh, dh_nonce, request_body, opts)
220231
client_dh_nonce: RASN1::Types::OctetString.new(value: dh_nonce)
221232
)
222233

234+
223235
auth_pack[:client_public_value][:subject_public_key].bit_length = pub_key_encoded.length * 8
224236

237+
225238
signed_auth_pack = sign_auth_pack(auth_pack, pfx.key, certificate)
226239

240+
227241
pa_as_req = Rex::Proto::Kerberos::Model::PreAuthPkAsReq.new
228242

243+
229244
pa_as_req.signed_auth_pack = signed_auth_pack
230245

246+
231247
Rex::Proto::Kerberos::Model::PreAuthDataEntry.new(type: Rex::Proto::Kerberos::Model::PreAuthType::PA_PK_AS_REQ,
232-
value: pa_as_req.to_der)
248+
value: pa_as_req.to_der)
233249
end
234250

235251
# Calculate the cryptographic signatures over the AuthPack, and create the appropriate

0 commit comments

Comments
 (0)