用大模型增强图神经网络,精准识别恶意Python包的隐藏行为。
LLM-Enhanced Hierarchical Heterogeneous Graph Representation Learning for Malicious Python Package Detection

- 构建分层异构代码图,融合结构与语义信息。
- 在真实数据集上准确率显著优于现有方法。
- 自动定位可疑函数,适合安全研究人员使用。
由于PyPI等开源仓库的广泛使用,恶意Python包已成为软件供应链生态的主要威胁。现有基于学习的检测方法难以捕捉程序实体间的分层结构和异构交互。尽管大语言模型(LLMs)在代码理解与语义推理方面表现突出,但极少与程序结构表示结合用于细粒度恶意行为分析。本文提出一种基于LLM增强的分层异构图表示学习框架,用于恶意Python包检测。该框架构建了显式建模异构代码实体及多种结构依赖关系的分层异构代码图,并利用LLMs推断函数级语义角色,引入额外的语义异构性。在此基础上,设计分层异构图神经网络,实现针对不同节点与边类别的类型感知消息传递,有效建模恶意行为传播,完成包级别分类。框架还集成函数级归因机制,结合LLM推理,无需人工干预即可自动识别可疑函数并精确定位恶意行为。在真实世界数据集上的大量实验表明,该框架在不同大小与依赖复杂度的包上,持续优于传统机器学习方法、基于图的检测器以及最先进LLMs,同时提供准确、鲁棒且可解释的恶意行为定位。
原文摘要 · Abstract (English)
Malicious Python packages have become a major threat to software supply chain ecosystems due to the widespread adoption of open-source repositories such as PyPI. Existing learning-based detection methods struggle to capture the hierarchical organization and heterogeneous interactions among different program entities. Although Large Language Models (LLMs) have demonstrated strong capabilities in code understanding and semantic reasoning, they are rarely integrated with structural program representations for fine-grained malicious behavior analysis. In this paper, we propose an LLM-enhanced hierarchical heterogeneous graph representation learning framework for malicious Python package detection. The framework constructs a hierarchical heterogeneous code graph that explicitly models heterogeneous code entities and different types of structural dependencies. LLMs are further leveraged to infer function-level semantic roles, introducing an additional layer of semantic heterogeneity. Based on this graph, we develop a hierarchical heterogeneous graph neural network that performs type-aware message passing over different node and edge categories, effectively modeling malicious behavior propagation for accurate package-level classification. The framework also incorporates a function-level attribution mechanism which, combined with LLM reasoning, automatically identifies suspicious functions and localizes fine-grained malicious behaviors without human expert intervention. Extensive experiments on real-world datasets show that our framework consistently outperforms traditional machine learning methods, graph-based detectors, and state-of-the-art LLMs across packages with varying sizes and dependency complexities, while providing accurate, robust, and interpretable malicious behavior localization.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。