[Paper Review] An Empirical Study of Malicious Code In PyPI Ecosystem
This paper presents a large-scale empirical study of malicious code in the PyPI ecosystem, constructing a dataset of 4,669 malicious packages through automated collection from PyPI mirrors and other sources. It reveals that over 50% of malicious packages exhibit multiple behaviors—especially information stealing and command execution—and that 74.81% successfully infiltrate user projects via source code installation, with many persisting in mirrors long after discovery.
PyPI provides a convenient and accessible package management platform to developers, enabling them to quickly implement specific functions and improve work efficiency. However, the rapid development of the PyPI ecosystem has led to a severe problem of malicious package propagation. Malicious developers disguise malicious packages as normal, posing a significant security risk to end-users. To this end, we conducted an empirical study to understand the characteristics and current state of the malicious code lifecycle in the PyPI ecosystem. We first built an automated data collection framework and collated a multi-source malicious code dataset containing 4,669 malicious package files. We preliminarily classified these malicious code into five categories based on malicious behaviour characteristics. Our research found that over 50% of malicious code exhibits multiple malicious behaviours, with information stealing and command execution being particularly prevalent. In addition, we observed several novel attack vectors and anti-detection techniques. Our analysis revealed that 74.81% of all malicious packages successfully entered end-user projects through source code installation, thereby increasing security risks. A real-world investigation showed that many reported malicious packages persist in PyPI mirror servers globally, with over 72% remaining for an extended period after being discovered. Finally, we sketched a portrait of the malicious code lifecycle in the PyPI ecosystem, effectively reflecting the characteristics of malicious code at different stages. We also present some suggested mitigations to improve the security of the Python open-source ecosystem.
Motivation & Objective
- To address the lack of publicly available, high-quality datasets for malicious PyPI packages.
- To investigate the lifecycle of malicious code in the PyPI ecosystem, from development to user infiltration.
- To analyze the behavioral patterns, evasion techniques, and real-world impact of malicious packages.
- To provide actionable insights for improving detection and mitigation in the Python open-source ecosystem.
Proposed method
- Built an automated data collection framework to gather malicious packages from PyPI mirrors and multiple external sources.
- Constructed a multi-source dataset of 4,669 malicious code instances, including full packages, code snippets, and malware samples.
- Classified malicious packages into five behavior-based categories using static and dynamic analysis.
- Employed heuristic and machine learning techniques to detect malicious commands and backdoors in Python source code.
- Tracked package propagation through source code installation and analyzed persistence in global PyPI mirrors.
- Conducted real-world case studies to assess the impact and infiltration patterns of malicious packages on end-user systems.
Experimental results
Research questions
- RQ1RQ1: What are the primary attributes and sources of malicious code in the PyPI ecosystem, and how do they compare to other platforms?
- RQ2RQ2: How do attackers combine various attack strategies and malicious behaviors when injecting code into open-source packages, and how do these tactics evolve across platforms?
- RQ3RQ3: How effective are existing detection tools at identifying malicious packages, and what evasion methods do malicious packages use to bypass them?
- RQ4RQ4: What is the impact and infiltration mechanism of malicious packages on end-user systems, and which operating systems are primarily targeted?
Key findings
- Over 50% of malicious packages in the PyPI ecosystem exhibit multiple malicious behaviors, with information stealing and command execution being the most prevalent.
- 74.81% of malicious packages successfully entered end-user projects through source code installation, indicating a major attack vector.
- More than 72% of reported malicious packages remained accessible on global PyPI mirror servers for extended periods after discovery.
- Malicious packages primarily target Linux systems, suggesting platform-specific exploitation strategies.
- Attackers employ a range of anti-detection techniques, including code obfuscation and dynamic payload delivery, to evade static and dynamic analysis tools.
- The study identified novel attack vectors, such as supply chain poisoning via mismatched source code and package binaries, highlighting systemic risks in the software supply chain.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.