Cybersecurity researchers have uncovered a disturbing trend involving malicious npm packages impersonating the Nomic Foundation’s Hardhat tool to exfiltrate sensitive data from developer systems. These counterfeit packages, distributed via the npm registry, aim to compromise Ethereum developers by harvesting critical information such as private keys, mnemonics, and configuration files.
Understanding the Attack
Hardhat is a widely used development environment for Ethereum software, providing tools for editing, compiling, debugging, and deploying smart contracts and decentralized applications (dApps). By exploiting the open-source ecosystem’s inherent trust, attackers have successfully infiltrated development environments through malicious plugins disguised as legitimate Hardhat packages.
According to an analysis by the Socket research team, the attack begins when these counterfeit npm packages are installed. The packages exploit the Hardhat runtime environment using functions like hreInit()
and hreConfig()
to gather sensitive data. Once collected, this data is transmitted to attacker-controlled endpoints using hardcoded keys and Ethereum addresses for streamlined exfiltration.
List of Identified Malicious Packages
The following counterfeit packages have been flagged as malicious:
nomicsfoundations
@nomisfoundation/hardhat-configure
installedpackagepublish
@nomisfoundation/hardhat-config
@monicfoundation/hardhat-config
@nomicsfoundation/sdk-test
@nomicsfoundation/hardhat-config
@nomicsfoundation/web3-sdk
@nomicsfoundation/sdk-test1
@nomicfoundations/hardhat-config
crypto-nodes-validator
solana-validator
node-validators
hardhat-deploy-others
hardhat-gas-optimizer
solidity-comments-extractors
Among these, @nomicsfoundation/sdk-test
has garnered significant attention, with over 1,092 downloads since its publication in October 2023. Once installed, this package is designed to harvest mnemonic phrases and private keys from the Hardhat environment, posing a substantial risk to Ethereum developers.
Broader Implications of the Threat
This disclosure comes shortly after the detection of another malicious npm package, ethereumvulncontracthandler
, which masqueraded as a library for identifying vulnerabilities in Ethereum smart contracts. Instead, it was discovered to harbor functionality to deploy Quasar RAT malware, demonstrating the increasing sophistication of these supply chain attacks.
In recent months, attackers have even leveraged Ethereum smart contracts to distribute command-and-control (C2) server addresses, integrating infected machines into a blockchain-powered botnet named MisakaNetwork. This campaign has been attributed to a Russian-speaking threat actor known as “_lain,” who has openly admitted exploiting the npm ecosystem’s dependency sprawl and complexity.
Challenges in Open-Source Security
The npm ecosystem’s reliance on numerous dependencies creates a complex “nesting doll” structure, making comprehensive security reviews challenging. Threat actors exploit this complexity, knowing that it is impractical for developers to scrutinize every package and dependency. This underscores the need for enhanced vigilance and robust security practices in the open-source community.
Additionally, similar malicious activities have been observed across other ecosystems like PyPI and RubyGems. For instance:
adobe-dcapi-web
(npm): Capable of collecting system information while avoiding systems in Russia.monoliht
(PyPI): Designed to collect system metadata.chauuuyhhn
,nosvemosssadfsd
,holaaaaaafasdf
(RubyGems): Embedded with scripts that exfiltrate sensitive data via DNS queries to attacker-controlled endpoints.
These packages have been found leveraging out-of-band application security testing (OAST) tools such as oastify.com and oast.fun to facilitate data exfiltration and establish C2 channels.
Recommendations to Mitigate Supply Chain Risks
To counter the threats posed by malicious npm packages, developers and organizations should adopt the following best practices:
Verify Package Authenticity: Cross-check package names and publishers against trusted sources to avoid installing counterfeit libraries.
Inspect Source Code: Before installation, review the source code for any signs of malicious behavior.
Limit Dependencies: Minimize reliance on third-party packages to reduce the risk of supply chain attacks.
Use Security Tools: Leverage automated tools to analyze package dependencies and identify potential vulnerabilities.
Stay Updated: Regularly monitor updates and advisories from trusted cybersecurity sources to stay informed about new threats.
Implement Security Policies: Establish organizational policies that enforce secure coding and package management practices.
The discovery of these malicious npm packages highlights the growing challenges of securing open-source ecosystems. As attackers continue to exploit the trust inherent in these platforms, it is imperative for developers to remain vigilant and prioritize security in every phase of the software development lifecycle. By adopting proactive measures, the community can mitigate risks and safeguard critical assets against emerging threats.