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.
翻译:PyPI为开发者提供了便捷易用的包管理平台,使其能够快速实现特定功能并提升工作效率。然而,PyPI生态系统的快速发展导致恶意包传播问题日益严重。恶意开发者将恶意包伪装成正常包,对终端用户构成重大安全风险。为此,我们开展了一项实证研究,旨在理解PyPI生态系统中恶意代码生命周期特征与现状。我们首先构建了自动化数据采集框架,整理出包含4,669个恶意包文件的多源恶意代码数据集。基于恶意行为特征,我们将这些恶意代码初步划分为五大类别。研究发现,超过50%的恶意代码表现出多种恶意行为,其中信息窃取与命令执行尤为常见。此外,我们还观察到若干新型攻击向量与反检测技术。分析表明,所有恶意包中有74.81%通过源码安装方式成功侵入终端用户项目,从而增加了安全风险。实际调查显示,众多被报告的恶意包仍持续存在于全球PyPI镜像服务器中,超过72%的恶意包在被发现后仍长期留存。最后,我们描绘了PyPI生态系统中恶意代码的生命周期画像,有效反映了不同阶段恶意代码的特征。我们还提出了一些缓解建议,以提升Python开源生态系统的安全性。