DySec: A Machine Learning-Based Dynamic Analysis for Detecting Malicious Packages in PyPI Ecosystem

Sk. Tanzir Mehedi, Chadni Islam, Gowri Sankar Ramachandran, Raja Jurdak

TL;DR

DySec is a machine learning framework that uses eBPF (extended Berkeley Packet Filter) to catch malicious Python packages by monitoring their behavior in real-time during installation. By shifting from static code inspection to dynamic analysis, it achieves a 95.99% detection accuracy and has already successfully identified several live threats on PyPI that traditional scanners missed.

What Problem Does This Paper Address?

The Python Package Index (PyPI) is a cornerstone of modern software development, but its openness makes it a prime target for supply chain attacks. Traditional security measures usually rely on metadata analysis (checking package details like author or version) or static analysis (inspecting source code without running it).

However, attackers have become sophisticated. They use techniques like typosquatting (naming a malicious package pyth0n-dateutil instead of python-dateutil) and dynamic payload generation, where the malicious code is only created and executed during the pip install process. Furthermore, static analysis often fails to detect "indirect dependencies"—malicious code buried deep within a chain of legitimate-looking packages.

Figure 2: Dependency graphs showing how indirect malicious dependencies can hide within nested chains.

Methods

The authors introduce DySec, a framework that prioritizes behavior over appearance. Its core innovation is the use of eBPF kernel and user-level probes. eBPF is a revolutionary technology that allows programs to run in the Linux kernel without changing kernel source code or loading modules. This enables DySec to perform lightweight, real-time monitoring of:

  • System calls: Every time a package asks the OS to do something (like open a file or start a process).
  • Network traffic: Detecting unauthorized connections to attacker-controlled servers.
  • Resource usage: Identifying unusual spikes in CPU or memory.
  • Directory access: Watching for attempts to read sensitive files like SSH keys.

The DySec workflow consists of four phases: (i) data collection, (ii) dynamic trace extraction in an isolated sandbox, (iii) data processing and ML model training, and (iv) real-time detection.

Figure 3: The overall workflow of DySec, from data collection to real-time detection.

Datasets

The researchers developed a comprehensive dataset of 14,271 Python packages, consisting of:

  • 7,127 malicious samples: Collected from security blogs and threat intelligence feeds, then cross-referenced with 62 security vendors via VirusTotal.
  • 7,144 benign samples: Popular packages from PyPI verified as non-malicious.

Each package was executed in a controlled, isolated Raspberry Pi cluster to capture 36 real-time features across six categories, creating a robust benchmark for dynamic behavior.

Key Insights and Ideas

  • Install-time is the critical window: Many malicious packages are "sandbox-aware" or use encoded strings to hide their true intent until the moment of installation. DySec’s focus on the installation phase captures these "ephemeral" threats.
  • eBPF is the "Right Tool": Unlike traditional monitoring tools like Wireshark or Sysdig, eBPF provides deep visibility into kernel operations with negligible performance overhead, making it practical for high-scale environments.
  • PatternTraces are highly predictive: The researchers found that sequential system call patterns (e.g., a specific sequence of file opens followed by a network connection) are incredibly strong indicators of malicious intent, often achieving F1 scores above 0.98 for specific patterns.
  • Bridging the Gap: DySec significantly reduces "blind spots" in the supply chain by identifying malicious behaviors in nested dependencies that static tools simply cannot see.

Key Results

DySec outperformed existing state-of-the-art methods across the board:

  • Accuracy: Achieved 95.99% detection accuracy using a Random Forest model.
  • Latency: Detection happens in less than 0.5 seconds, making it fast enough for real-world deployment.
  • False Negative Reduction: Reduced false negatives by 78.65% compared to static analysis and 82.24% compared to metadata analysis.
  • Real-world Impact: During evaluation, DySec flagged 11 packages previously classified as benign on PyPI. Manual inspection confirmed 6 were indeed malicious, leading to the removal of 4 packages by PyPI maintainers.
Figure 6: ROC AUC curves comparing metadata, static, and dynamic analysis, showing DySec's superior discriminatory power.

Limitations and Future Work

While powerful, DySec has a few hurdles to clear:

  • Platform Dependency: eBPF is currently exclusive to the Linux kernel, meaning DySec cannot natively monitor installations on Windows or macOS without virtualization.
  • Resource Intensity: Setting up isolated sandboxes for dynamic execution requires significant computational resources compared to simple static scans.
  • Evasion Tactics: Sophisticated malware could potentially detect the eBPF probes or delay its malicious activity even further to bypass the 120-second monitoring window used in this study.

The authors plan to address these by developing a user-friendly platform for PyPI maintainers and exploring multi-modal analysis that combines dynamic traces with domain-specific behavioral modeling.

Summary updated

BibTeX
@article{mehedi2026dysec,
  author = {Sk. Tanzir Mehedi and Chadni Islam and Gowri Sankar Ramachandran and Raja Jurdak},
  title = {{DySec: A Machine Learning-Based Dynamic Analysis for Detecting Malicious Packages in PyPI Ecosystem}},
  journal = {IEEE Trans. Inf. Forensics Secur.},
  year = {2026},
  doi = {10.1109/tifs.2026.3654388},
}
Figure