Cutting the Gordian Knot: Detecting Malicious PyPI Packages via a Knowledge-Mining Framework

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Guo, Wenbo, Liu, Chengwei, Kang, Ming, Zhang, Yiran, Wu, Jiahui, Xu, Zhengzi, Sachidananda, Vinay, Liu, Yang
Format: Preprint
Veröffentlicht: 2026
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866908790053404672
author Guo, Wenbo
Liu, Chengwei
Kang, Ming
Zhang, Yiran
Wu, Jiahui
Xu, Zhengzi
Sachidananda, Vinay
Liu, Yang
author_facet Guo, Wenbo
Liu, Chengwei
Kang, Ming
Zhang, Yiran
Wu, Jiahui
Xu, Zhengzi
Sachidananda, Vinay
Liu, Yang
contents The Python Package Index (PyPI) has become a target for malicious actors, yet existing detection tools generate false positive rates of 15-30%, incorrectly flagging one-third of legitimate packages as malicious. This problem arises because current tools rely on simple syntactic rules rather than semantic understanding, failing to distinguish between identical API calls serving legitimate versus malicious purposes. To address this challenge, we propose PyGuard, a knowledge-driven framework that converts detection failures into useful behavioral knowledge by extracting patterns from existing tools' false positives and negatives. Our method utilizes hierarchical pattern mining to identify behavioral sequences that distinguish malicious from benign code, employs Large Language Models to create semantic abstractions beyond syntactic variations, and combines this knowledge into a detection system that integrates exact pattern matching with contextual reasoning. PyGuard achieves 99.50% accuracy with only 2 false positives versus 1,927-2,117 in existing tools, maintains 98.28% accuracy on obfuscated code, and identified 219 previously unknown malicious packages in real-world deployment. The behavioral patterns show cross-ecosystem applicability with 98.07% accuracy on NPM packages, demonstrating that semantic understanding enables knowledge transfer across programming languages.
format Preprint
id arxiv_https___arxiv_org_abs_2601_16463
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle Cutting the Gordian Knot: Detecting Malicious PyPI Packages via a Knowledge-Mining Framework
Guo, Wenbo
Liu, Chengwei
Kang, Ming
Zhang, Yiran
Wu, Jiahui
Xu, Zhengzi
Sachidananda, Vinay
Liu, Yang
Cryptography and Security
Software Engineering
The Python Package Index (PyPI) has become a target for malicious actors, yet existing detection tools generate false positive rates of 15-30%, incorrectly flagging one-third of legitimate packages as malicious. This problem arises because current tools rely on simple syntactic rules rather than semantic understanding, failing to distinguish between identical API calls serving legitimate versus malicious purposes. To address this challenge, we propose PyGuard, a knowledge-driven framework that converts detection failures into useful behavioral knowledge by extracting patterns from existing tools' false positives and negatives. Our method utilizes hierarchical pattern mining to identify behavioral sequences that distinguish malicious from benign code, employs Large Language Models to create semantic abstractions beyond syntactic variations, and combines this knowledge into a detection system that integrates exact pattern matching with contextual reasoning. PyGuard achieves 99.50% accuracy with only 2 false positives versus 1,927-2,117 in existing tools, maintains 98.28% accuracy on obfuscated code, and identified 219 previously unknown malicious packages in real-world deployment. The behavioral patterns show cross-ecosystem applicability with 98.07% accuracy on NPM packages, demonstrating that semantic understanding enables knowledge transfer across programming languages.
title Cutting the Gordian Knot: Detecting Malicious PyPI Packages via a Knowledge-Mining Framework
topic Cryptography and Security
Software Engineering
url https://arxiv.org/abs/2601.16463