Massive NPM Supply Chain Attack: Package Used to Deploy RAT Malware

Listen to this Post

Featured Image
A New Blow to Open Source Security: Here’s What Happened

A serious security breach has been uncovered in the widely-used npm package rand-user-agent, a tool that sees over 45,000 weekly downloads and is often leveraged in web scraping operations. Maintained by WebScrapingAPI, the package was discovered to be compromised with stealthy, malicious code hidden within recent versions. This breach represents a significant example of a supply chain attack targeting open-source ecosystems—an alarming trend that has grown rapidly in recent years.

Security researchers flagged the incident when anomaly detection engines found suspicious behavior in the dist/index.js file. Upon further inspection, heavily obfuscated code was found embedded in the file, bearing no resemblance to the last known clean version (2.0.82) hosted on GitHub. All newer versions diverged from the original source and contained malicious alterations.

De-obfuscating the rogue code revealed it to be a Remote Access Trojan (RAT) capable of installing dependencies without user consent, exfiltrating files, and executing remote shell commands. The RAT communicated with an attacker-controlled server and could remain hidden within a user’s local system, especially targeting Windows machines through environment PATH manipulation.

This incident highlights the escalating risk associated with automated dependency updates and emphasizes the need for robust integrity verification measures in modern development pipelines.

Summary of the Compromise (30 lines)

Package Involved: rand-user-agent, an npm module often used for web scraping.
Downloads Affected: Over 45,000 per week; significant global footprint.

Maintainer: WebScrapingAPI.

Nature of Attack: Supply chain compromise via npm.

Method of Detection: Flagged by anomaly detection in the dist/index.js file.
Version Last Known Clean: 2.0.82 (on GitHub, 7 months ago).

Malicious Versions: 1.0.110, 2.0.83, and 2.0.84.

Malware Type: Remote Access Trojan (RAT).

Code Obfuscation: Heavily layered and disguised from visual inspection.
C2 Communication: Persistent socket connection to attacker server at 85.239.62[.]36:3306.
File Theft Mechanism: Uses axios to exfiltrate data to 85.239.62[.]36:27017/u/f.
Dependency Manipulation: Installs axios and socket.io-client in a hidden .node_modules folder.
Command Execution: Via Node.js child_process, allowing shell and file operations.
Session Management: Supports queued commands, pausing, and process control.
Targeted OS Features: Windows PATH variable hijacking using fake Python directories.
Persistence Strategy: PATH manipulation redirects Python execution to attacker binaries.
Risk Level: High; particularly for enterprises using automated npm updates.

Recommended Actions:

Audit your project dependencies.

Remove and reinstall clean versions from GitHub.

Monitor network traffic for IOCs.

Inspect Windows PATH values for anomalies.

Hidden Install Path: `~/.node_modules`.

Stealth Features: Uses hidden directories and silent installations.

Victim Identification: Sends hostname, username, OS, and UUID to attacker.
Attack Sophistication: Highly organized, mimicking past supply chain attacks.
IOCs Published: Detailed indicators for C2, file paths, and versions.
GitHub Discrepancy: GitHub repo remains clean, diverged from npm builds.
Impact Scope: Global, due to high usage across automation and scraping tools.
Security Advice: Avoid blind trust in npm packages, especially those with obfuscation.
Developer Action: Stop using affected versions and rebuild from trusted sources.

Ecosystem Risk: Highlights ongoing threats to open-source infrastructure.

Call to Action: Follow best practices and stay updated via trusted security feeds.

What Undercode Say:

This breach underscores a pivotal truth: the open-source ecosystem, while revolutionary and empowering, is increasingly being targeted as a soft entry point for cyberattacks. The compromise of rand-user-agent wasn’t a simplistic malware injection. Instead, it represents a deeply embedded attack that leverages legitimate package update mechanisms to implant sophisticated spyware.

By breaking away from the GitHub source and quietly modifying npm-published packages, the attacker bypassed community visibility. This allowed malicious code to live undetected in production environments—potentially for weeks or months. Such a divergence between source repositories and published packages is one of the clearest indicators of modern supply chain subversion.

The use of obfuscation and hidden directories like .node_modules further complicates detection. Most developers would not expect npm install to quietly download and place files outside the visible dependency tree. Moreover, silently installing networking libraries like axios and socket.io-client—not listed in the package manifest—indicates deliberate stealth, not mere negligence.

Windows users faced an added layer of risk through the environment PATH hijack. This tactic could effectively reroute execution flows toward attacker-supplied Python binaries, paving the way for privilege escalation or data tampering. These tricks aren’t new, but their integration into a seemingly harmless npm module makes the attack all the more dangerous.

The real problem lies in trust—developers rely heavily on the perceived integrity of packages, especially those downloaded tens of thousands of times a week. Automation, while efficient, has also made it easier for such threats to propagate rapidly. If a CI/CD pipeline blindly accepts new versions, the attack surface expands dramatically.

Organizations must rethink their package management practices. Simply pinning dependency versions is not enough. Developers should verify package hashes, implement local mirrors for package repositories, and adopt anomaly detection in build systems. Continuous integrity monitoring and community-driven audits can help uncover tampering early.

This incident should also serve as a warning to the npm ecosystem: publishing controls need strengthening. While manual reviews may not scale, introducing automated integrity checks between GitHub and npm distributions could flag discrepancies in real time.

Ultimately, rand-user-agent is just the latest casualty in an escalating war on developer trust. Without proactive mitigation strategies, we risk losing the reliability that open-source software was built upon.

Fact Checker Results

Confirmed: The malicious code did exist only in the npm versions, not the GitHub source.
Verified: The RAT behavior, including file exfiltration and shell access, was successfully demonstrated.
Corroborated: IPs and techniques used match recent supply chain attacks in similar ecosystems.

Prediction

Supply chain attacks like this one will continue to escalate in complexity and frequency. As attackers evolve, they’ll likely move beyond obfuscation and begin mimicking legitimate development activity to evade detection even more effectively. In response, we predict a rise in next-gen package verification tools, source-to-distribution integrity checks, and community-driven security audits becoming standard practice across open-source ecosystems. Developers will also begin adopting zero-trust principles for dependency management, much like enterprise network security did in past decades.

References:

Reported By: cyberpress.org
Extra Source Hub:
https://www.pinterest.com
Wikipedia
Undercode AI

Image Source:

Unsplash
Undercode AI DI v2

Join Our Cyber World:

💬 Whatsapp | 💬 Telegram