Skip to content

[Python] Unsafe unpacking using shutil.unpack_archive() query and tests #719

Closed

Description

@Sim4n6

Query PR

github/codeql#11570

Language

Python

CVE(s) ID list

CWE

CWE-022

Report

  1. Unsafe unpacking of a tarball retrieved from a remote location.
  2. A remotely downloaded tarball may be malicious and contains filename paths with relative path .. or absolute paths starting with /. It seems that shutil.unpack_archive() does unpack tarballs with extensions .tar, .tar.gz, .tar.xz, .tar.bz2, or .gztar in an unsafe way. Which leads to the extraction of files within the tarball to an unintended folder.
  3. I use a simple fact:
  • Source: remote HTTP client request.
  • Sink a call to shutil.unpack_archive().
  • additional taint steps: opening and writing the response to a tarball.
  1. Well, I removed a couple of in the python standard library cases.
  2. This CodeQL query is very specific but since the shutil.unpack_archive() is unsafe, it could be extended to more sources. Here, I considered a remotely retrieved tarball, but in fact, any tarball input could be identified as malicious. For instance, a CLI tool that takes a path to a tarball in the filesystem is not yet identified with this CodeQL query.

Are you planning to discuss this vulnerability submission publicly? (Blog Post, social networks, etc).

  • Yes
  • No

Blog post link

https://www.getrevue.co/profile/sim4n6

Activity

  1. added
    All For OneSubmissions to the All for One, One for All bounty
    on Dec 5, 2022
  2. Sim4n6 commented on Jan 2, 2023

    @Sim4n6
    Author

    I hate to say that but any update please related to this CodeQL query?

  3. pwntester commented on Jan 10, 2023

    @pwntester
    Contributor

    Hi @Sim4n6, thanks for yet another submission!

    Sorry this one is taking so long but there was an ongoing inter-team discussion and, because of the different xmas breaks, it took longer to have everyone onboard. The query, as it is now, does not meet the minimum scope criteria to make it eligible for a bounty. We have been discussing different possibilities such as combining with other existing queries or making it a semantic query. While looking into the sink, @JarLob spotted that there are other similar and also vulnerable sinks (eg: tarfile and zipfile) that could be added to this query so increase its scope. Adding support for these additional sinks would increase the scope score and make it eligible. Would you willing to do so?

  4. Sim4n6 commented on Jan 10, 2023

    @Sim4n6
    Author

    Sure why not, but one detail please tarslip and zipslip queries are already available in the experimental queries do you suggest that I update them accordingly to consider the shutil.unpack sink? 😃

  5. pwntester commented on Jan 10, 2023

    @pwntester
    Contributor

    Yep, I think it would make sense to integrate this one into the tarslip one by creating a new source that includes all the cases you considered. So the new source would be either the creation of a new TarFile or a path coming from the sources you collected.

    The problem here is that your source may be incomplete and therefore we may not report some issues. We could just report all calls to unpack_archive() but such simple semantic query would not meet the acceptance criteria. We think that there is value in the source and taintsteps you wrote and therefore will accept it as an extension of the existing tarslip query

  6. Sim4n6 commented on Jan 10, 2023

    @Sim4n6
    Author

    Perfect, I will be working on that

  7. pwntester commented on Jan 18, 2023

    @pwntester
    Contributor

    Hi @Sim4n6 we have decided to accept the query as is since merging it with the existing one would be mixing sources and sinks that were not really meant to work together. There is nothing for you to do. Thanks for the contribution!

  8. Sim4n6 commented on Jan 18, 2023

    @Sim4n6
    Author

    Great thank you @pwntester I was going crazy with that... By the way, I have identified at least 03 CVEs with the query.

  9. ghsecuritylab commented on Jan 18, 2023

    @ghsecuritylab
    Collaborator

    Your submission is now in status Test run.

    For information, the evaluation workflow is the following:
    Initial triage > Test run > Results analysis > Query review > Final decision > Pay > Closed

  10. Sim4n6 commented on Feb 2, 2023

    @Sim4n6
    Author

    Hi @pwntester,

    I'm getting more potential CVEs assigned with the modified version of the query, and I would like to consider the sinks and the sources (as additional steps) from the TarSlip into the UnsafeUnpack query. It would look to me much more as modeling a whole and a viable attack from a RemoteFlowSource to an unsafe extraction. May the new query be considered for a higher bounty in that case, please? or do you suggest that I constrain the UnpackUnsafe for the sink shutil.unpack_archive() and apply for the bug slayer program, next?

    Please, how do you suggest that I proceed?

  11. pwntester commented on Feb 2, 2023

    @pwntester
    Contributor

    Hi @Sim4n6,

    That would increase the Scope of the query for sure. However, the scope is not the only element considered for the bounty level so I cant assure you that a higher scope level will transform into a higher bounty level. I encourage you to do so and at the same time, submit for the Bug Slayer program if you meet the criteria

  12. Sim4n6 commented on Feb 2, 2023

    @Sim4n6
    Author

    No problem, I will add the TarSlip sinks&sources to the UnsafeUnpack query. And latter apply for the Bug slayer. Thanks

  13. ghsecuritylab commented on Feb 21, 2023

    @ghsecuritylab
    Collaborator

    Your submission is now in status Query review.

    For information, the evaluation workflow is the following:
    Initial triage > Test run > Results analysis > Query review > Final decision > Pay > Closed

  14. ghsecuritylab commented on Feb 24, 2023

    @ghsecuritylab
    Collaborator

    Your submission is now in status Final decision.

    For information, the evaluation workflow is the following:
    Initial triage > Test run > Results analysis > Query review > Final decision > Pay > Closed

  15. Sim4n6 commented on Mar 3, 2023

    @Sim4n6
    Author

    So what is the final ruling on the matter, please?

  16. ghsecuritylab commented on Mar 9, 2023

    @ghsecuritylab
    Collaborator

    Your submission is now in status Pay.

    For information, the evaluation workflow is the following:
    Initial triage > Test run > Results analysis > Query review > Final decision > Pay > Closed

  17. xcorail commented on Mar 9, 2023

    @xcorail
    Contributor

    Created Hackerone report 1898441 for bounty 463052 : [719] [Python] Unsafe unpacking using shutil.unpack_archive() query and tests

  18. ghsecuritylab commented on Mar 9, 2023

    @ghsecuritylab
    Collaborator

    Your submission is now in status Closed.

    For information, the evaluation workflow is the following:
    Initial triage > Test run > Results analysis > Query review > Final decision > Pay > Closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    All For OneSubmissions to the All for One, One for All bounty

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions