The Shai-Hulud 2.0 npm Worm: A Deep Dive into One of the Largest Supply Chain Attacks Ever
- Akshay Jain
- 13 hours ago
- 3 min read
Why the Shai-Hulud 2.0 npm Worm Matters?
The Shai-Hulud 2.0 npm worm represents a shocking escalation in software supply chain attacks, a malware campaign that doesn't just lie dormant in one package, but self-propagates like a biological worm, infecting npm packages, harvesting credentials, and compromising developer environments and CI/CD systems at massive scale.
Unlike traditional malware that relies on command and control servers or manual operator interaction, this worm operates autonomously, leveraging developers own credentials to publish further infected packages and expand its reach. These traits make it one of the most dangerous JavaScript ecosystem attacks ever observed, with consequences for both application security and cloud infrastructure risk.

What Is the Shai-Hulud 2.0 npm Worm?
Shai-Hulud 2.0 is a self-replicating malware worm targeting the npm ecosystem - a centralized registry of JavaScript libraries used in millions of projects worldwide.
Key Traits of the Worm:
Supply Chain Compromise: Attackers inject malicious code into legitimate npm packages and republish them to the official registry.
Self-Propagation without C2: After infection, the worm uses the victim's npm or GitHub credentials to publish new malicious versions of packages automatically, enabling exponential spread.
Credential Harvesting & Exfiltration: Once executed, the malware scans for sensitive credentials such as GitHub tokens, npm tokens, cloud provider keys (AWS, GCP, Azure), and CI/CD secrets, exfiltrating them to public repositories created by the worm.
Preinstall Execution: Unlike earlier versions, Shai-Hulud 2.0 uses npm’s preinstall script hook, meaning it executes before installation even starts
Destructive Fallback: If it cannot propagate or exfiltrate data, the worm may attempt to delete the user's home directory, adding a ransomware-like destructive element.
Technical Breakdown: How the Worm Works
Initial Package Compromise
Attackers gain access to package maintainer accounts, often through stolen credentials, phishing, or compromised CI/CD automation tokens.
Once access is obtained, the attacker injects malicious files into existing packages, typically:
setup_bun.js
bun_environment.js
And adds a preinstall script that executes automatically when npm install runs.
Malware Execution on Client Systems
During installation, the preinstall script triggers installation of Bun (an alternative JavaScript runtime used to evade Node.js focused detection).
Execution of the obfuscated payload (bun_environment.js), which begins scanning the environment for credentials.
Credential Harvesting
The worm leverages tools like TruffleHog or custom scanning logic to search for:
NPM authentication tokens
GitHub personal access tokens
AWS, Azure, GCP keys
SSH keys
CI/CD environment variables
Exfiltration to Public GitHub Repositories
Using harvested GitHub credentials, the malware
Creates public repositories associated with victims accounts
Names them with campaign markers like "Sha1-Hulud: The Second Coming"
Publishes credential dumps and environment snapshots
Autonomous Replication
Using the victim's npm credentials, the worm:
Identifies packages the user is authorized to publish
Injects malicious files into those packages
Publishes new versions to npm
If the worm fails to propagate or find credentials, a built-in "scorched earth" fallback may erase the user's home directory
Real-World Impact & Case Study
Multiple security vendors and researchers including Wiz, Microsoft, Datadog, and Palo Alto Unit 42 have documented Shai-Hulud 2.0 as one of the largest and most aggressive supply chain compromises in the npm ecosystem.
Statistics & Scope
~800 npm packages compromised
Over 25,000+ infected GitHub repositories discovered in rapid spread
Developer secrets leaked in thousands of public repos
Compromise of CI/CD pipelines
Indicators of Compromise (IOCs)
Known artifact files:
setup_bun.js
bun_environment.js
Unexpected preinstall scripts in trusted packages
Newly created repos with names or descriptions containing "Shai-Hulud" or variants
CI/CD signals
Unexpected self-hosted runners named like SHA1HULUD
Unauthorized pipeline triggers or workspace modifications
Mitigation & Prevention: Reducing Supply Chain Risk
Use package lockfiles to ensure only vetted versions are installed.
Rotate API tokens and keys frequently
Restrict workflow permissions
Code review enforcement before automated script runs
Disable auto-execution of untrusted scripts
Incorporate tools that scan dependencies for malicious code
Use npm’s new trusted publisher model or scoped publish access to limit the blast radius if compromise occurs.
The Shai-Hulud 2.0 npm worm represents an inflection point in software supply chain threats, a malware that thinks like a worm, exploits trusted developer credentials, and leverages modern CI/CD workflows to spread far beyond a single machine or package.
For developers and security teams alike, this campaign underscores a powerful truth: your software supply chain is only as secure as the weakest process in your pipeline. By combining rigorous dependency management, credential hygiene, CI/CD hardening, and proactive monitoring, organizations can reduce exposure to this new breed of automated, credential-stealing worms.
Happy cyber-exploration! 🚀🔒
Note: Feel free to drop your thoughts in the comments below - whether it's feedback, a topic you'd love to see covered, or just to say hi! Don’t forget to join the forum for more engaging discussions and stay updated with the latest blog posts. Let’s keep the conversation going and make cybersecurity a community effort!
-AJ