Fix NoMethodError in PKINIT extract_user_and_realm#21140
Open
RiOxFRANKY wants to merge 1 commit intorapid7:masterfrom
Open
Fix NoMethodError in PKINIT extract_user_and_realm#21140RiOxFRANKY wants to merge 1 commit intorapid7:masterfrom
RiOxFRANKY wants to merge 1 commit intorapid7:masterfrom
Conversation
This commit fixes a NoMethodError that occurred when the SAN extension contained non-string ASN1Data entries. It replaces broken normalization logic with filter_map and adds comprehensive unit tests. Fixes rapid7#20427
|
Thanks for your pull request! As part of our landing process, we manually verify that all modules work as expected. We've added the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix NoMethodError in PKINIT extract_user_and_realm (Issue #20427)
Summary
This PR fixes a
NoMethodError: undefined method 'downcase' for OpenSSL::ASN1::ASN1Datathat occurs in the Metasploit Kerberos client when a certificate's Subject Alternative Name (SAN) extension contains OtherName entries that are not MS UPNs (or are formatted in a way that returnsASN1Datainstead of aString).Root Cause
The bug was located in the normalization block of extract_user_and_realm. While the previous logic tried to handle
ASN1Dataobjects using a series ofelsif/elsechecks, it unfortunately relied on.to_s.downcasefor non-string values. This caused:ASN1Dataobject (like an OtherName entry) was passed to the normalization block, it triggered theNoMethodError..to_sproduced garbage values like"[#<OpenSSL::ASN1::ObjectId:0x0000...>]".The Fix
Replaced the broken
maplogic with a robustfilter_map. The new implementation:.downcaseon actualStringobjects.normalized_resultsonly contains valid principal/realm strings.Kerberos::Client::Pkinit#extract_user_and_realmwith specific SAN extension #19495 which fixed the outer SAN extension parsing.Verification Steps
Automated Tests
Run the following spec to verify the fix and prevent regressions: