Skip to content
RCE Advisory Intermediate CVE-2021-24105

Package Managers Configurations Remote Code Execution Vulnerability (CVE-2021-24105)

Package managers can be configured to prefer public repositories over private ones, allowing an attacker to publish a malicious package with a higher version number that gets downloaded and executed. This can lead to remote code execution on developer machines, CI pipelines, or production systems.

Alex Birsan Follow

Originally disclosed on Microsoft

High 8.4 View original

Description

Depending on configuration of various package managers it is possible for an attacker to insert a malicious package into a package manager's repository which can be retrieved and used during development, build, and release processes. This insertion could lead to remote code execution. We believe this vulnerability affects multiple package managers across multiple languages, including but not limited to: Python/pip, .NET/NuGet, Java/Maven, JavaScript/npm. Attack scenarios An attacker could take advantage of this ecosystem-wide issue to cause harm in a variety of ways. The original attack scenarios were discovered by Alex Birsan and are detailed in their whitepaper, Dependency Confusion: How I Hacked Into Apple, Microsoft and Dozens of Other Companies . With basic knowledge of the target ecosystems, an attacker could create an empty shell for a package and insert malicious code in the install scripts, give it a high version, and publish it to the public repository. Vulnerable victim machines will download the higher version of the package between the public and private repositories and attempt to install it. Due to code incompatibility it will probably error out upon import or upon compilation, making it easier to detect; however the attacker would have gained code execution by that point. An advanced attacker with some inside knowledge of the target could take a copy of a working package, insert the malicious code (in the package itself or in the install), and then publish it to a public repository. The package will likely install and import correctly, granting the attacker an initial foothold and persistence. These two methods could affect target organizations at any of these various levels: Developer machines An entire team if the configuration to import the malicious package is uploaded to a code repository Continuous integration pipelines if they pull the malicious packages during the build, test, and/or deploy stages Customers, download servers, production services if the malicious code has not been detected This remote code execution vulnerability can only be addressed by reconfiguring installation tools and workflows, and not by correcting anything in the package repositories themselves. See the FAQ section of this CVE for configuration guidance.

FAQ

How do I protect my systems or organization from this vulnerability? This remote code execution vulnerability can only be addressed by reconfiguring installation tools and workflows, and not by correcting anything in the package repositories themselves. Some package repositories may be able to reduce the likelihood of a successful attack. Where can I find guidance for configuring my installation tools and workflows to be protected from this vulnerability? Depending on the package manager used and how it is configured, there are several mitigations available to protect against this vulnerability. Follow the guidance for your specific language as outlined in 3 Ways to Mitigate Risk Using Private Package Feeds See also Changes to Azure Artifact Upstream Behavior . References 3 Ways to Mitigate Risk Using Private Package Feeds Changes to Azure Artifact Upstream Behavior Dependency Confusion: How I Hacked Into Apple, Microsoft and Dozens of Other Companies .

Developer Tools

Developer Tools

Microsoft

Microsoft

The original report as published on the Microsoft Security Response Center, by Alex Birsan. Images and videos are our own copies; raw HTML is shown as text. View it on Microsoft Security Response Center.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely misconfiguration of package managers that prioritise public repositories over private ones, allowing dependency confusion.

Impact

An attacker could gain code execution on developer machines, entire teams, CI pipelines, or production services, though the malicious package may error out upon import or compilation, making it easier to detect.

What the attacker needed

Knowledge of target package names; ability to publish to public repository; victim uses vulnerable configuration

The fix

The vulnerability should be fixed by reconfiguring installation tools and workflows, not by changing package repositories.

How it was found

  1. Create an empty shell for a package and insert malicious code in the install scripts.
  2. Give it a high version and publish it to the public repository.
  3. Vulnerable victim machines download the higher version between public and private repositories and attempt to install it.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Package managers like pip or npm fetch code libraries from online repositories. If a company uses a private package with the same name as a public one, and the tool is set to prefer the public source, an attacker can upload a malicious version with a higher version number. The tool then downloads and runs the attacker's code, giving them control of the machine.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from Microsoft

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.