Rogue PyPI Library Solana Users, Steals Blockchain Wallet Keys

Summary:
A recent discovery by security researchers at Sonatype, published on August 7th, 2024, highlights a new malicious package on the Python Package Index (PyPI) masquerading as a legitimate Solana blockchain library, "solana-py". This fake package leverages a typosquat technique, exploiting the slight naming discrepancy between the genuine "solana-py" project on GitHub and its simplified name "solana" on PyPI. The counterfeit package incorporates legitimate code from the real project while harboring malicious functionalities within the "init.py" file designed to steal Solana blockchain wallet keys. The attack strategy essentially hinges on the reference made to "solana-py" within the documentation of the legitimate "solders" library, also hosted on PyPI. This increases the likelihood of developers being misled into mistakenly installing the malicious "solana-py" instead of the intended and legitimate "solana" package. Other red flags include a higher version number (0.34.5) displayed by the fake package compared to the real "solana" (0.34.3), suggesting a seemingly more updated version that acts as another social engineering tactic against victims. Additionally, the threat actor behind "solana-py" has also altered the "init.py" file, a core script within the package, to include a network call to a suspicious URL hosted on Hugging Face Spaces, another legitimate technology often exploited by attackers. The malicious code within "solana-py" specifically targets the "solders.keypair.Keypair.__init__" method, aiming to replace it with a function designed to exfiltrate the "self.to_bytes_array" value, which holds the sensitive Solana wallet key data. This stolen information is then transmitted to the attacker's C2 hosted on Hugging Face.

Security Officer Comments:
The "solana-py" incident serves as another reminder of the evolving tactics employed by cybercriminals to exploit the open-source ecosystem for voluminous malware propagation. This case underscores the critical need for enhanced supply chain security measures and heightened vigilance when utilizing third-party software repositories. Developers and organizations must prioritize robust security practices throughout the development lifecycle to minimize risks associated with external dependencies. The success of the "solana-py" attack, despite garnering only a moderate download count (1,122), emphasizes the effectiveness of social engineering tactics. By mimicking a legitimate project and manipulating version numbers, the attackers increased the potential for developer oversight. Furthermore, the exploitation of a trusted platform like Hugging Face Spaces demonstrates the attackers' resourcefulness in leveraging legitimate services for malicious purposes.

Moving forward, developers should implement stricter package vetting processes, including thorough code reviews and verification of publisher identities to effectively mitigate software supply chain threats. Utilizing two-factor authentication and content signing mechanisms offered by package repositories can add an extra layer of security. Organizations should consider deploying automated dependency management tools to identify and mitigate vulnerabilities within their codebase.

Suggested Corrections:
Threat actors employ different techniques to execute software supply chain attacks. Three common techniques are:

  • Hijacking updates
  • Undermining code signing
  • Compromising open-source code

Hijacking Updates
“Most modern software receives routine updates to address bugs and security issues. Software vendors typically distribute updates from centralized servers to customers as a routine part of product maintenance. Threat actors can hijack an update by infiltrating the vendor’s network and either inserting malware into the outgoing update or altering the update to grant the threat actor control over the software’s normal functionality. For example, the NotPetya attack occurred in 2017 when Russian hackers targeting Ukraine spread malware through tax accounting software popular in Ukraine. What would later be called the NotPetya malware spread well beyond Ukraine and caused major global disruptions in crucial industries, including international shipping, financial services, and healthcare” (CISA, 2022)

Undermining Codesigning
“Codesigning is used to validate the identity of the code’s author and the integrity of the code. Attackers undermine codesigning by self-signing certificates, breaking signing systems, or exploiting misconfigured account access controls. By undermining codesigning, threat actors are able to successfully hijack software updates by impersonating a trusted vendor and inserting malicious code into an update. For example, APT 41, a China-based threat actor, routinely undermines codesigning while conducting sophisticated software supply chain compromises against the United States and other countries” (CISA, 2022)

Compromising Open-Source Code
“Open-source code compromises occur when threat actors insert malicious code into publicly accessible code libraries, which unsuspecting developers—looking for free blocks of code to perform specific functions—then add into their own third-party code. For example, in 2018, researchers discovered 12 malicious Python libraries uploaded on the official Python Package Index (PyPI). The attacker used typosquatting tactics by creating libraries titled “diango,” “djago,” “dajngo,” etc., to lure developers seeking the popular “django” Python library. The malicious libraries contained the same code and functionality of those they impersonated; but they also contained additional functionality, including the ability to obtain boot persistence and open a reverse shell on remote workstations. Open-source code compromises can also affect privately owned software because developers of proprietary code routinely leverage blocks of open-source code in their products” (CISA, 2022)

“Network defenders are limited in their ability to quickly mitigate consequences after a threat actor has compromised a software supply chain. This is because organizations rarely control their entire software supply chain and lack authority to compel every organization in their supply chain to take prompt mitigation steps. Due to the difficulty of mitigating consequences after a software supply chain attack occurs, network defenders should observe industry best practices before an attack has occurred. Implementing best practices will bolster an organization’s ability to prevent, mitigate, and respond to such attacks” (CISA, 2022)

NIST suggests eight key practices for establishing a NIST C-SCRM (Cyber Supply Chain Risk Management) approach that can be applied to software.

  1. Integrate C-SCRM across the organization.
  2. Establish a formal C-SCRM program.
  3. Know and manage critical components and suppliers.
  4. Understand the organization’s supply chain. software for which a vulnerability is disclosed
  5. Closely collaborate with key suppliers.
  6. Include key suppliers in resilience and improvement activities.
  7. Assess and monitor throughout the supplier relationship.
  8. Plan for the full lifecycle.

These practices can assist in preventing, mitigating, and responding to software vulnerabilities that may be introduced through the cyber supply chain and exploited by malicious actors.

https://www.cisa.gov/sites/default/files/publications/defending_against_software_supply_chain_attacks_508_1.pdf

Link(s):
https://thehackernews.com/2024/08/rogue-pypi-library-solana-users-steals.html

https://www.sonatype.com/blog/an-ideal-pypi-typosquat-solana-py-is-here-to-steal-your-crypto-keys