Skip to content

[Java]: CWE 295 - Insecure TrustManager - MiTM #222

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

Closed
1 task done
intrigus-lgtm opened this issue Dec 24, 2020 · 16 comments
Closed
1 task done

[Java]: CWE 295 - Insecure TrustManager - MiTM #222

intrigus-lgtm opened this issue Dec 24, 2020 · 16 comments
Labels
All For One Submissions to the All for One, One for All bounty

Comments

@intrigus-lgtm
Copy link
Contributor

CVE ID(s)

List the CVE ID(s) associated with this vulnerability. GitHub will automatically link CVE IDs to the GitHub Advisory Database.

Report

Describe the vulnerability. Provide any information you think will help GitHub assess the impact your query has on the open source community.
A insecure TrustManager is an implementation of the TrustManager interface, where the checkServerTrusted method trusts any certificate because it never throws a CertificateException.
As the TrustManager trusts any certificate, an attacker can create a self-signed certificate that will be accepted as any certificate is trusted. This leads to a MiTM attack against the connection thereby stealing sensitive secrets such as login data or other tokens is possible.

  • Are you planning to discuss this vulnerability submission publicly? (Blog Post, social networks, etc). We would love to have you spread the word about the good work you are doing,

Query:

github/codeql#4879

Result(s)

Provide at least one useful result found by your query, on some revision of a real project.

@intrigus-lgtm intrigus-lgtm added the All For One Submissions to the All for One, One for All bounty label Dec 24, 2020
@luchua-bc
Copy link

Has the listed issue opencast/opencast@4225bf9 already been detected by the query codeql/java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql? Will the queries be merged?

      public boolean verify(String host, SSLSession ssl) {
        logger.trace("Skipping SSL session host name check on {}", host);
        return true;
      }
    };

@intrigus-lgtm
Copy link
Contributor Author

Has the listed issue opencast/opencast@4225bf9 already been detected by the query codeql/java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql? Will the queries be merged?

      public boolean verify(String host, SSLSession ssl) {
        logger.trace("Skipping SSL session host name check on {}", host);
        return true;
      }
    };

I don't know whether UnsafeCertTrust.ql would have detected it, but I don't think it would have detected it.
https://github.com/github/codeql/blob/8d4f7e2db7ec3b7559a3e358fd1b8a7203ce7474/java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql#L22 requires the checkServerTrusted method to have 0 statements and the checkServerTrusted method of opencast has more than 0 statements, because it includes a logging call.

I tried building an database of opencast but building failed.
If you or someone else has a database that still has the vulnerability, I could have a look whether it would have been detected.

I found it easier for me to create a new query and then remove the overlapping code from UnsafeCertTrust.ql, because it contains/contained three sub-queries and separating them nicely was hard...

@smowton
Copy link

smowton commented Jan 5, 2021

You can download a database at https://lgtm.com/projects/g/opencast/opencast/ci/#ql

@intrigus-lgtm
Copy link
Contributor Author

I know that I can download databases from lgtm.com, but the issue has already been fixed.
As far as I know, only the latest database is available or isn't it?

@smowton
Copy link

smowton commented Jan 5, 2021

Ah, yes I think that is the case, sorry.

@m-y-mo
Copy link
Contributor

m-y-mo commented Jan 26, 2021

@intrigus-lgtm Would you be able to share the build log with us so that we can check what went wrong with the build and then perhaps can help you to build the database? Thanks.

@intrigus-lgtm
Copy link
Contributor Author

@m-y-mo sure, but the problem seems to be related to a maven package that is missing.
I'm currently trying different opencast versions to see if I can find one that compiles...

@intrigus-lgtm
Copy link
Contributor Author

I was able to compile it.
(Are you interested in the database?)
Here are the results:

UnsafeCertTrust.ql:
grafik

InsecureTrustManager.ql:
grafik

@ghsecuritylab
Copy link
Collaborator

Your submission is now in status SecLab review.

For information, the evaluation workflow is the following:
CodeQL initial assessment > SecLab review > CodeQL review > SecLab finalize > Pay > Closed

@m-y-mo
Copy link
Contributor

m-y-mo commented Jan 29, 2021

@intrigus-lgtm Thanks. I'm mostly interested to see if there the UnsafeCertTrust.ql query catches the result and whether the build failure is a problem of the codeql extract so we can take a look at it. As the result is not flagged by UnsafeCertTrust.ql, we are happy to move it to the next stage and review the security impact, scope and FP rate of the query. We'll get back to you once it is done. Thanks.

@intrigus-lgtm
Copy link
Contributor Author

@m-y-mo the build failure was not related to codeql :)
Note that I still plan to do same improvements.
Running the query on lgtm.com showed that there are quite some FPs that should be quite easily fixable.
So the FP rate of the query is subject to change :)

@ghsecuritylab
Copy link
Collaborator

Your submission is now in status CodeQL review.

For information, the evaluation workflow is the following:
CodeQL initial assessment > SecLab review > CodeQL review > SecLab finalize > Pay > Closed

@ghsecuritylab
Copy link
Collaborator

Your submission is now in status SecLab finalize.

For information, the evaluation workflow is the following:
SecLab review > Generate Query Results > FP Check > CodeQL review > SecLab finalize > Pay > Closed

@ghsecuritylab
Copy link
Collaborator

Your submission is now in status Pay.

For information, the evaluation workflow is the following:
SecLab review > Generate Query Results > FP Check > CodeQL review > SecLab finalize > Pay > Closed

@xcorail
Copy link
Contributor

xcorail commented Jul 2, 2021

Created Hackerone report 1250306 for bounty 314830 : [222] [Java]: CWE 295 - Insecure TrustManager - MiTM

@xcorail xcorail closed this as completed Jul 2, 2021
@ghsecuritylab
Copy link
Collaborator

Your submission is now in status Closed.

For information, the evaluation workflow is the following:
SecLab review > Generate Query Results > FP Check > CodeQL review > SecLab finalize > Pay > Closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
All For One Submissions to the All for One, One for All bounty
Projects
None yet
Development

No branches or pull requests

7 participants
@smowton @xcorail @m-y-mo @luchua-bc @intrigus-lgtm @ghsecuritylab and others