Malware Campaign Uses Ethereum Smart Contracts to Control npm Typosquat Packages

Haider amin
4 min readNov 5, 2024

--

Author: Haider Amin

A sophisticated malware campaign has recently emerged, targeting npm developers by leveraging hundreds of typosquat packages on the npm registry. These packages imitate popular libraries, and the attackers are utilizing Ethereum smart contracts to obscure their command-and-control (C2) server addresses. This tactic, previously seen in campaigns like EtherHiding, illustrates how blockchain technology is being misused to enhance malware resilience and hinder takedown efforts.

What’s Happening?

On October 31, 2024, cybersecurity firms Checkmarx, Phylum, and Socket collectively identified the campaign, noting that it had likely begun weeks prior. The campaign includes at least 287 typosquat packages designed to resemble legitimate libraries like Puppeteer, Bignum.js, and various cryptocurrency utilities. Once a developer unknowingly installs one of these malicious packages, the attack is set in motion.

Each compromised package contains obfuscated JavaScript that executes during or after installation. This code is responsible for retrieving a secondary binary payload from a remote server, which then establishes persistence on the victim’s system and exfiltrates sensitive information back to the same server. This exfiltration gives attackers access to crucial machine-level data, increasing their ability to launch further attacks or gather intelligence.

How the Attack Leverages Ethereum Smart Contracts:

The notable element of this campaign is its innovative use of Ethereum smart contracts to fetch C2 server addresses. By using the ethers.js library, the malware retrieves an IP address from an Ethereum smart contract, which acts as a decentralized conduit for controlling the malware’s next steps. Unlike traditional C2 approaches that rely on centralized servers, the blockchain-based method is highly resilient. Ethereum's decentralized, immutable nature allows the attackers to continuously update IP addresses, making it nearly impossible for defenders to block the infrastructure without targeting the entire Ethereum network.

This approach is advantageous to the threat actors in two primary ways:

  1. Resilience Against Takedown Efforts: Since the blockchain is decentralized and immutable, it’s impossible to “take down” an Ethereum contract or prevent it from distributing IP addresses.
  2. Dynamic IP Updates: Even if specific IPs are blocked by security defenses, the attackers can update the C2 addresses in the smart contract. This ensures that malware on compromised devices remains connected to the C2 infrastructure and can receive further instructions.

Tactics, Techniques, and Procedures (TTPs)

The campaign operates in phases, with each phase adding a layer of sophistication:

  1. Typosquatting: By creating slightly modified versions of popular libraries, attackers trick developers into installing malicious packages.
  2. JavaScript Obfuscation: The initial payload includes obfuscated JavaScript, making it difficult to analyze and detect.
  3. Cross-Platform Binary Retrieval: Based on the host operating system, the malware fetches an appropriate binary payload, enhancing its reach across Windows, macOS, and Linux.
  4. Blockchain-Backed C2 Infrastructure: The payload communicates with an Ethereum smart contract to fetch an IP address for C2, making it hard to disrupt the infrastructure.

Potential Attribution:

While the identity of the threat actors remains unknown, the Socket Threat Research Team noted that certain error messages in the malware were written in Russian. This linguistic clue suggests a possible link to Russian-speaking attackers, though it’s still speculative.

Why This Matters for the Open-Source Ecosystem:

This campaign underscores the rising threat of supply chain attacks within open-source ecosystems. Attackers increasingly exploit trust in these platforms to inject malicious code into libraries that developers routinely use. The novel use of blockchain technology for C2 infrastructure elevates this attack by rendering traditional detection and blocking strategies ineffective.

Mitigation Strategies:

To protect against such threats, developers and security teams should take the following precautions:

  1. Verify Package Sources: Only install packages from trusted sources and double-check for typos in package names. Avoid installing packages with unclear documentation or without recent activity.
  2. Use Security Scanning Tools: Leverage tools like npm-audit, Snyk, or Socket’s Dependency Scanner to detect potential typosquatting or malicious code within packages.
  3. Monitor Unusual Activity: Keep an eye out for unexpected network requests or installations triggered by dependencies. Analyze network traffic to identify any unusual IP addresses or connections.
  4. Regularly Update Dependencies: Stay updated with the latest versions of npm packages, which are more likely to have known vulnerabilities patched. However, be cautious of sudden, unexplained version changes in less-frequently updated packages.

Conclusion:

The use of blockchain technology in malware distribution represents a formidable shift in cybercriminal tactics, especially in supply chain attacks. The immutable and decentralized characteristics of blockchain networks offer malicious actors resilience and flexibility that traditional infrastructures lack. For developers, this incident serves as a reminder of the importance of vigilance and security hygiene when dealing with open-source dependencies.

As attackers continue to innovate, defenders must remain proactive by using comprehensive security tools, maintaining awareness of the latest attack vectors, and fostering a community that emphasizes secure development practices.

--

--

Haider amin
Haider amin

Written by Haider amin

Cybersecurity researcher | ethical hacker

No responses yet