The vulnerability lies in the Microsoft.AspNetCore.Authentication.Negotiate package when configured to use LDAP for role retrieval. The analysis of the patch commit af0f47f658f85daefb2b55cd11f7dc93b0c7798a revealed several flaws in the LdapAdapter.cs file.
The primary vulnerable function is RetrieveClaimsAsync. Before the patch, it was susceptible to two main issues:
- Improper Realm Validation: It did not verify that the realm of the authenticated user (the part after the '@' in the User Principal Name) matched the LDAP domain configured in the application. This allowed an attacker from a different, untrusted Kerberos realm to authenticate as a local user if they shared the same username, leading to an elevation of privilege.
- LDAP Injection: The
userAccountName was used directly in an LDAP search filter without proper escaping. This allowed an attacker to inject malicious characters into the filter, potentially bypassing authentication or extracting sensitive information from the LDAP directory.
The secondary vulnerable function is GetNestedGroups. This function was used to resolve nested group memberships. It looked up groups by their sAMAccountName or CN which could be ambiguous. An attacker could create a group with a common name that collides with a privileged group, and if the search returned the attacker's group first, they could be granted unintended permissions.
The patch addresses these issues by:
- Adding strict realm validation in
RetrieveClaimsAsync to ensure the user belongs to the configured domain.
- Introducing a new function,
EscapeLdapFilterValue, to sanitize input used in LDAP filters, thus preventing LDAP injection attacks.
- Modifying
GetNestedGroups to look up groups by their unique distinguishedName (DN) instead of the ambiguous CN, eliminating the possibility of group name collisions.