Malicious ‘dependency confusion’ packages are stealing password files

Image of a cyber criminal using several computers in a dark room
(Image credit: Shutterstock)

Security researchers have identified malicious code in JavaScript repositories that could enable hackers to steal password files in Linux and Unix systems.

According to cyber security firm Sonotype, these “dependency confusion” packages are published to the npm ecosystem and named after repositories, namespaces, or components companies commonly use, such as Amazon, Zillow, Lyft, and Slack. These malicious packages include amzn, zg-rentals, lyft-dataset-sdk, and serverless-slack-app.

Hackers created packages using names similar to ones found in a legitimate organization’s internal repositories. In public repositories, such internal names can be found referenced in public code repositories, such as GitHub, in source code files.

When hosted on a public site, dependency managers use these packages rather than internal ones belonging to a company when creating an application.

This "dependency confusion" enables hackers to insert their malicious code into an internal application to carry out a supply-chain attack. Researchers said many of these packages have no disclaimers or code comments in place that indicate these are linked to any kind of ethical bug bounty program or created for security research purposes.

While having such a disclaimer is no guarantee a package’s author is working in good faith, a lack of one can surely raise alarm bells, especially when combined with malicious code, said researchers.

“As soon as these packages are installed automatically because they share a name with an internal dependency (thereby exploiting “dependency confusion”), they exfiltrate the user’s .bash_history file and /etc/shadow, and in some cases spawn a reverse shell,” said researchers.

In one example, a package named “amzn” contained code that opened a reverse shell to their server, which would spawn as soon as the `amzn` package infiltrated the vulnerable build. It also displayed the contents of a /etc/shadow file.

The /etc/shadow file is a successor to the /etc/passwd Linux file that maintains hashed password data of user accounts on a system.

“Although the file is typically restricted to “superuser” accounts, there remains a slight chance of a malicious actor, in this case, being able to obtain the file should the infected machine be running npm with elevated privileges,” said researchers.

Sonatype security researcher Juan Aguirre said he was “starting to wonder when we were going to see a malicious actor take advantage of the current situation. Finally, we've spotted one.”

“There is no scenario I can imagine where I'm going to submit a PoC for a bug bounty program that actually harms the organization. Taking their /etc/shadow file is definitely harmful,” he added.

In creating these malicious packages, hackers have used the same code base as the proof-of-concept PoC released by security researcher Alex Birsan, who discovered this flaw. The hackers then got creative.

“These packages stood out because they reflect the behavior of actual malware, a first stage payload to grab a binary which further grabs your bash history,” said Aguirre.

While some malicious packages steal the /etc/shadow password file, some others, such as “lyft-dataset-sdk” and “serverless-slack-app,” steal a .bash_history file and send it to a remote host under the hacker’s control. This file lists all commands typed into a shell, including passwords. This enables hackers to harvest credentials.

Researchers said they only expect this trend to increase, with adversaries abusing dependency confusion to conduct even more sinister activities.

Organizations have been urged to download a “dependency/namespace confusion checker” script from GitHub to check if they have artifacts with the same name between repositories and determine if a dependency confusion attack has impacted them in the past.

Rene Millman

Rene Millman is a freelance writer and broadcaster who covers cybersecurity, AI, IoT, and the cloud. He also works as a contributing analyst at GigaOm and has previously worked as an analyst for Gartner covering the infrastructure market. He has made numerous television appearances to give his views and expertise on technology trends and companies that affect and shape our lives. You can follow Rene Millman on Twitter.