-
Notifications
You must be signed in to change notification settings - Fork 3k
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
How to reproduce CVE-2021-3572? #10042
Comments
If the tag you're trying to hijack is AAAA, to instead provide the user with the revision BBBB, you'd need to do something like:
With this, when pip is trying to install from AAAA, it will instead misparse that tag and install using the revision BBBB. |
Yea, basically. It is fixing a logical mistake in the parsing of the tags, which could be used to inject malicious tags on repositories in a manner that's specific to pip, and is non-trivial for repository hosting services to defend against (if they choose to do so). |
Thanks for the explanation! Now, I see that the first sentence in the PR confused me:
I've created a repository we can use to test the vulnerability: https://github.com/frenzymadness/CVE-2021-3572 There is a short description about the repository and the vulnerability. If you want to, use it in your own tests. |
From my point of view, this issue can be closed now. |
By the way, to exploit the vulnerability in older pip (like 9.0.3) the tag has to look different because the old version uses |
To add more info to my latest comment. Older pip (<10) uses a different approach to get an output of That means, that older pips are even more vulnerable because all you need to do is to create a tag with some blank character at the end of its name. When pip parses the output the two tags look the same for pip because the blank character is stripped during processing the output of the command which means that the one appearing later in the output is the one that will be in the final mapping between tags and hashes. |
@frenzymadness I'm trying to patch v9.0.1 for this CVE and the problem is even more complicated there. Because |
@skazi0 I've discovered the same. I was thinking about making the |
@frenzymadness This is my patch: https://github.com/skazi0/CVE-2021-3572/blob/master/CVE-2021-3572-v9.0.1.patch |
Good job. Your patch looks very good to me and it seems that is not that complex so I'll have to fix also the ancient pip versions in our RPM packages. |
Closing since there’s nothing actionable for pip’s maintainers here, but I’m glad you’ve been able to reproduce this and come up with backports! I’ll add a test for this when I’m able to find the time to do so. |
I'm trying to understand the CVE-2021-3572 which was fixed by #9827 and create a test (reproducer) for it. The CVE is reserved but without further details yet: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3572
I think that if an attacker can gain an access to a git repository from which a user installs a package, there is no need to create some special tags to hijack commit-based pin on a user side.
Let me demonstrate that it can work also with the latest version of pip with no usage of the special Unicode characters in tags.
pip install git+https://gitlab.cee.redhat.com/lbalhar/marshalparser.git@b5f61d773ca28f7afb2bb5623d142ee27e3daecf
. Because the sha hash points to the specific commit in the git repository, I always have the same version installed.b5f61d773ca28f7afb2bb5623d142ee27e3daecf
.Full log:
Could please somebody explain to me why would an attacker need to use some special Unicode linebreak characters in a tag name to hijack the commit-based requirement if there is a possibility to do it in the described simple way?
The truth is that these simple steps do not work for me on Github because Github does not allow branches or tags to have names looking like commit hashes:
So, is the fix in the pip needed for Github, where you cannot use the described attack in the simple way?
The text was updated successfully, but these errors were encountered: