CVE-2021-24105
Malicious packages can be inserted into repositories, leading to RCE.
- CVSS 8.4
- CWE-1104
- Configuration Issues
- **Remo
<p>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.</p> <p><strong>Attack scenarios</strong></p> <p>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, <a href="https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610">Dependency Confusion: How I Hacked Into Apple, Microsoft and Dozens of Other Companies</a>.</p> <ul> <li><p>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.</p> </li> <li><p>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.</p> </li> </ul> <p>These two methods could affect target organizations at any of these various levels:</p> <ul> <li>Developer machines</li> <li>An entire team if the configuration to import the malicious package is uploaded to a code repository</li> <li>Continuous integration pipelines if they pull the malicious packages during the build, test, and/or deploy stages</li> <li>Customers, download servers, production services if the malicious code has not been detected</li> </ul> <p>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 <strong>FAQ</strong> section of this CVE for configuration guidance.</p>
- CWE
- CWE-1104
- CVSS base score
- 8.4
- Published
- 2021-02-25
- OWASP
- A09 Security Misconfiguration
- Orthogonal defect classification
- Build/Package/Merge
- Code defect classification
- **Incorrect Functionalit
- Category
- Configuration Issues
- Subcategory
- I don't know!
- Accessibility scope
- **Remo
- Impact
- Arbitrary Code Execution
- Affected component
- Python/pip
Solution
I don't know!
Vulnerable code sample
import subprocess
def install(package_name):
"""Vulnerable function that demonstrates the security issue."""
# VULNERABLE: This code is susceptible to sql injection
subprocess.run(["pip", "install", package_name], check=True)
install("package")Patched code sample
import subprocess
ALLOWED_PACKAGES = {"package1", "package2", "package"}
def install(package_name):
"""Secure function that fixes the vulnerability."""
if package_name not in ALLOWED_PACKAGES:
raise ValueError("Package installation is not allowed.")
subprocess.run(["pip", "install", package_name], check=True)
install("package")Payload
import os
# Malicious payload example for demonstration purposes
def malicious_install_script():
# This code simulates a malicious action
os.system("echo 'Malicious code executed!'")
# Simulating the installation of a malicious package
if __name__ == "__main__":
malicious_install_script()
Cite this entry
@misc{vaitp:cve202124105,
title = {{Malicious packages can be inserted into repositories, leading to RCE.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-24105},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-24105/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
