Skip to content
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

Java: Query for detecting unsafe deserialization with Spring exporters #289

Closed
1 task done
artem-smotrakov opened this issue Feb 27, 2021 · 17 comments
Closed
1 task done
Labels
All For One Submissions to the All for One, One for All bounty

Comments

@artem-smotrakov
Copy link

artem-smotrakov commented Feb 27, 2021

CVE ID(s)

Not yet.

Report

Spring Framework provides an abstract base class RemoteInvocationSerializingExporter for defining remote service exporters. A Spring exporter, which is based on this class, deserializes incoming data using ObjectInputStream. Deserializing untrusted data (CWE-502) is easily exploitable and in many cases allows an attacker to execute arbitrary code. Spring Framework also provides two classes that extend RemoteInvocationSerializingExporter:

  • HttpInvokerServiceExporter
  • SimpleHttpInvokerServiceExporter

CVE-2016-1000027 has been assigned to this issue in Spring Framework. There is no fix for that.

I'd like to propose a new experimental query that looks for unsafe deserialization with Spring exporters:

github/codeql#5260

Many projects have received alerts about CVE-2016-1000027 from security scanners. Since Spring Framework didn't address the issue, they can't just update Spring Framework. Instead, they have to understand the issue and check their code. This query can make their life easier and help them check the code. Moreover, the query can detect unsafe exporters even without scanners that look for known vulnerabilities.

  • 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

I wrote a blog post about detecting unsafe deserialization with Spring exporters with CodeQL.

Result(s)

@artem-smotrakov artem-smotrakov added the All For One Submissions to the All for One, One for All bounty label Feb 27, 2021
@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

@pwntester
Copy link
Contributor

Thanks for the submission @artem-smotrakov!

The query as is is only returning two results in LGTM. I think it is mostly due to these exporters being mostly used in XML-based configurations. Can you please extend the submission to account for XML declared exporters?

@artem-smotrakov
Copy link
Author

That would be a good improvement but I thought CodeQL can't parse XML files. I'll look into it. Meanwhile, please let me know if you have an example of a query that checks XML files.

@pwntester
Copy link
Contributor

There are probably better examples but one using SpringBean class is UnusedBean

@artem-smotrakov
Copy link
Author

Thanks @pwntester !

@artem-smotrakov
Copy link
Author

@pwntester I've updated the query to detect vulnerable exporters in XML configs -- thanks for the suggestion! I realized it is not possible to use both Method and SpringBean in select, and it is not possible to cast XMLElement to Element. To overcome this, I use File in select. I am not sure whether this is the best solution or not. Another option is just to write two separate queries. Please let me know if you have a better idea.

@pwntester
Copy link
Contributor

I think that reporting on the File can be confusing for users, so it would be better to split it into two separate queries. But I leave that to the CodeQL experts /cc @smowton

@smowton
Copy link

smowton commented Mar 8, 2021

Two queries sounds right to me in this case

@artem-smotrakov
Copy link
Author

I'll split the query then. If I understand correctly, each query needs its own qhelp file as well.

@artem-smotrakov
Copy link
Author

@pwntester @smowton I've split the query. One selects Method, another one selects SpringBean. Please let me know what you think.

@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:
CodeQL initial assessment > SecLab review > CodeQL review > SecLab finalize > Pay > Closed

@artem-smotrakov
Copy link
Author

@xcorail
Copy link
Contributor

xcorail commented Mar 25, 2021

Hey @artem-smotrakov let me know when you tweet about your blog post ;-)

@artem-smotrakov
Copy link
Author

Hey @xcorail Just created a tweet :)

@ghsecuritylab
Copy link
Collaborator

Your submission is now in status Pay.

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

@xcorail xcorail closed this as completed Mar 25, 2021
@ghsecuritylab
Copy link
Collaborator

Your submission is now in status Closed.

For information, the evaluation workflow is the following:
CodeQL initial assessment > SecLab review > 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

5 participants