Malicious npm Packages Steal SSH Keys and API Tokens

Recent investigations have uncovered a coordinated supply chain attack targeting developers through malicious npm packages. These packages are designed to exfiltrate sensitive information, including SSH private keys, cloud service credentials, cryptocurrency wallet data, and API tokens, upon installation.

One particularly concerning package, identified as ‘moralis-sdk,’ had amassed over 2.7 million downloads before detection, indicating a potentially widespread impact on developer systems and CI/CD pipelines. The attackers employed various techniques to execute their malicious code, such as leveraging npm lifecycle hooks like preinstall and postinstall scripts, as well as utilizing obfuscated loaders and Ethereum smart contracts to dynamically retrieve command-and-control addresses.

For instance, the ‘ethers-jss’ package masqueraded as a legitimate Ethereum development tool but intercepted wallet creation and recovery functions to capture private keys and mnemonic phrases, which were then transmitted to an attacker-controlled server. Another package, ‘coinbase-wallet-utils,’ focused on reconnaissance by collecting system information and environment variables, subsequently exfiltrating this data using HTTP requests.

In a more sophisticated approach, a cluster of packages published by the npm user ‘ethcompat’ encrypted stolen credentials with AES-256-GCM and embedded them within Ethereum blockchain transactions, effectively concealing the exfiltration process.

This incident underscores the escalating threat posed by supply chain attacks within the open-source ecosystem. Developers are urged to exercise heightened vigilance by scrutinizing package sources, monitoring for unusual behavior post-installation, and implementing robust security practices to safeguard sensitive credentials and infrastructure.

As the open-source community continues to grapple with these challenges, it is imperative to develop and adopt more advanced detection mechanisms and security protocols to mitigate the risks associated with malicious package distribution.