Cybersecurity · · 3 min read

Nascent Malware Campaign Targets npm, PyPI, and RubyGems Developers: A Deep Dive

Nascent Malware Campaign Targets npm, PyPI, and RubyGems Developers: A Deep Dive

In the ever-evolving landscape of cybersecurity, the Phylum Research Team has recently unearthed a nascent malware campaign that poses a significant threat to developers across multiple programming ecosystems—npm, PyPI, and RubyGems. This blog post aims to dissect the intricacies of this campaign, its modus operandi, and the potential risks it poses to the software development community.

The Discovery

Phylum's automated platform, which analyzes nearly a billion files across millions of packages in real-time, flagged the first package in this campaign on September 3, 2023. The package, named kwxiaodian, was found to contain malicious code designed to collect system information and exfiltrate it to a remote server.

Phylum's Cutting-Edge Detection Mechanism

Phylum's automated platform stands as a sentinel in the realm of open-source package management, scrutinizing nearly a billion files across millions of packages in real-time. This is no small feat; it's akin to having a cybersecurity SWAT team that never sleeps. On September 3, 2023, this platform flagged its first package in this insidious campaign: kwxiaodian. This package was not just another false positive; it was a well-crafted piece of malware designed to collect system information and exfiltrate it to a remote server.

Anatomy of the Malware: A Deep Technical Dive

Python Malware: The kwxiaodian Package

The Python package contained a file that was far from benign. This script was engineered to execute upon installation, a common but risky practice in package management. It contained a Python function that leveraged the os.popen() method to run shell commands, gathering various pieces of system information:

  • OS Version: Using uname -a, it fetches detailed information about the operating system.
  • User ID: The id command provides the user and group IDs.
  • Current Working Directory: Retrieved using the pwd command.
  • IP Address: Acquired via the ifconfig command.

The data is then Base64 encoded, a rudimentary form of obfuscation, and sent to a remote server. The server's IP address and port were hard-coded, pointing to

JavaScript Malware: npm's Stealthy Approach

The npm package took the Python package's modus operandi and added a layer of sophistication. Instead of merely Base64 encoding the data, it employed encryption algorithms to make the data more challenging to intercept and decipher. The package used a combination of native Node.js modules like https, os, and crypto to perform these operations.

The JavaScript code also included obfuscation techniques, making it harder for static analysis tools to flag it as malicious. The data was encrypted and then sent to the same remote server, mimicking the communication pattern seen in the Python package.

RubyGems Malware: Targeting macOS

The RubyGems package was specifically designed to execute only on macOS systems, as indicated by the if RUBY_PLATFORM.include?("darwin") condition. This package collected similar types of information but used Ruby's native Socket library to fetch the IP address and hostname. The data was then Base64 encoded and sent to a different port on the same remote server,

Cross-Ecosystem Commonalities

What's particularly alarming is the cross-ecosystem nature of this campaign. It's not confined to just one package manager; it spans npm, PyPI, and RubyGems. This indicates a level of planning and coordination that suggests the attackers are not amateurs but potentially part of a more extensive, organized operation.

By targeting multiple ecosystems, the attackers increase their chances of success. Developers often use multiple languages and package managers, and by casting a wider net, the attackers are playing a numbers game that increases their odds of hitting a high-value target.

Common Traits Across Ecosystems

  1. Target Platform: All packages specifically target macOS systems.
  2. Remote Server: All packages communicate with the same remote server at IP address
  3. Data Encoding: Data is either Base64 encoded or encrypted before being sent.
  4. Versioning: Similar versions (e.g., 9.1.10) were used across npm and PyPI packages.

The Risks

The end goal of this campaign remains unclear, but the potential risks are manifold:

  1. Data Exfiltration: The malware collects sensitive system information.
  2. Chain of Trust: Developers often trust packages from these repositories, making it easier for malware to infiltrate systems.
  3. Software Supply Chain Attacks: Given that these packages are dependencies for other projects, the malware could propagate exponentially.

What Should Developers Do?

Defensive Measures

  1. Automated Security Audits: Utilize automated solutions like Phylum to scan packages for malicious behavior.
  2. Sandboxing: Install packages in a locked-down sandbox environment that limits access to network, disk, and environment variables.
  3. CI/CD Integration: Integrate security checks into your build and CI pipelines.

Proactive Steps

  1. Manual Audits: While not always feasible, occasional manual audits can provide an additional layer of security.
  2. Policy Enforcement: Define and enforce security policies for package installations.


The discovery by Phylum serves as a wake-up call for the developer community. As the threats grow more sophisticated, it's crucial to take the risks associated with open-source packages seriously. Ignoring these vulnerabilities could be tantamount to leaving your front door unlocked in a neighborhood known for burglaries.

Read next