Skip to content

Java: Insecure LDAP authentication #4854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 4, 2021

Conversation

luchua-bc
Copy link
Contributor

When using the Java LDAP API to perform LDAPv3-style extended operations and controls like user profile retrieval, a context with connection properties including user credentials is started. Transmission of LDAP credentials in cleartext allows remote attackers to obtain sensitive information by sniffing the network.

This query detects transmission of cleartext credentials in LDAP authentication, which meets the following two criteria:

  1. Use the protocol "ldap" instead of "ldaps"
  2. Use "simple" authentication instead of SASL authentication using encrypted/hashed credentials

Please consider to merge the PR. Thanks.

@smowton
Copy link
Contributor

smowton commented Dec 21, 2020

Acknowledged; will look at this on January 4th or later

@luchua-bc
Copy link
Contributor Author

Thanks @smowton. This is also my last planned PR before the holidays. Merry Christmas and Happy New Year!

@luchua-bc

@smowton smowton self-assigned this Jan 4, 2021
@smowton
Copy link
Contributor

smowton commented Jan 4, 2021

Looks good, waiting on security-lab to look at the results now.

@JarLob
Copy link
Contributor

JarLob commented Jan 12, 2021

Hi @luchua-bc,
It looks like it is still possible to use an encrypted connection by setting Context.SECURITY_PROTOCOL to ssl even if the schema is ldap://. Could you please improve the query to take it into account?

@luchua-bc
Copy link
Contributor Author

Thanks @JarLob for reviewing this PR. I thought about this one when submitting the first version but finally decided not to include it since it's not that a common configuration. There is no GitHub repository found with this configuration during a quick search when I drafted the query.

However, it's nice to have it so that the query can be more comprehensive and can help to reduce possible false positives. I've made requested changes. Please review.

Cheers,
@luchua-bc

@JarLob
Copy link
Contributor

JarLob commented Jan 13, 2021

The results are much better now! But it bugs me that the sink is .put(Context.PROVIDER_URL instead of the InitialDirContext constructor call. Could you please remove the side-conditions on the sink and additional taint step regarding SECURITY_PROTOCOL and SECURITY_AUTHENTICATION; instead, use a separate Configuration for each of them, and look for a sink which IS also a sink for SECURITY_AUTHENTICATION = simple AND PROVIDER_URL = ldap:// AND NOT SECURITY_PROTOCOL = ssl. It wouldn't warn in a case like:

Hashtable<String, String> env = new Hashtable<>();
setSSL(env);
env.put(Context.PROVIDER_URL, "ldap://blabla");
setBasicAuth(env);
userContext = new InitialLdapContext(env, null);

@luchua-bc
Copy link
Contributor Author

Sorry I don't quite get what you mean. Do you want to make the Hashtable env the sink? How can three configurations be made with the same sink? And what will be their source? Please provide more details. Thanks.

@smowton
Copy link
Contributor

smowton commented Jan 14, 2021

The new InitialLdapContext(env, ...) call would be the sink, and env.put calls with an appropriate key would be an additional taint step. Look for "ldap://..." flowing to the sink, AND basic-authentication flowing to the sink, AND NOT SSL flowing to the sink. That means three configurations, differing by the env.put key they're sensitive to.

@luchua-bc
Copy link
Contributor Author

Thanks @smowton for the detailed explanation.

As the approach is quite different from my original thoughts, it took me some time to revamp the query. Although I'm still not entirely sure whether it's what we want, the new query does render desired results.

Please review. Thanks.

@smowton
Copy link
Contributor

smowton commented Jan 27, 2021

I don't have any further comments; pinged a Java code-owner to take a look.

@aschackmull aschackmull merged commit 35e620a into github:main Feb 4, 2021
@luchua-bc luchua-bc deleted the java/insecure-ldap-auth branch February 4, 2021 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants